diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 66329007ec0..aaa9af7a6a9 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -139,10 +139,6 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_runtime_upgrade() -> Weight { - migration::migrate_to_latest::() - } - fn on_idle(_now: T::BlockNumber, max_weight: Weight) -> Weight { // on_idle processes additional messages with any remaining block weight. Self::service_queue(max_weight) diff --git a/pallets/dmp-queue/src/migration.rs b/pallets/dmp-queue/src/migration.rs index 5e1d357e142..b2323f6a60f 100644 --- a/pallets/dmp-queue/src/migration.rs +++ b/pallets/dmp-queue/src/migration.rs @@ -19,31 +19,34 @@ use crate::{Config, Configuration, Overweight, Pallet, DEFAULT_POV_SIZE}; use frame_support::{ pallet_prelude::*, - traits::StorageVersion, + traits::{OnRuntimeUpgrade, StorageVersion}, weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight}, }; /// The current storage version. -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); +pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); -/// Migrates the pallet storage to the most recent version, checking and setting the -/// `StorageVersion`. -pub fn migrate_to_latest() -> Weight { - let mut weight = T::DbWeight::get().reads(1); +/// Migrates the pallet storage to the most recent version. +pub struct Migration(PhantomData); - if StorageVersion::get::>() == 0 { - weight.saturating_accrue(migrate_to_v1::()); - StorageVersion::new(1).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - } +impl OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> Weight { + let mut weight = T::DbWeight::get().reads(1); - if StorageVersion::get::>() == 1 { - weight.saturating_accrue(migrate_to_v2::()); - StorageVersion::new(2).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - } + if StorageVersion::get::>() == 0 { + weight.saturating_accrue(migrate_to_v1::()); + StorageVersion::new(1).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); + } - weight + if StorageVersion::get::>() == 1 { + weight.saturating_accrue(migrate_to_v2::()); + StorageVersion::new(2).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); + } + + weight + } } mod v0 { diff --git a/pallets/parachain-system/src/lib.rs b/pallets/parachain-system/src/lib.rs index 5f7e1501570..43ada564ee4 100644 --- a/pallets/parachain-system/src/lib.rs +++ b/pallets/parachain-system/src/lib.rs @@ -57,7 +57,7 @@ use sp_runtime::{ use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*}; use xcm::latest::XcmHash; -mod migration; +pub mod migration; mod relay_state_snapshot; #[macro_use] pub mod validate_block; @@ -197,10 +197,6 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_runtime_upgrade() -> Weight { - migration::on_runtime_upgrade::() - } - fn on_finalize(_: T::BlockNumber) { >::kill(); >::kill(); diff --git a/pallets/parachain-system/src/migration.rs b/pallets/parachain-system/src/migration.rs index e3d1e11a51b..17dce3a11a9 100644 --- a/pallets/parachain-system/src/migration.rs +++ b/pallets/parachain-system/src/migration.rs @@ -16,32 +16,37 @@ use crate::{Config, Pallet, ReservedDmpWeightOverride, ReservedXcmpWeightOverride}; use frame_support::{ - traits::{Get, StorageVersion}, + pallet_prelude::*, + traits::{Get, OnRuntimeUpgrade, StorageVersion}, weights::Weight, }; /// The current storage version. pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); -/// Call this during the next runtime upgrade for this module. -pub fn on_runtime_upgrade() -> Weight { - let mut weight: Weight = T::DbWeight::get().reads(2); +/// Migrates the pallet storage to the most recent version. +pub struct Migration(PhantomData); - if StorageVersion::get::>() == 0 { - weight = weight - .saturating_add(v1::migrate::()) - .saturating_add(T::DbWeight::get().writes(1)); - StorageVersion::new(1).put::>(); - } +impl OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> Weight { + let mut weight: Weight = T::DbWeight::get().reads(2); - if StorageVersion::get::>() == 1 { - weight = weight - .saturating_add(v2::migrate::()) - .saturating_add(T::DbWeight::get().writes(1)); - STORAGE_VERSION.put::>(); - } + if StorageVersion::get::>() == 0 { + weight = weight + .saturating_add(v1::migrate::()) + .saturating_add(T::DbWeight::get().writes(1)); + StorageVersion::new(1).put::>(); + } - weight + if StorageVersion::get::>() == 1 { + weight = weight + .saturating_add(v2::migrate::()) + .saturating_add(T::DbWeight::get().writes(1)); + StorageVersion::new(2).put::>(); + } + + weight + } } /// V2: Migrate to 2D weights for ReservedXcmpWeightOverride and ReservedDmpWeightOverride. diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index 93c9100f520..12ee6dae25a 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -115,10 +115,6 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_runtime_upgrade() -> Weight { - migration::migrate_to_latest::() - } - fn on_idle(_now: T::BlockNumber, max_weight: Weight) -> Weight { // on_idle processes additional messages with any remaining block weight. Self::service_xcmp_queue(max_weight) diff --git a/pallets/xcmp-queue/src/migration.rs b/pallets/xcmp-queue/src/migration.rs index fd1301b9491..bda54620cd9 100644 --- a/pallets/xcmp-queue/src/migration.rs +++ b/pallets/xcmp-queue/src/migration.rs @@ -19,31 +19,34 @@ use crate::{Config, Overweight, Pallet, QueueConfig, DEFAULT_POV_SIZE}; use frame_support::{ pallet_prelude::*, - traits::StorageVersion, + traits::{OnRuntimeUpgrade, StorageVersion}, weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight}, }; /// The current storage version. -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); +pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); -/// Migrates the pallet storage to the most recent version, checking and setting the -/// `StorageVersion`. -pub fn migrate_to_latest() -> Weight { - let mut weight = T::DbWeight::get().reads(1); +/// Migrates the pallet storage to the most recent version. +pub struct Migration(PhantomData); - if StorageVersion::get::>() == 1 { - weight.saturating_accrue(migrate_to_v2::()); - StorageVersion::new(2).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - } +impl OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> Weight { + let mut weight = T::DbWeight::get().reads(1); - if StorageVersion::get::>() == 2 { - weight.saturating_accrue(migrate_to_v3::()); - StorageVersion::new(3).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - } + if StorageVersion::get::>() == 1 { + weight.saturating_accrue(migrate_to_v2::()); + StorageVersion::new(2).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); + } - weight + if StorageVersion::get::>() == 2 { + weight.saturating_accrue(migrate_to_v3::()); + StorageVersion::new(3).put::>(); + weight.saturating_accrue(T::DbWeight::get().writes(1)); + } + + weight + } } mod v1 { diff --git a/parachains/runtimes/contracts/contracts-rococo/Cargo.toml b/parachains/runtimes/contracts/contracts-rococo/Cargo.toml index 37996e29586..7908002d9c4 100644 --- a/parachains/runtimes/contracts/contracts-rococo/Cargo.toml +++ b/parachains/runtimes/contracts/contracts-rococo/Cargo.toml @@ -86,6 +86,7 @@ std = [ "frame-support/std", "frame-system-rpc-runtime-api/std", "frame-system/std", + "frame-try-runtime/std", "kusama-runtime-constants/std", "pallet-aura/std", "pallet-authorship/std", diff --git a/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index d90c60990c4..b7401b58642 100644 --- a/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -95,9 +95,16 @@ pub type SignedExtra = ( pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; +/// Migrations to apply on runtime upgrade. pub type Migrations = ( + cumulus_pallet_dmp_queue::migration::Migration, + cumulus_pallet_parachain_system::migration::Migration, + cumulus_pallet_xcmp_queue::migration::Migration, + pallet_balances::migration::MigrateToTrackInactive, pallet_contracts::Migration, + pallet_multisig::migrations::v1::MigrateToV1, pallet_collator_selection::migration::v1::MigrateToV1, + pallet_xcm::migration::v1::MigrateToV1, ); type EventRecord = frame_system::EventRecord< diff --git a/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index 2f39cc6536d..c386e8880c6 100644 --- a/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -43,6 +43,7 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const ExecutiveBody: BodyId = BodyId::Executive; + pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } /// We allow root and the Relay Chain council to execute privileged collator selection operations.