From e6579c545ad768b1ad3c86370e8f27dbb3c68d67 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Sat, 26 Aug 2023 18:34:02 +0700 Subject: [PATCH 1/4] rename VersionedRuntimeUpgrade to VersionedMigration --- .../common/src/assigned_slots/migration.rs | 6 ++--- polkadot/xcm/pallet-xcm/Cargo.toml | 2 +- polkadot/xcm/pallet-xcm/src/migration.rs | 4 +-- substrate/frame/society/Cargo.toml | 2 +- substrate/frame/society/src/migrations.rs | 7 +++-- substrate/frame/support/src/migrations.rs | 26 +++++++++---------- substrate/frame/support/src/traits/hooks.rs | 2 +- .../test/tests/versioned_runtime_upgrade.rs | 12 ++++----- 8 files changed, 30 insertions(+), 31 deletions(-) diff --git a/polkadot/runtime/common/src/assigned_slots/migration.rs b/polkadot/runtime/common/src/assigned_slots/migration.rs index 884d67222d28..e0da5d7b678b 100644 --- a/polkadot/runtime/common/src/assigned_slots/migration.rs +++ b/polkadot/runtime/common/src/assigned_slots/migration.rs @@ -64,10 +64,10 @@ pub mod v1 { } /// [`VersionUncheckedMigrateToV1`] wrapped in a - /// [`frame_support::migrations::VersionedRuntimeUpgrade`], ensuring the migration is only - /// performed when on-chain version is 0. + /// [`frame_support::migrations::VersionedMigration`], ensuring the migration is only performed + /// when on-chain version is 0. #[cfg(feature = "experimental")] - pub type VersionCheckedMigrateToV1 = frame_support::migrations::VersionedRuntimeUpgrade< + pub type VersionCheckedMigrateToV1 = frame_support::migrations::VersionedMigration< 0, 1, MigrateToV1, diff --git a/polkadot/xcm/pallet-xcm/Cargo.toml b/polkadot/xcm/pallet-xcm/Cargo.toml index eefc3c2f5491..654ebe306b72 100644 --- a/polkadot/xcm/pallet-xcm/Cargo.toml +++ b/polkadot/xcm/pallet-xcm/Cargo.toml @@ -32,7 +32,7 @@ xcm-builder = { path = "../xcm-builder" } [features] default = [ "std" ] -# Enable `VersionedRuntimeUpgrade` for the migrations that is currently still experimental. +# Enable `VersionedMigration` for the migrations that is currently still experimental. experimental = [ "frame-support/experimental" ] std = [ "bounded-collections/std", diff --git a/polkadot/xcm/pallet-xcm/src/migration.rs b/polkadot/xcm/pallet-xcm/src/migration.rs index 08809f0d2f2e..5bd94194aaf4 100644 --- a/polkadot/xcm/pallet-xcm/src/migration.rs +++ b/polkadot/xcm/pallet-xcm/src/migration.rs @@ -63,10 +63,10 @@ pub mod v1 { /// Version checked migration to v1. /// - /// Wrapped in VersionedRuntimeUpgrade so the pre/post checks don't begin failing after the + /// Wrapped in [`VersionedMigration`] so the pre/post checks don't begin failing after the /// upgrade is enacted on-chain. #[cfg(feature = "experimental")] - pub type VersionCheckedMigrateToV1 = frame_support::migrations::VersionedRuntimeUpgrade< + pub type VersionCheckedMigrateToV1 = frame_support::migrations::VersionedMigration< 0, 1, VersionUncheckedMigrateToV1, diff --git a/substrate/frame/society/Cargo.toml b/substrate/frame/society/Cargo.toml index 9e2bbe3b3549..8eee017f7cc7 100644 --- a/substrate/frame/society/Cargo.toml +++ b/substrate/frame/society/Cargo.toml @@ -34,7 +34,7 @@ sp-io = { path = "../../primitives/io" } [features] default = [ "std" ] -# Enable `VersionedRuntimeUpgrade` for the migrations that is currently still experimental. +# Enable `VersionedMigration` for migrations using this feature. experimental = [ "frame-support/experimental" ] std = [ "codec/std", diff --git a/substrate/frame/society/src/migrations.rs b/substrate/frame/society/src/migrations.rs index 4685167dcbcf..b50b0e088a6e 100644 --- a/substrate/frame/society/src/migrations.rs +++ b/substrate/frame/society/src/migrations.rs @@ -93,12 +93,11 @@ impl< } } -/// [`VersionUncheckedMigrateToV2`] wrapped in a -/// [`frame_support::migrations::VersionedRuntimeUpgrade`], ensuring the migration is only performed -/// when on-chain version is 0. +/// [`VersionUncheckedMigrateToV2`] wrapped in a [`frame_support::migrations::VersionedMigration`], +/// ensuring the migration is only performed when on-chain version is 0. #[cfg(feature = "experimental")] pub type VersionCheckedMigrateToV2 = - frame_support::migrations::VersionedRuntimeUpgrade< + frame_support::migrations::VersionedMigration< 0, 2, VersionUncheckedMigrateToV2, diff --git a/substrate/frame/support/src/migrations.rs b/substrate/frame/support/src/migrations.rs index 19eec194a76a..6fc1834f01ad 100644 --- a/substrate/frame/support/src/migrations.rs +++ b/substrate/frame/support/src/migrations.rs @@ -28,9 +28,9 @@ use sp_std::marker::PhantomData; /// /// Make it easier to write versioned runtime upgrades. /// -/// [`VersionedRuntimeUpgrade`] allows developers to write migrations without worrying about -/// checking and setting storage versions. Instead, the developer wraps their migration in this -/// struct which takes care of version handling using best practices. +/// [`VersionedMigration`] allows developers to write migrations without worrying about checking and +/// setting storage versions. Instead, the developer wraps their migration in this struct which +/// takes care of version handling using best practices. /// /// It takes 5 type parameters: /// - `From`: The version being upgraded from. @@ -39,11 +39,11 @@ use sp_std::marker::PhantomData; /// - `Pallet`: The Pallet being upgraded. /// - `Weight`: The runtime's RuntimeDbWeight implementation. /// -/// When a [`VersionedRuntimeUpgrade`] `on_runtime_upgrade`, `pre_upgrade`, or `post_upgrade` -/// method is called, the on-chain version of the pallet is compared to `From`. If they match, the -/// `Inner` equivalent is called and the pallets on-chain version is set to `To` after the -/// migration. Otherwise, a warning is logged notifying the developer that the upgrade was a noop -/// and should probably be removed. +/// When a [`VersionedMigration`] `on_runtime_upgrade`, `pre_upgrade`, or `post_upgrade` method is +/// called, the on-chain version of the pallet is compared to `From`. If they match, the `Inner` +/// equivalent is called and the pallets on-chain version is set to `To` after the migration. +/// Otherwise, a warning is logged notifying the developer that the upgrade was a noop and should +/// probably be removed. /// /// ### Examples /// ```ignore @@ -54,7 +54,7 @@ use sp_std::marker::PhantomData; /// } /// /// pub type VersionCheckedMigrateV5ToV6 = -/// VersionedRuntimeUpgrade< +/// VersionedMigration< /// 5, /// 6, /// VersionUncheckedMigrateV5ToV6, @@ -70,7 +70,7 @@ use sp_std::marker::PhantomData; /// ); /// ``` #[cfg(feature = "experimental")] -pub struct VersionedRuntimeUpgrade { +pub struct VersionedMigration { _marker: PhantomData<(Inner, Pallet, Weight)>, } @@ -85,7 +85,7 @@ pub enum VersionedPostUpgradeData { Noop, } -/// Implementation of the `OnRuntimeUpgrade` trait for `VersionedRuntimeUpgrade`. +/// Implementation of the `OnRuntimeUpgrade` trait for `VersionedMigration`. /// /// Its main function is to perform the runtime upgrade in `on_runtime_upgrade` only if the on-chain /// version of the pallets storage matches `From`, and after the upgrade set the on-chain storage to @@ -98,7 +98,7 @@ impl< Inner: crate::traits::OnRuntimeUpgrade, Pallet: GetStorageVersion + PalletInfoAccess, DbWeight: Get, - > crate::traits::OnRuntimeUpgrade for VersionedRuntimeUpgrade + > crate::traits::OnRuntimeUpgrade for VersionedMigration { /// Executes pre_upgrade if the migration will run, and wraps the pre_upgrade bytes in /// [`VersionedPostUpgradeData`] before passing them to post_upgrade, so it knows whether the @@ -158,7 +158,7 @@ impl< ) -> Result<(), sp_runtime::TryRuntimeError> { use codec::DecodeAll; match ::decode_all(&mut &versioned_post_upgrade_data_bytes[..]) - .map_err(|_| "VersionedRuntimeUpgrade post_upgrade failed to decode PreUpgradeData")? + .map_err(|_| "VersionedMigration post_upgrade failed to decode PreUpgradeData")? { VersionedPostUpgradeData::MigrationExecuted(inner_bytes) => Inner::post_upgrade(inner_bytes), diff --git a/substrate/frame/support/src/traits/hooks.rs b/substrate/frame/support/src/traits/hooks.rs index 6163c048e75d..a94e6be613b7 100644 --- a/substrate/frame/support/src/traits/hooks.rs +++ b/substrate/frame/support/src/traits/hooks.rs @@ -359,7 +359,7 @@ pub trait Hooks { /// done. This is helpful to prevent accidental repetitive execution of this hook, which can be /// catastrophic. /// - /// Alternatively, `migrations::VersionedRuntimeUpgrade` can be used to assist with + /// Alternatively, [`frame_support::migrations::VersionedMigration`] can be used to assist with /// this. /// /// ## Implementation Note: Runtime Level Migration diff --git a/substrate/frame/support/test/tests/versioned_runtime_upgrade.rs b/substrate/frame/support/test/tests/versioned_runtime_upgrade.rs index 93d87df8ca18..a0766f6bec25 100644 --- a/substrate/frame/support/test/tests/versioned_runtime_upgrade.rs +++ b/substrate/frame/support/test/tests/versioned_runtime_upgrade.rs @@ -15,13 +15,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Tests for VersionedRuntimeUpgrade +//! Tests for [`VersionedMigration`] #![cfg(all(feature = "experimental", feature = "try-runtime"))] use frame_support::{ construct_runtime, derive_impl, - migrations::VersionedRuntimeUpgrade, + migrations::VersionedMigration, parameter_types, traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}, weights::constants::RocksDbWeight, @@ -90,7 +90,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities { ext } -/// A dummy migration for testing the `VersionedRuntimeUpgrade` trait. +/// A dummy migration for testing the `VersionedMigration` trait. /// Sets SomeStorage to S. struct SomeUnversionedMigration(sp_std::marker::PhantomData); @@ -124,13 +124,13 @@ impl OnRuntimeUpgrade for SomeUnversioned } type VersionedMigrationV0ToV1 = - VersionedRuntimeUpgrade<0, 1, SomeUnversionedMigration, DummyPallet, RocksDbWeight>; + VersionedMigration<0, 1, SomeUnversionedMigration, DummyPallet, RocksDbWeight>; type VersionedMigrationV1ToV2 = - VersionedRuntimeUpgrade<1, 2, SomeUnversionedMigration, DummyPallet, RocksDbWeight>; + VersionedMigration<1, 2, SomeUnversionedMigration, DummyPallet, RocksDbWeight>; type VersionedMigrationV2ToV4 = - VersionedRuntimeUpgrade<2, 4, SomeUnversionedMigration, DummyPallet, RocksDbWeight>; + VersionedMigration<2, 4, SomeUnversionedMigration, DummyPallet, RocksDbWeight>; #[test] fn successful_upgrade_path() { From 38a683f8f0daef3d3f3e8571739819d9ce9b6ed1 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Sat, 26 Aug 2023 18:36:09 +0700 Subject: [PATCH 2/4] doc lint --- polkadot/xcm/pallet-xcm/Cargo.toml | 2 +- polkadot/xcm/pallet-xcm/src/migration.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/Cargo.toml b/polkadot/xcm/pallet-xcm/Cargo.toml index 654ebe306b72..cd30abbec91e 100644 --- a/polkadot/xcm/pallet-xcm/Cargo.toml +++ b/polkadot/xcm/pallet-xcm/Cargo.toml @@ -32,7 +32,7 @@ xcm-builder = { path = "../xcm-builder" } [features] default = [ "std" ] -# Enable `VersionedMigration` for the migrations that is currently still experimental. +# Enable `VersionedMigration` for the migrations using the experimental feature. experimental = [ "frame-support/experimental" ] std = [ "bounded-collections/std", diff --git a/polkadot/xcm/pallet-xcm/src/migration.rs b/polkadot/xcm/pallet-xcm/src/migration.rs index 5bd94194aaf4..e28ca56563c6 100644 --- a/polkadot/xcm/pallet-xcm/src/migration.rs +++ b/polkadot/xcm/pallet-xcm/src/migration.rs @@ -63,8 +63,8 @@ pub mod v1 { /// Version checked migration to v1. /// - /// Wrapped in [`VersionedMigration`] so the pre/post checks don't begin failing after the - /// upgrade is enacted on-chain. + /// Wrapped in [`frame_support::migrations::VersionedMigration`] so the pre/post checks don't + /// begin failing after the upgrade is enacted on-chain. #[cfg(feature = "experimental")] pub type VersionCheckedMigrateToV1 = frame_support::migrations::VersionedMigration< 0, From d3d62811c5c3659f72c0cb14074c6d418a47eb3d Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Sun, 27 Aug 2023 14:13:27 +0700 Subject: [PATCH 3/4] rename test filename --- .../{versioned_runtime_upgrade.rs => versioned_migration.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename substrate/frame/support/test/tests/{versioned_runtime_upgrade.rs => versioned_migration.rs} (100%) diff --git a/substrate/frame/support/test/tests/versioned_runtime_upgrade.rs b/substrate/frame/support/test/tests/versioned_migration.rs similarity index 100% rename from substrate/frame/support/test/tests/versioned_runtime_upgrade.rs rename to substrate/frame/support/test/tests/versioned_migration.rs From 8b0451169cd15b95114f5b179b4a6400c33a38a2 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Wed, 30 Aug 2023 13:41:31 +1000 Subject: [PATCH 4/4] cargo +nightly fmt --- polkadot/runtime/common/src/assigned_slots/migration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/common/src/assigned_slots/migration.rs b/polkadot/runtime/common/src/assigned_slots/migration.rs index 3770e8b8e42c..6a84ea3ccc42 100644 --- a/polkadot/runtime/common/src/assigned_slots/migration.rs +++ b/polkadot/runtime/common/src/assigned_slots/migration.rs @@ -64,8 +64,8 @@ pub mod v1 { } /// [`MigrateToV1`] wrapped in a - /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the migration - /// is only performed when on-chain version is 0. + /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the + /// migration is only performed when on-chain version is 0. #[cfg(feature = "experimental")] pub type VersionCheckedMigrateToV1 = frame_support::migrations::VersionedMigration< 0,