Skip to content

Commit

Permalink
rename VersionedRuntimeUpgrade to VersionedMigration
Browse files Browse the repository at this point in the history
  • Loading branch information
liamaharon committed Aug 26, 2023
1 parent 2c17d39 commit e6579c5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
6 changes: 3 additions & 3 deletions polkadot/runtime/common/src/assigned_slots/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = frame_support::migrations::VersionedRuntimeUpgrade<
pub type VersionCheckedMigrateToV1<T> = frame_support::migrations::VersionedMigration<
0,
1,
MigrateToV1<T>,
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/pallet-xcm/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = frame_support::migrations::VersionedRuntimeUpgrade<
pub type VersionCheckedMigrateToV1<T> = frame_support::migrations::VersionedMigration<
0,
1,
VersionUncheckedMigrateToV1<T>,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/society/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions substrate/frame/society/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, I, PastPayouts> =
frame_support::migrations::VersionedRuntimeUpgrade<
frame_support::migrations::VersionedMigration<
0,
2,
VersionUncheckedMigrateToV2<T, I, PastPayouts>,
Expand Down
26 changes: 13 additions & 13 deletions substrate/frame/support/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -54,7 +54,7 @@ use sp_std::marker::PhantomData;
/// }
///
/// pub type VersionCheckedMigrateV5ToV6<T, I> =
/// VersionedRuntimeUpgrade<
/// VersionedMigration<
/// 5,
/// 6,
/// VersionUncheckedMigrateV5ToV6<T, I>,
Expand All @@ -70,7 +70,7 @@ use sp_std::marker::PhantomData;
/// );
/// ```
#[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)>,
}

Expand All @@ -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
Expand All @@ -98,7 +98,7 @@ impl<
Inner: crate::traits::OnRuntimeUpgrade,
Pallet: GetStorageVersion<CurrentStorageVersion = StorageVersion> + PalletInfoAccess,
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
/// [`VersionedPostUpgradeData`] before passing them to post_upgrade, so it knows whether the
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<
) -> Result<(), sp_runtime::TryRuntimeError> {
use codec::DecodeAll;
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) =>
Inner::post_upgrade(inner_bytes),
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/src/traits/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ pub trait Hooks<BlockNumber> {
/// 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
Expand Down
12 changes: 6 additions & 6 deletions substrate/frame/support/test/tests/versioned_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<T: Config, const S: u32>(sp_std::marker::PhantomData<T>);

Expand Down Expand Up @@ -124,13 +124,13 @@ impl<T: dummy_pallet::Config, const S: u32> OnRuntimeUpgrade for SomeUnversioned
}

type VersionedMigrationV0ToV1 =
VersionedRuntimeUpgrade<0, 1, SomeUnversionedMigration<Test, 1>, DummyPallet, RocksDbWeight>;
VersionedMigration<0, 1, SomeUnversionedMigration<Test, 1>, DummyPallet, RocksDbWeight>;

type VersionedMigrationV1ToV2 =
VersionedRuntimeUpgrade<1, 2, SomeUnversionedMigration<Test, 2>, DummyPallet, RocksDbWeight>;
VersionedMigration<1, 2, SomeUnversionedMigration<Test, 2>, DummyPallet, RocksDbWeight>;

type VersionedMigrationV2ToV4 =
VersionedRuntimeUpgrade<2, 4, SomeUnversionedMigration<Test, 4>, DummyPallet, RocksDbWeight>;
VersionedMigration<2, 4, SomeUnversionedMigration<Test, 4>, DummyPallet, RocksDbWeight>;

#[test]
fn successful_upgrade_path() {
Expand Down

0 comments on commit e6579c5

Please sign in to comment.