Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

add VersionedRuntimeUpgrade to kitchensink runtime #14785

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
14 changes: 11 additions & 3 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use frame_support::{
ConstantMultiplier, IdentityFee, Weight,
},
BoundedVec, PalletId, RuntimeDebug,
migrations::VersionedRuntimeUpgrade
};
use frame_system::{
limits::{BlockLength, BlockWeights},
Expand Down Expand Up @@ -1995,12 +1996,19 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

pub type VersionCheckedMigrateV1ToV2<Runtime> =
VersionedRuntimeUpgrade<
1,
2,
pallet_nomination_pools::migration::v2::VersionUncheckedMigrateV1ToV2<Runtime>,
pallet_nomination_pools::Pallet<Runtime>,
<Runtime as frame_system::Config>::DbWeight
>;

// All migrations executed on runtime upgrade as a nested tuple of types implementing
// `OnRuntimeUpgrade`.
type Migrations = (
pallet_nomination_pools::migration::v2::MigrateToV2<Runtime>,
pallet_alliance::migration::Migration<Runtime>,
pallet_contracts::Migration<Runtime>,
VersionCheckedMigrateV1ToV2<Runtime>,
);

type EventRecord = frame_system::EventRecord<
Expand Down
24 changes: 5 additions & 19 deletions frame/nomination-pools/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ pub mod v2 {

/// Migrate the pool reward scheme to the new version, as per
/// <https://github.com/paritytech/substrate/pull/11669.>.
pub struct MigrateToV2<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> MigrateToV2<T> {
pub struct VersionUncheckedMigrateV1ToV2<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> VersionUncheckedMigrateV1ToV2<T> {
fn run(current: StorageVersion) -> Weight {
let mut reward_pools_translated = 0u64;
let mut members_translated = 0u64;
Expand Down Expand Up @@ -337,24 +337,10 @@ pub mod v2 {
}
}

impl<T: Config> OnRuntimeUpgrade for MigrateToV2<T> {
impl<T: Config> OnRuntimeUpgrade for VersionUncheckedMigrateV1ToV2<T> {
fn on_runtime_upgrade() -> Weight {
let current = Pallet::<T>::current_storage_version();
let onchain = Pallet::<T>::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")]
Expand Down Expand Up @@ -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(())
}
}
Expand Down