diff --git a/CHANGELOG.md b/CHANGELOG.md index 813ae52939..20bf47c4a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Asset Hubs: setup auto incremented asset id to 50_000_000 for trust backed assets ([polkadot-fellows/runtimes#414](https://github.com/polkadot-fellows/runtimes/pull/414)). - Upgrade dependencies to the [polkadot-sdk@1.13.0](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.13.0) release ([polkadot-fellows/runtimes#332](https://github.com/polkadot-fellows/runtimes/pull/332)). - Filter `interlace` calls on the Polkadot Coretime Chain until the Relay chain implementation is more mature ([polkadot-fellows/runtimes#438](https://github.com/polkadot-fellows/runtimes/pull/438)). +- Kusama, pallet OnDemandAssignmentProvider: renamed to OnDemand ([polkadot-fellows/runtimes#417](https://github.com/polkadot-fellows/runtimes/pull/417)) #### From [#322](https://github.com/polkadot-fellows/runtimes/pull/322): diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index f36bbe75cc..febb4ba5de 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1727,7 +1727,7 @@ construct_runtime! { ParaSessionInfo: parachains_session_info = 61, ParasDisputes: parachains_disputes = 62, ParasSlashing: parachains_slashing = 63, - OnDemandAssignmentProvider: parachains_assigner_on_demand = 64, + OnDemand: parachains_assigner_on_demand = 64, CoretimeAssignmentProvider: parachains_assigner_coretime = 65, // Parachain Onboarding Pallets. Start indices at 70 to leave room. @@ -1795,6 +1795,72 @@ pub type Migrations = (migrations::Unreleased, migrations::Permanent); #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; + #[cfg(feature = "try-runtime")] + use frame_support::storage::PrefixIterator; + use frame_support::{ + migration::move_pallet, + traits::{GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess}, + }; + #[cfg(feature = "try-runtime")] + use sp_io::hashing::twox_128; + + // Migrate storage for pallet rename `OnDemandAssignmentProvider` -> `OnDemand`. + pub struct OnDemandRename; + impl OnDemandRename { + const OLD_PALLET_NAME: &'static str = "OnDemandAssignmentProvider"; + } + impl OnRuntimeUpgrade for OnDemandRename { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + let old_pallet_prefix = twox_128(Self::OLD_PALLET_NAME.as_bytes()); + let iter = PrefixIterator::<_>::new( + old_pallet_prefix.to_vec(), + old_pallet_prefix.to_vec(), + |k, v| Ok((k.to_vec(), v.to_vec())), + ); + + let mut count = 0; + for (k, v) in iter { + log::trace!(target: "runtime", "Found storage keys before running OnDemandRename: {:x?}", k); + count += 1; + } + + log::trace!(target: "runtime", "Before running OnDemandRename: {} keys found for prefix {:x?}", count, old_pallet_prefix); + + Ok(Vec::new()) + } + + fn on_runtime_upgrade() -> Weight { + // todo: version check + + log::info!(target: "runtime", "Applying OnDemandRename"); + + let new_pallet = ::name(); + move_pallet(Self::OLD_PALLET_NAME.as_bytes(), new_pallet.as_bytes()); + ::DbWeight::get().reads_writes(0, 0) //todo: set proper weights + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + let old_pallet_prefix = twox_128(Self::OLD_PALLET_NAME.as_bytes()); + let count = PrefixIterator::<_>::new( + old_pallet_prefix.to_vec(), + old_pallet_prefix.to_vec(), + |_, _| Ok(()), + ) + .count(); + + log::trace!(target: "runtime", "After running OnDemandRename: {} old keys found", count); + + if count == 0 { + Ok(()) + } else { + Err(sp_runtime::TryRuntimeError::Other( + "OnDemandRename failed - keys with the old prefix still exist", + )) + } + } + } /// Unreleased migrations. Add new ones here: pub type Unreleased = ( @@ -1802,6 +1868,7 @@ pub mod migrations { pallet_staking::migrations::v15::MigrateV14ToV15, parachains_inclusion::migration::MigrateToV1, parachains_assigner_on_demand::migration::MigrateV0ToV1, + OnDemandRename, ); /// Migrations/checks that do not need to be versioned and can run on every update. @@ -1840,7 +1907,7 @@ mod benches { [runtime_parachains::initializer, Initializer] [runtime_parachains::paras_inherent, ParaInherent] [runtime_parachains::paras, Paras] - [runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider] + [runtime_parachains::assigner_on_demand, OnDemand] [runtime_parachains::coretime, Coretime] // Substrate [pallet_balances, Native]