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

Contracts: Use RuntimeUpgrade hooks instead of Hooks::on_runtime_upgrade #2570

Merged
merged 11 commits into from
Jun 5, 2023
11 changes: 9 additions & 2 deletions pallets/dmp-queue/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
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);
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

/// Migrates the pallet storage to the most recent version, checking and setting the
/// `StorageVersion`.
Expand All @@ -46,6 +46,13 @@ pub fn migrate_to_latest<T: Config>() -> Weight {
weight
}

pub struct Migration<T: Config>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> Weight {
migrate_to_latest::<T>()
}
}

mod v0 {
use super::*;
use codec::{Decode, Encode};
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion pallets/parachain-system/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

use crate::{Config, Pallet, ReservedDmpWeightOverride, ReservedXcmpWeightOverride};
use frame_support::{
traits::{Get, StorageVersion},
pallet_prelude::*,
traits::{Get, OnRuntimeUpgrade, StorageVersion},
weights::Weight,
};

Expand Down Expand Up @@ -44,6 +45,13 @@ pub fn on_runtime_upgrade<T: Config>() -> Weight {
weight
}

pub struct Migration<T: Config>(PhantomData<T>);
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> Weight {
on_runtime_upgrade::<T>()
}
}

/// V2: Migrate to 2D weights for ReservedXcmpWeightOverride and ReservedDmpWeightOverride.
mod v2 {
use super::*;
Expand Down
11 changes: 9 additions & 2 deletions pallets/xcmp-queue/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
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);
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);

/// Migrates the pallet storage to the most recent version, checking and setting the
/// `StorageVersion`.
Expand All @@ -46,6 +46,13 @@ pub fn migrate_to_latest<T: Config>() -> Weight {
weight
}

pub struct Migration<T: Config>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> Weight {
migrate_to_latest::<T>()
}
}

mod v1 {
use super::*;
use codec::{Decode, Encode};
Expand Down
1 change: 1 addition & 0 deletions parachains/runtimes/contracts/contracts-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion parachains/runtimes/contracts/contracts-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ pub type UncheckedExtrinsic =
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;

pub type Migrations = (pallet_contracts::Migration<Runtime>,);
pub type Migrations = (
cumulus_pallet_parachain_system::migration::Migration<Runtime>,
cumulus_pallet_xcmp_queue::migration::Migration<Runtime>,
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
pallet_contracts::Migration<Runtime>,
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
cumulus_pallet_dmp_queue::migration::Migration<Runtime>,
);

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down