diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 25ac687a8bc4..3b54fde69261 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1287,6 +1287,52 @@ impl pallet_asset_rate::Config for Runtime { type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments; } +#[frame_support::pallet] +pub mod im_online_remover { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(n: BlockNumberFor) -> Weight { + if RemoveAtBlock::::get() == None { + RemoveAtBlock::::set(Some(n)); + } + Weight::zero() + } + + fn offchain_worker(n: BlockNumberFor) { + const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; + if let Some(remove_at) = RemoveAtBlock::::get() { + if remove_at == n { + let validator_set_size = + pallet_session::Pallet::::validators().len() as u32; + (0..validator_set_size).for_each(|idx| { + let key = { + let mut key = DB_PREFIX.to_vec(); + key.extend(idx.encode()); + key + }; + // FIXME: `StorageLock` needed? + sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); + }); + } + } + } + } + + #[pallet::storage] + pub(super) type RemoveAtBlock = StorageValue<_, BlockNumberFor, OptionQuery>; +} + +impl im_online_remover::Config for Runtime {} + construct_runtime! { pub enum Runtime { @@ -1403,6 +1449,8 @@ construct_runtime! { // Pallet for sending XCM. XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config} = 99, + ImOnlineRemover: im_online_remover::{Pallet, Storage} = 100, + ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call} = 250, AssignedSlots: assigned_slots::{Pallet, Call, Storage, Event, Config} = 251, @@ -1504,7 +1552,7 @@ pub mod migrations { type PalletName = TipsPalletName; } - /// Upgrade Session keys to exclude ImOnline key. + /// Upgrade Session keys to exclude `ImOnline` key. /// When this is removed, should also remove `OldSessionKeys`. pub struct UpgradeSessionKeys; impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { @@ -1514,24 +1562,6 @@ pub mod migrations { } } - // Remove offchain storage values of `im-online` pallet - pub struct RemoveImOnlineOffchainStorageValues; - impl frame_support::traits::OnRuntimeUpgrade for RemoveImOnlineOffchainStorageValues { - fn on_runtime_upgrade() -> Weight { - const DB_PREFIX: &[u8] = b"parity/im-online-heartbeat/"; - let validator_set_size = pallet_session::Pallet::::validators().len() as u32; - (0..validator_set_size).for_each(|idx| { - let key = { - let mut key = DB_PREFIX.to_vec(); - key.extend(idx.encode()); - key - }; - sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear(); - }); - Weight::zero() - } - } - /// Unreleased migrations. Add new ones here: pub type Unreleased = ( pallet_society::migrations::MigrateToV2, @@ -1562,10 +1592,7 @@ pub mod migrations { // Upgrade `SessionKeys` to exclude `ImOnline` UpgradeSessionKeys, - // Remove im-online pallet off-chain storage - RemoveImOnlineOffchainStorageValues, - - // Remove im-online pallet on-chain storage + // Remove `im-online` pallet on-chain storage frame_support::migrations::RemovePallet::DbWeight>, ); } @@ -1627,6 +1654,7 @@ mod benches { [runtime_parachains::paras_inherent, ParaInherent] [runtime_parachains::paras, Paras] [runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider] + [im_online_remover, ImOnlineRemover] // Substrate [pallet_balances, Balances] [pallet_balances, NisCounterpartBalances]