Remove xcm on_runtime_upgrade pallet hook (#7235)

* move migration stuffs

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* Fix test

* fix

* lint

* fix lint

* rm extra space

* fix lint

* PR review

* fixes

* use saturating_accrue in fn

* fix test

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
PG Herveou
2023-08-05 18:09:21 +02:00
committed by GitHub
parent 0142a01353
commit ed7a0b87eb
3 changed files with 28 additions and 36 deletions
+21 -24
View File
@@ -25,6 +25,7 @@ const DEFAULT_PROOF_SIZE: u64 = 64 * 1024;
pub mod v1 {
use super::*;
use crate::{CurrentMigration, VersionMigrationStage};
/// Named with the 'VersionUnchecked'-prefix because although this implements some version
/// checking, the version checking is not complete as it will begin failing after the upgrade is
@@ -33,34 +34,30 @@ pub mod v1 {
/// Use experimental [`VersionCheckedMigrateToV1`] instead.
pub struct VersionUncheckedMigrateToV1<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for VersionUncheckedMigrateToV1<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
ensure!(StorageVersion::get::<Pallet<T>>() == 0, "must upgrade linearly");
Ok(sp_std::vec::Vec::new())
}
fn on_runtime_upgrade() -> Weight {
if StorageVersion::get::<Pallet<T>>() == 0 {
let mut weight = T::DbWeight::get().reads(1);
let mut weight = T::DbWeight::get().reads(1);
let translate = |pre: (u64, u64, u32)| -> Option<(u64, Weight, u32)> {
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
let translated = (pre.0, Weight::from_parts(pre.1, DEFAULT_PROOF_SIZE), pre.2);
log::info!("Migrated VersionNotifyTarget {:?} to {:?}", pre, translated);
Some(translated)
};
VersionNotifyTargets::<T>::translate_values(translate);
log::info!("v1 applied successfully");
StorageVersion::new(1).put::<Pallet<T>>();
weight.saturating_add(T::DbWeight::get().writes(1))
} else {
if StorageVersion::get::<Pallet<T>>() != 0 {
log::warn!("skipping v1, should be removed");
T::DbWeight::get().reads(1)
return weight
}
weight.saturating_accrue(T::DbWeight::get().writes(1));
CurrentMigration::<T>::put(VersionMigrationStage::default());
let translate = |pre: (u64, u64, u32)| -> Option<(u64, Weight, u32)> {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
let translated = (pre.0, Weight::from_parts(pre.1, DEFAULT_PROOF_SIZE), pre.2);
log::info!("Migrated VersionNotifyTarget {:?} to {:?}", pre, translated);
Some(translated)
};
VersionNotifyTargets::<T>::translate_values(translate);
log::info!("v1 applied successfully");
weight.saturating_accrue(T::DbWeight::get().writes(1));
StorageVersion::new(1).put::<Pallet<T>>();
weight
}
}