From 268079c98315a982f20c87486324e4e40f9abf7b Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Aug 2024 10:43:24 +0300 Subject: [PATCH 1/4] Rename `OnDemandAssignmentProvider` to `OnDemand` on Kusama --- relay/kusama/src/lib.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 0b6704edfd..f8908c67b9 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1115,7 +1115,8 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | + RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) @@ -1625,7 +1626,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. @@ -1693,9 +1694,29 @@ pub type Migrations = (migrations::Unreleased, migrations::Permanent); #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; + use frame_support::{migration::move_storage_from_pallet, traits::OnRuntimeUpgrade}; + + // Migrate storage for pallet rename `OnDemandAssignmentProvider` -> `OnDemand` + pub struct OnDemandRename; + impl OnRuntimeUpgrade for OnDemandRename { + fn on_runtime_upgrade() -> Weight { + move_storage_from_pallet(b"Pallet", b"OnDemandAssignmentProvider", b"OnDemand"); + move_storage_from_pallet(b"ParaIdAffinity", b"OnDemandAssignmentProvider", b"OnDemand"); + move_storage_from_pallet(b"QueueStatus", b"OnDemandAssignmentProvider", b"OnDemand"); + move_storage_from_pallet(b"FreeEntries", b"OnDemandAssignmentProvider", b"OnDemand"); + move_storage_from_pallet( + b"AffinityEntries", + b"OnDemandAssignmentProvider", + b"OnDemand", + ); + move_storage_from_pallet(b"Revenue", b"OnDemandAssignmentProvider", b"OnDemand"); + ::DbWeight::get().reads_writes(0, 0) //todo + } + } /// Unreleased migrations. Add new ones here: pub type Unreleased = ( + OnDemandRename, parachains_configuration::migration::v12::MigrateToV12, pallet_staking::migrations::v15::MigrateV14ToV15, parachains_inclusion::migration::MigrateToV1, @@ -1738,7 +1759,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] From f6186d1e573a6a36c2de1a17687c9e3f9826f526 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Aug 2024 10:48:18 +0300 Subject: [PATCH 2/4] fmt --- relay/kusama/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index f8908c67b9..3514509564 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1115,8 +1115,7 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | - RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) From 930e392511438cdaba219f610fb750e3817e07ee Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Aug 2024 10:53:29 +0300 Subject: [PATCH 3/4] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f083d6a5bb..aec51b70f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Bounties: Remove payout delay ([polkadot-fellows/runtimes#386](https://github.com/polkadot-fellows/runtimes/pull/386)). - Polkadot System Chains: Reduce the base transaction fee by half ([polkadot-fellows/runtimes#398](https://github.com/polkadot-fellows/runtimes/pull/398)). +- Kusama, pallet OnDemandAssignmentProvider: renamed to Ondemand. #### From [#322](https://github.com/polkadot-fellows/runtimes/pull/322): From 820e8992ba9006bf4300acad8c1d3bd7ffd14eb4 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Thu, 22 Aug 2024 11:03:02 +0300 Subject: [PATCH 4/4] Use `move_pallet` and add `try-runtime` checks --- relay/kusama/src/lib.rs | 75 +++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 5c56e93dc2..be0176c251 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1700,33 +1700,80 @@ pub type Migrations = (migrations::Unreleased, migrations::Permanent); #[allow(deprecated, missing_docs)] pub mod migrations { use super::*; - use frame_support::{migration::move_storage_from_pallet, traits::OnRuntimeUpgrade}; + #[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` + // Migrate storage for pallet rename `OnDemandAssignmentProvider` -> `OnDemand`. pub struct OnDemandRename; + impl OnDemandRename { + const OLD_PALLET_NAME: &'static str = "OnDemandAssignmentProvider"; + } impl OnRuntimeUpgrade for OnDemandRename { - fn on_runtime_upgrade() -> Weight { - move_storage_from_pallet(b"Pallet", b"OnDemandAssignmentProvider", b"OnDemand"); - move_storage_from_pallet(b"ParaIdAffinity", b"OnDemandAssignmentProvider", b"OnDemand"); - move_storage_from_pallet(b"QueueStatus", b"OnDemandAssignmentProvider", b"OnDemand"); - move_storage_from_pallet(b"FreeEntries", b"OnDemandAssignmentProvider", b"OnDemand"); - move_storage_from_pallet( - b"AffinityEntries", - b"OnDemandAssignmentProvider", - b"OnDemand", + #[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())), ); - move_storage_from_pallet(b"Revenue", b"OnDemandAssignmentProvider", b"OnDemand"); - ::DbWeight::get().reads_writes(0, 0) //todo + + 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 = ( - OnDemandRename, parachains_configuration::migration::v12::MigrateToV12, 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.