mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 00:17:56 +00:00
Contracts: Use RuntimeUpgrade hooks instead of Hooks::on_runtime_upgrade (#2570)
* Fixes * Remove on_runtime_upgrade hook * remove upgrade_fn / add doc to Migration struct * Add cumulus_pallet_*::migration to Migrations type * add docstring * fix * Update parachain-template/runtime/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs * Update pallets/parachain-system/src/migration.rs --------- Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -139,10 +139,6 @@ pub mod pallet {
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
migration::migrate_to_latest::<T>()
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -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<T: Config>() -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
/// Migrates the pallet storage to the most recent version.
|
||||
pub struct Migration<T: Config>(PhantomData<T>);
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 0 {
|
||||
weight.saturating_accrue(migrate_to_v1::<T>());
|
||||
StorageVersion::new(1).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 0 {
|
||||
weight.saturating_accrue(migrate_to_v1::<T>());
|
||||
StorageVersion::new(1).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
}
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 1 {
|
||||
weight.saturating_accrue(migrate_to_v2::<T>());
|
||||
StorageVersion::new(2).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
}
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 1 {
|
||||
weight.saturating_accrue(migrate_to_v2::<T>());
|
||||
StorageVersion::new(2).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
}
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
mod v0 {
|
||||
|
||||
@@ -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<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
migration::on_runtime_upgrade::<T>()
|
||||
}
|
||||
|
||||
fn on_finalize(_: T::BlockNumber) {
|
||||
<DidSetValidationCode<T>>::kill();
|
||||
<UpgradeRestrictionSignal<T>>::kill();
|
||||
|
||||
@@ -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<T: Config>() -> Weight {
|
||||
let mut weight: Weight = T::DbWeight::get().reads(2);
|
||||
/// Migrates the pallet storage to the most recent version.
|
||||
pub struct Migration<T: Config>(PhantomData<T>);
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 0 {
|
||||
weight = weight
|
||||
.saturating_add(v1::migrate::<T>())
|
||||
.saturating_add(T::DbWeight::get().writes(1));
|
||||
StorageVersion::new(1).put::<Pallet<T>>();
|
||||
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
let mut weight: Weight = T::DbWeight::get().reads(2);
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 0 {
|
||||
weight = weight
|
||||
.saturating_add(v1::migrate::<T>())
|
||||
.saturating_add(T::DbWeight::get().writes(1));
|
||||
StorageVersion::new(1).put::<Pallet<T>>();
|
||||
}
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 1 {
|
||||
weight = weight
|
||||
.saturating_add(v2::migrate::<T>())
|
||||
.saturating_add(T::DbWeight::get().writes(1));
|
||||
StorageVersion::new(2).put::<Pallet<T>>();
|
||||
}
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 1 {
|
||||
weight = weight
|
||||
.saturating_add(v2::migrate::<T>())
|
||||
.saturating_add(T::DbWeight::get().writes(1));
|
||||
STORAGE_VERSION.put::<Pallet<T>>();
|
||||
}
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
/// V2: Migrate to 2D weights for ReservedXcmpWeightOverride and ReservedDmpWeightOverride.
|
||||
|
||||
@@ -115,10 +115,6 @@ pub mod pallet {
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
migration::migrate_to_latest::<T>()
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -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<T: Config>() -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
/// Migrates the pallet storage to the most recent version.
|
||||
pub struct Migration<T: Config>(PhantomData<T>);
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 1 {
|
||||
weight.saturating_accrue(migrate_to_v2::<T>());
|
||||
StorageVersion::new(2).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 1 {
|
||||
weight.saturating_accrue(migrate_to_v2::<T>());
|
||||
StorageVersion::new(2).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
}
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 2 {
|
||||
weight.saturating_accrue(migrate_to_v3::<T>());
|
||||
StorageVersion::new(3).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
}
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 2 {
|
||||
weight.saturating_accrue(migrate_to_v3::<T>());
|
||||
StorageVersion::new(3).put::<Pallet<T>>();
|
||||
weight.saturating_accrue(T::DbWeight::get().writes(1));
|
||||
}
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
mod v1 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -95,9 +95,16 @@ pub type SignedExtra = (
|
||||
pub type UncheckedExtrinsic =
|
||||
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
|
||||
|
||||
/// Migrations to apply on runtime upgrade.
|
||||
pub type Migrations = (
|
||||
cumulus_pallet_dmp_queue::migration::Migration<Runtime>,
|
||||
cumulus_pallet_parachain_system::migration::Migration<Runtime>,
|
||||
cumulus_pallet_xcmp_queue::migration::Migration<Runtime>,
|
||||
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
|
||||
pallet_contracts::Migration<Runtime>,
|
||||
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
|
||||
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
|
||||
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
|
||||
);
|
||||
|
||||
type EventRecord = frame_system::EventRecord<
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user