Rename VersionedRuntimeUpgrade to VersionedMigration (#1187)

* rename VersionedRuntimeUpgrade to VersionedMigration

* doc lint

* rename test filename

---------

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Liam Aharon
2023-08-30 14:28:03 +10:00
committed by GitHub
parent b4ee6f2aa9
commit 2f49252bcd
8 changed files with 31 additions and 32 deletions
@@ -64,10 +64,10 @@ pub mod v1 {
} }
/// [`MigrateToV1`] wrapped in a /// [`MigrateToV1`] wrapped in a
/// [`VersionedRuntimeUpgrade`](frame_support::migrations::VersionedRuntimeUpgrade), ensuring /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the
/// the migration is only performed when on-chain version is 0. /// migration is only performed when on-chain version is 0.
#[cfg(feature = "experimental")] #[cfg(feature = "experimental")]
pub type VersionCheckedMigrateToV1<T> = frame_support::migrations::VersionedRuntimeUpgrade< pub type VersionCheckedMigrateToV1<T> = frame_support::migrations::VersionedMigration<
0, 0,
1, 1,
MigrateToV1<T>, MigrateToV1<T>,
+1 -1
View File
@@ -32,7 +32,7 @@ xcm-builder = { path = "../xcm-builder" }
[features] [features]
default = [ "std" ] default = [ "std" ]
# Enable `VersionedRuntimeUpgrade` for the migrations that is currently still experimental. # Enable `VersionedMigration` for the migrations using the experimental feature.
experimental = [ "frame-support/experimental" ] experimental = [ "frame-support/experimental" ]
std = [ std = [
"bounded-collections/std", "bounded-collections/std",
+3 -3
View File
@@ -63,10 +63,10 @@ pub mod v1 {
/// Version checked migration to v1. /// Version checked migration to v1.
/// ///
/// Wrapped in VersionedRuntimeUpgrade so the pre/post checks don't begin failing after the /// Wrapped in [`frame_support::migrations::VersionedMigration`] so the pre/post checks don't
/// upgrade is enacted on-chain. /// begin failing after the upgrade is enacted on-chain.
#[cfg(feature = "experimental")] #[cfg(feature = "experimental")]
pub type VersionCheckedMigrateToV1<T> = frame_support::migrations::VersionedRuntimeUpgrade< pub type VersionCheckedMigrateToV1<T> = frame_support::migrations::VersionedMigration<
0, 0,
1, 1,
VersionUncheckedMigrateToV1<T>, VersionUncheckedMigrateToV1<T>,
+1 -1
View File
@@ -34,7 +34,7 @@ sp-io = { path = "../../primitives/io" }
[features] [features]
default = [ "std" ] default = [ "std" ]
# Enable `VersionedRuntimeUpgrade` for the migrations that is currently still experimental. # Enable `VersionedMigration` for migrations using this feature.
experimental = [ "frame-support/experimental" ] experimental = [ "frame-support/experimental" ]
std = [ std = [
"codec/std", "codec/std",
+3 -4
View File
@@ -93,12 +93,11 @@ impl<
} }
} }
/// [`VersionUncheckedMigrateToV2`] wrapped in a /// [`VersionUncheckedMigrateToV2`] wrapped in a [`frame_support::migrations::VersionedMigration`],
/// [`frame_support::migrations::VersionedRuntimeUpgrade`], ensuring the migration is only performed /// ensuring the migration is only performed when on-chain version is 0.
/// when on-chain version is 0.
#[cfg(feature = "experimental")] #[cfg(feature = "experimental")]
pub type VersionCheckedMigrateToV2<T, I, PastPayouts> = pub type VersionCheckedMigrateToV2<T, I, PastPayouts> =
frame_support::migrations::VersionedRuntimeUpgrade< frame_support::migrations::VersionedMigration<
0, 0,
2, 2,
VersionUncheckedMigrateToV2<T, I, PastPayouts>, VersionUncheckedMigrateToV2<T, I, PastPayouts>,
+13 -13
View File
@@ -28,9 +28,9 @@ use sp_std::marker::PhantomData;
/// ///
/// Make it easier to write versioned runtime upgrades. /// Make it easier to write versioned runtime upgrades.
/// ///
/// [`VersionedRuntimeUpgrade`] allows developers to write migrations without worrying about /// [`VersionedMigration`] allows developers to write migrations without worrying about checking and
/// checking and setting storage versions. Instead, the developer wraps their migration in this /// setting storage versions. Instead, the developer wraps their migration in this struct which
/// struct which takes care of version handling using best practices. /// takes care of version handling using best practices.
/// ///
/// It takes 5 type parameters: /// It takes 5 type parameters:
/// - `From`: The version being upgraded from. /// - `From`: The version being upgraded from.
@@ -39,11 +39,11 @@ use sp_std::marker::PhantomData;
/// - `Pallet`: The Pallet being upgraded. /// - `Pallet`: The Pallet being upgraded.
/// - `Weight`: The runtime's RuntimeDbWeight implementation. /// - `Weight`: The runtime's RuntimeDbWeight implementation.
/// ///
/// When a [`VersionedRuntimeUpgrade`] `on_runtime_upgrade`, `pre_upgrade`, or `post_upgrade` /// When a [`VersionedMigration`] `on_runtime_upgrade`, `pre_upgrade`, or `post_upgrade` method is
/// method is called, the on-chain version of the pallet is compared to `From`. If they match, the /// called, the on-chain version of the pallet is compared to `From`. If they match, the `Inner`
/// `Inner` equivalent is called and the pallets on-chain version is set to `To` after the /// equivalent is called and the pallets on-chain version is set to `To` after the migration.
/// migration. Otherwise, a warning is logged notifying the developer that the upgrade was a noop /// Otherwise, a warning is logged notifying the developer that the upgrade was a noop and should
/// and should probably be removed. /// probably be removed.
/// ///
/// ### Examples /// ### Examples
/// ```ignore /// ```ignore
@@ -54,7 +54,7 @@ use sp_std::marker::PhantomData;
/// } /// }
/// ///
/// pub type VersionCheckedMigrateV5ToV6<T, I> = /// pub type VersionCheckedMigrateV5ToV6<T, I> =
/// VersionedRuntimeUpgrade< /// VersionedMigration<
/// 5, /// 5,
/// 6, /// 6,
/// VersionUncheckedMigrateV5ToV6<T, I>, /// VersionUncheckedMigrateV5ToV6<T, I>,
@@ -70,7 +70,7 @@ use sp_std::marker::PhantomData;
/// ); /// );
/// ``` /// ```
#[cfg(feature = "experimental")] #[cfg(feature = "experimental")]
pub struct VersionedRuntimeUpgrade<const FROM: u16, const TO: u16, Inner, Pallet, Weight> { pub struct VersionedMigration<const FROM: u16, const TO: u16, Inner, Pallet, Weight> {
_marker: PhantomData<(Inner, Pallet, Weight)>, _marker: PhantomData<(Inner, Pallet, Weight)>,
} }
@@ -85,7 +85,7 @@ pub enum VersionedPostUpgradeData {
Noop, 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 /// 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 /// 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, Inner: crate::traits::OnRuntimeUpgrade,
Pallet: GetStorageVersion<CurrentStorageVersion = StorageVersion> + PalletInfoAccess, Pallet: GetStorageVersion<CurrentStorageVersion = StorageVersion> + PalletInfoAccess,
DbWeight: Get<RuntimeDbWeight>, DbWeight: Get<RuntimeDbWeight>,
> crate::traits::OnRuntimeUpgrade for VersionedRuntimeUpgrade<FROM, TO, Inner, Pallet, DbWeight> > crate::traits::OnRuntimeUpgrade for VersionedMigration<FROM, TO, Inner, Pallet, DbWeight>
{ {
/// Executes pre_upgrade if the migration will run, and wraps the pre_upgrade bytes in /// 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 /// [`VersionedPostUpgradeData`] before passing them to post_upgrade, so it knows whether the
@@ -158,7 +158,7 @@ impl<
) -> Result<(), sp_runtime::TryRuntimeError> { ) -> Result<(), sp_runtime::TryRuntimeError> {
use codec::DecodeAll; use codec::DecodeAll;
match <VersionedPostUpgradeData>::decode_all(&mut &versioned_post_upgrade_data_bytes[..]) match <VersionedPostUpgradeData>::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) => VersionedPostUpgradeData::MigrationExecuted(inner_bytes) =>
Inner::post_upgrade(inner_bytes), Inner::post_upgrade(inner_bytes),
+1 -1
View File
@@ -359,7 +359,7 @@ pub trait Hooks<BlockNumber> {
/// done. This is helpful to prevent accidental repetitive execution of this hook, which can be /// done. This is helpful to prevent accidental repetitive execution of this hook, which can be
/// catastrophic. /// catastrophic.
/// ///
/// Alternatively, `migrations::VersionedRuntimeUpgrade` can be used to assist with /// Alternatively, [`frame_support::migrations::VersionedMigration`] can be used to assist with
/// this. /// this.
/// ///
/// ## Implementation Note: Runtime Level Migration /// ## Implementation Note: Runtime Level Migration
@@ -15,13 +15,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Tests for VersionedRuntimeUpgrade //! Tests for [`VersionedMigration`]
#![cfg(all(feature = "experimental", feature = "try-runtime"))] #![cfg(all(feature = "experimental", feature = "try-runtime"))]
use frame_support::{ use frame_support::{
construct_runtime, derive_impl, construct_runtime, derive_impl,
migrations::VersionedRuntimeUpgrade, migrations::VersionedMigration,
parameter_types, parameter_types,
traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion}, traits::{GetStorageVersion, OnRuntimeUpgrade, StorageVersion},
weights::constants::RocksDbWeight, weights::constants::RocksDbWeight,
@@ -90,7 +90,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
ext ext
} }
/// A dummy migration for testing the `VersionedRuntimeUpgrade` trait. /// A dummy migration for testing the `VersionedMigration` trait.
/// Sets SomeStorage to S. /// Sets SomeStorage to S.
struct SomeUnversionedMigration<T: Config, const S: u32>(sp_std::marker::PhantomData<T>); struct SomeUnversionedMigration<T: Config, const S: u32>(sp_std::marker::PhantomData<T>);
@@ -124,13 +124,13 @@ impl<T: dummy_pallet::Config, const S: u32> OnRuntimeUpgrade for SomeUnversioned
} }
type VersionedMigrationV0ToV1 = type VersionedMigrationV0ToV1 =
VersionedRuntimeUpgrade<0, 1, SomeUnversionedMigration<Test, 1>, DummyPallet, RocksDbWeight>; VersionedMigration<0, 1, SomeUnversionedMigration<Test, 1>, DummyPallet, RocksDbWeight>;
type VersionedMigrationV1ToV2 = type VersionedMigrationV1ToV2 =
VersionedRuntimeUpgrade<1, 2, SomeUnversionedMigration<Test, 2>, DummyPallet, RocksDbWeight>; VersionedMigration<1, 2, SomeUnversionedMigration<Test, 2>, DummyPallet, RocksDbWeight>;
type VersionedMigrationV2ToV4 = type VersionedMigrationV2ToV4 =
VersionedRuntimeUpgrade<2, 4, SomeUnversionedMigration<Test, 4>, DummyPallet, RocksDbWeight>; VersionedMigration<2, 4, SomeUnversionedMigration<Test, 4>, DummyPallet, RocksDbWeight>;
#[test] #[test]
fn successful_upgrade_path() { fn successful_upgrade_path() {