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 3 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
16 changes: 13 additions & 3 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#![cfg(all(feature = "experimental", feature = "try-runtime"))]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove that line I get:

Compiling kitchensink-runtime v3.0.0-dev (/home/bruno/src/substrate/bin/node/runtime)
error: failed to run custom build command for `kitchensink-runtime v3.0.0-dev (/home/bruno/src/substrate/bin/node/runtime)`

Caused by:
  process didn't exit successfully: `/home/bruno/src/substrate/target/debug/build/kitchensink-runtime-b16098d4b7703ca7/build-script-build` (exit status: 1)
  --- stdout
  Information that should be included in a bug report.
  Executing build command: RUSTFLAGS="-C target-cpu=mvp -C target-feature=-sign-ext -C link-arg=--export-table -Clink-arg=--export=__heap_base -C link-arg=--import-memory  " SKIP_WASM_BUILD="" "/home/bruno/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/home/bruno/src/substrate/target/debug/wbuild/kitchensink-runtime/Cargo.toml" "--color=always" "--profile" "release"
  Using rustc version: rustc 1.70.0 (90c541806 2023-05-31)

use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::{
bounds::{ElectionBounds, ElectionBoundsBuilder},
Expand All @@ -48,6 +50,7 @@ use frame_support::{
ConstantMultiplier, IdentityFee, Weight,
},
BoundedVec, PalletId, RuntimeDebug,
migrations::VersionedRuntimeUpgrade
};
use frame_system::{
limits::{BlockLength, BlockWeights},
Expand Down Expand Up @@ -1995,12 +1998,19 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

pub type VersionCheckedMigrateV1ToV2<T, I> =
VersionedRuntimeUpgrade<
1,
2,
pallet_nomination_pools::migration::v2::VersionUncheckedMigrateV1ToV2<T, I>,
pallet_nomination_pools::Pallet<T>,
<T 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<T, ()>,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic <T> is not found in this scope.

);

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
Loading