Files
pezkuwi-sdk/pezcumulus/pezpallets/teyrchain-system/src/migration.rs
T
pezkuwichain 3139ffa25e fix: Complete snowbridge pezpallet rebrand and critical bug fixes
- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs)
- pallet/ directories → pezpallet/ (4 locations)
- Fixed pezpallet.rs self-include recursion bug
- Fixed sc-chain-spec hardcoded crate name in derive macro
- Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API)
- Added BizinikiwiConfig type alias for zombienet tests
- Deleted obsolete session state files

Verified: pezsnowbridge-pezpallet-*, pezpallet-staking,
pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
2025-12-16 09:57:23 +03:00

91 lines
2.9 KiB
Rust

// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Pezcumulus.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::{Config, Pezpallet, ReservedDmpWeightOverride, ReservedXcmpWeightOverride};
use pezframe_support::{
pezpallet_prelude::*,
traits::{Get, OnRuntimeUpgrade, StorageVersion},
weights::Weight,
};
/// The in-code storage version.
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
/// Migrates the pezpallet storage to the most recent version.
pub struct Migration<T: Config>(PhantomData<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::<Pezpallet<T>>() == 0 {
weight = weight
.saturating_add(v1::migrate::<T>())
.saturating_add(T::DbWeight::get().writes(1));
StorageVersion::new(1).put::<Pezpallet<T>>();
}
if StorageVersion::get::<Pezpallet<T>>() == 1 {
weight = weight
.saturating_add(v2::migrate::<T>())
.saturating_add(T::DbWeight::get().writes(1));
StorageVersion::new(2).put::<Pezpallet<T>>();
}
weight
}
}
/// V2: Migrate to 2D weights for ReservedXcmpWeightOverride and ReservedDmpWeightOverride.
mod v2 {
use super::*;
const DEFAULT_POV_SIZE: u64 = 64 * 1024; // 64 KB
pub fn migrate<T: Config>() -> Weight {
let translate = |pre: u64| -> Weight { Weight::from_parts(pre, DEFAULT_POV_SIZE) };
if ReservedXcmpWeightOverride::<T>::translate(|pre| pre.map(translate)).is_err() {
log::error!(
target: "teyrchain_system",
"unexpected error when performing translation of the ReservedXcmpWeightOverride type during storage upgrade to v2"
);
}
if ReservedDmpWeightOverride::<T>::translate(|pre| pre.map(translate)).is_err() {
log::error!(
target: "teyrchain_system",
"unexpected error when performing translation of the ReservedDmpWeightOverride type during storage upgrade to v2"
);
}
T::DbWeight::get().reads_writes(2, 2)
}
}
/// V1: `LastUpgrade` block number is removed from the storage since the upgrade
/// mechanism now uses signals instead of block offsets.
mod v1 {
use crate::{Config, Pezpallet};
#[allow(deprecated)]
use pezframe_support::{migration::remove_storage_prefix, pezpallet_prelude::*};
pub fn migrate<T: Config>() -> Weight {
#[allow(deprecated)]
remove_storage_prefix(<Pezpallet<T>>::name().as_bytes(), b"LastUpgrade", b"");
T::DbWeight::get().writes(1)
}
}