diff --git a/Cargo.lock b/Cargo.lock index e9c6bb7c65..d8da48327c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9716,6 +9716,7 @@ dependencies = [ "pallet-fast-unstake", "pallet-grandpa", "pallet-identity", + "pallet-im-online", "pallet-indices", "pallet-message-queue", "pallet-mmr", @@ -13955,6 +13956,7 @@ dependencies = [ "pallet-election-provider-support-benchmarking", "pallet-fast-unstake", "pallet-grandpa", + "pallet-im-online", "pallet-indices", "pallet-message-queue", "pallet-mmr", diff --git a/Cargo.toml b/Cargo.toml index 681b5d6efd..1dc5589094 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -120,6 +120,7 @@ pallet-fast-unstake = { version = "34.0.0", default-features = false } pallet-glutton = { version = "21.0.0", default-features = false } pallet-grandpa = { version = "35.0.0", default-features = false } pallet-identity = { version = "35.0.0", default-features = false } +pallet-im-online = { version = "34.0.0", default-features = false } pallet-indices = { version = "35.0.0", default-features = false } pallet-insecure-randomness-collective-flip = { version = "23.0.0", default-features = false } pallet-membership = { version = "35.0.0", default-features = false } diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index 8f081e18f2..2f705a5775 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -57,6 +57,7 @@ frame-executive = { workspace = true } frame-metadata-hash-extension = { workspace = true } pallet-grandpa = { workspace = true } pallet-nis = { workspace = true } +pallet-im-online = { workspace = true } pallet-indices = { workspace = true } pallet-message-queue = { workspace = true } pallet-mmr = { workspace = true } @@ -151,6 +152,7 @@ std = [ "pallet-election-provider-support-benchmarking?/std", "pallet-fast-unstake/std", "pallet-grandpa/std", + "pallet-im-online/std", "pallet-indices/std", "pallet-message-queue/std", "pallet-mmr/std", @@ -227,6 +229,7 @@ runtime-benchmarks = [ "pallet-election-provider-support-benchmarking/runtime-benchmarks", "pallet-fast-unstake/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", + "pallet-im-online/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-mmr/runtime-benchmarks", @@ -281,6 +284,7 @@ try-runtime = [ "pallet-election-provider-multi-phase/try-runtime", "pallet-fast-unstake/try-runtime", "pallet-grandpa/try-runtime", + "pallet-im-online/try-runtime", "pallet-indices/try-runtime", "pallet-message-queue/try-runtime", "pallet-mmr/try-runtime", diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 92de3de80e..446c9f5899 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1507,59 +1507,6 @@ impl pallet_asset_rate::Config for Runtime { type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::AssetRateArguments; } -// A mock pallet to keep `ImOnline` events decodable after pallet removal -pub mod pallet_im_online { - use frame_support::pallet_prelude::*; - pub use pallet::*; - - pub mod sr25519 { - mod app_sr25519 { - use sp_application_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; - app_crypto!(sr25519, IM_ONLINE); - } - pub type AuthorityId = app_sr25519::Public; - } - - #[frame_support::pallet] - pub mod pallet { - use super::*; - use frame_support::traits::{ValidatorSet, ValidatorSetWithIdentification}; - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> - + IsType<::RuntimeEvent>; - type ValidatorSet: ValidatorSetWithIdentification; - } - - pub type ValidatorId = <::ValidatorSet as ValidatorSet< - ::AccountId, - >>::ValidatorId; - - pub type IdentificationTuple = ( - ValidatorId, - <::ValidatorSet as ValidatorSetWithIdentification< - ::AccountId, - >>::Identification, - ); - - #[pallet::event] - pub enum Event { - HeartbeatReceived { authority_id: super::sr25519::AuthorityId }, - AllGood, - SomeOffline { offline: sp_std::vec::Vec> }, - } - } -} - -impl pallet_im_online::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type ValidatorSet = Historical; -} - construct_runtime! { pub enum Runtime { @@ -1584,7 +1531,6 @@ construct_runtime! { Session: pallet_session = 8, Grandpa: pallet_grandpa = 10, - ImOnline: pallet_im_online::{Event} = 11, AuthorityDiscovery: pallet_authority_discovery = 12, // Governance stuff. @@ -1879,6 +1825,12 @@ sp_api::impl_runtime_apis! { impl sp_offchain::OffchainWorkerApi for Runtime { fn offchain_worker(header: &::Header) { + use sp_runtime::{traits::Header, DigestItem}; + + if header.digest().logs().iter().any(|di| di == &DigestItem::RuntimeEnvironmentUpdated) { + pallet_im_online::migration::clear_offchain_storage(Session::validators().len() as u32); + } + Executive::offchain_worker(header) } } diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index b6c20f2649..c89d7fc2c2 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -54,6 +54,7 @@ frame-executive = { workspace = true } frame-metadata-hash-extension = { workspace = true } pallet-grandpa = { workspace = true } pallet-identity = { workspace = true } +pallet-im-online = { workspace = true } pallet-indices = { workspace = true } pallet-message-queue = { workspace = true } pallet-mmr = { workspace = true } @@ -149,6 +150,7 @@ std = [ "pallet-fast-unstake/std", "pallet-grandpa/std", "pallet-identity/std", + "pallet-im-online/std", "pallet-indices/std", "pallet-message-queue/std", "pallet-mmr/std", @@ -225,6 +227,7 @@ runtime-benchmarks = [ "pallet-fast-unstake/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-identity/runtime-benchmarks", + "pallet-im-online/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-mmr/runtime-benchmarks", @@ -277,6 +280,7 @@ try-runtime = [ "pallet-fast-unstake/try-runtime", "pallet-grandpa/try-runtime", "pallet-identity/try-runtime", + "pallet-im-online/try-runtime", "pallet-indices/try-runtime", "pallet-message-queue/try-runtime", "pallet-mmr/try-runtime", diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index e2c3c09850..522fc6af86 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1575,59 +1575,6 @@ impl pallet_asset_rate::Config for Runtime { type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::AssetRateArguments; } -// A mock pallet to keep `ImOnline` events decodable after pallet removal -pub mod pallet_im_online { - use frame_support::pallet_prelude::*; - pub use pallet::*; - - pub mod sr25519 { - mod app_sr25519 { - use sp_application_crypto::{app_crypto, key_types::IM_ONLINE, sr25519}; - app_crypto!(sr25519, IM_ONLINE); - } - pub type AuthorityId = app_sr25519::Public; - } - - #[frame_support::pallet] - pub mod pallet { - use super::*; - use frame_support::traits::{ValidatorSet, ValidatorSetWithIdentification}; - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> - + IsType<::RuntimeEvent>; - type ValidatorSet: ValidatorSetWithIdentification; - } - - pub type ValidatorId = <::ValidatorSet as ValidatorSet< - ::AccountId, - >>::ValidatorId; - - pub type IdentificationTuple = ( - ValidatorId, - <::ValidatorSet as ValidatorSetWithIdentification< - ::AccountId, - >>::Identification, - ); - - #[pallet::event] - pub enum Event { - HeartbeatReceived { authority_id: super::sr25519::AuthorityId }, - AllGood, - SomeOffline { offline: sp_std::vec::Vec> }, - } - } -} - -impl pallet_im_online::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type ValidatorSet = Historical; -} - construct_runtime! { pub enum Runtime { @@ -1654,7 +1601,6 @@ construct_runtime! { Session: pallet_session = 9, Grandpa: pallet_grandpa = 11, - ImOnline: pallet_im_online::{Event} = 12, AuthorityDiscovery: pallet_authority_discovery = 13, // OpenGov stuff. @@ -1785,17 +1731,8 @@ pub type Migrations = (migrations::Unreleased, migrations::Permanent); pub mod migrations { use super::*; - parameter_types! { - pub const ImOnlinePalletName: &'static str = "ImOnline"; - } - /// Unreleased migrations. Add new ones here: pub type Unreleased = ( - // Remove `im-online` pallet on-chain storage - frame_support::migrations::RemovePallet< - ImOnlinePalletName, - ::DbWeight, - >, parachains_configuration::migration::v12::MigrateToV12, parachains_inclusion::migration::MigrateToV1, pallet_staking::migrations::v15::MigrateV14ToV15, @@ -1985,6 +1922,12 @@ sp_api::impl_runtime_apis! { impl sp_offchain::OffchainWorkerApi for Runtime { fn offchain_worker(header: &::Header) { + use sp_runtime::{traits::Header, DigestItem}; + + if header.digest().logs().iter().any(|di| di == &DigestItem::RuntimeEnvironmentUpdated) { + pallet_im_online::migration::clear_offchain_storage(Session::validators().len() as u32); + } + Executive::offchain_worker(header) } }