From 9e3235f10fe9d5365f74e4186dbf7257fcade543 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Thu, 17 Aug 2023 09:54:21 -0600 Subject: [PATCH 1/4] add `VersionedRuntimeUpgrade` to kitchensink runtime --- bin/node/runtime/Cargo.toml | 2 +- bin/node/runtime/src/lib.rs | 15 ++++++++++++--- frame/nomination-pools/src/migration.rs | 24 +++++------------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index de0ec1a5489a8..7ba9e288f63dc 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -50,7 +50,7 @@ sp-io = { version = "23.0.0", default-features = false, path = "../../../primiti frame-executive = { version = "4.0.0-dev", default-features = false, path = "../../../frame/executive" } frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/benchmarking" } frame-benchmarking-pallet-pov = { version = "4.0.0-dev", default-features = false, path = "../../../frame/benchmarking/pov" } -frame-support = { version = "4.0.0-dev", default-features = false, path = "../../../frame/support", features = ["tuples-96"] } +frame-support = { version = "4.0.0-dev", default-features = false, path = "../../../frame/support", features = ["tuples-96", "experimental"] } frame-system = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system" } frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system/benchmarking", optional = true } frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support" } diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 4e1b6d4e8bec0..9d0f6f8757423 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -22,6 +22,8 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limits. #![recursion_limit = "1024"] +#![cfg(all(feature = "experimental", feature = "try-runtime"))] + use codec::{Decode, Encode, MaxEncodedLen}; use frame_election_provider_support::{ bounds::{ElectionBounds, ElectionBoundsBuilder}, @@ -1995,12 +1997,19 @@ pub type Executive = frame_executive::Executive< Migrations, >; +pub type VersionCheckedMigrateV1ToV2 = + VersionedRuntimeUpgrade< + 1, + 2, + pallet_nomination_pools::migration::v2::VersionUncheckedMigrateV1ToV2, + pallet_nomination_pools::Pallet, + ::DbWeight + >; + // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. type Migrations = ( - pallet_nomination_pools::migration::v2::MigrateToV2, - pallet_alliance::migration::Migration, - pallet_contracts::Migration, + pallet_nomination_pools::migration::v2::VersionCheckedMigrateV1ToV2, ); type EventRecord = frame_system::EventRecord< diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 2ae4cd1b86857..c411b59ee0962 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -194,8 +194,8 @@ pub mod v2 { /// Migrate the pool reward scheme to the new version, as per /// . - pub struct MigrateToV2(sp_std::marker::PhantomData); - impl MigrateToV2 { + pub struct VersionUncheckedMigrateV1ToV2(sp_std::marker::PhantomData); + impl VersionUncheckedMigrateV1ToV2 { fn run(current: StorageVersion) -> Weight { let mut reward_pools_translated = 0u64; let mut members_translated = 0u64; @@ -337,24 +337,10 @@ pub mod v2 { } } - impl OnRuntimeUpgrade for MigrateToV2 { + impl OnRuntimeUpgrade for VersionUncheckedMigrateV1ToV2 { fn on_runtime_upgrade() -> Weight { let current = Pallet::::current_storage_version(); - let onchain = Pallet::::on_chain_storage_version(); - - log!( - info, - "Running migration with current storage version {:?} / onchain {:?}", - current, - onchain - ); - - if current == 2 && onchain == 1 { - Self::run(current) - } else { - log!(info, "MigrateToV2 did not executed. This probably should be removed"); - T::DbWeight::get().reads(1) - } + Self::run(current) } #[cfg(feature = "try-runtime")] @@ -400,7 +386,7 @@ pub mod v2 { Ok(()) })?; - log!(info, "post upgrade hook for MigrateToV2 executed."); + log!(info, "post upgrade hook for VersionUncheckedMigrateV1ToV2 executed."); Ok(()) } } From 2a41bf3eaaf8115cc8118adcd79ade916df5768c Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Fri, 18 Aug 2023 09:08:22 -0600 Subject: [PATCH 2/4] include `VersionedRuntimeUpgrade` import --- bin/node/runtime/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 9d0f6f8757423..2e58b2e8da429 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -50,6 +50,7 @@ use frame_support::{ ConstantMultiplier, IdentityFee, Weight, }, BoundedVec, PalletId, RuntimeDebug, + migrations::VersionedRuntimeUpgrade }; use frame_system::{ limits::{BlockLength, BlockWeights}, From de830d90ca718c9ea145bcf950ab8bb3a0d7b278 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Fri, 18 Aug 2023 09:14:09 -0600 Subject: [PATCH 3/4] specify the `VersionCheckMigration` --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 2e58b2e8da429..4cb58ab34b20b 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -2010,7 +2010,7 @@ pub type VersionCheckedMigrateV1ToV2 = // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. type Migrations = ( - pallet_nomination_pools::migration::v2::VersionCheckedMigrateV1ToV2, + VersionCheckedMigrateV1ToV2, ); type EventRecord = frame_system::EventRecord< From 5d9e012de7b25cd1cd21eb6f4a430f3409ea47ab Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Fri, 18 Aug 2023 10:53:54 -0600 Subject: [PATCH 4/4] Use `` instead of `` --- bin/node/runtime/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 4cb58ab34b20b..65ff0bb970c49 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -22,8 +22,6 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limits. #![recursion_limit = "1024"] -#![cfg(all(feature = "experimental", feature = "try-runtime"))] - use codec::{Decode, Encode, MaxEncodedLen}; use frame_election_provider_support::{ bounds::{ElectionBounds, ElectionBoundsBuilder}, @@ -1998,19 +1996,19 @@ pub type Executive = frame_executive::Executive< Migrations, >; -pub type VersionCheckedMigrateV1ToV2 = +pub type VersionCheckedMigrateV1ToV2 = VersionedRuntimeUpgrade< 1, 2, - pallet_nomination_pools::migration::v2::VersionUncheckedMigrateV1ToV2, - pallet_nomination_pools::Pallet, - ::DbWeight + pallet_nomination_pools::migration::v2::VersionUncheckedMigrateV1ToV2, + pallet_nomination_pools::Pallet, + ::DbWeight >; // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. type Migrations = ( - VersionCheckedMigrateV1ToV2, + VersionCheckedMigrateV1ToV2, ); type EventRecord = frame_system::EventRecord<