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:
PG Herveou
2023-06-05 13:56:55 +02:00
committed by GitHub
parent 2a4edaf39c
commit 005b9d0989
9 changed files with 75 additions and 67 deletions
+1 -5
View File
@@ -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.