From e1e2b154c8ff5f4035e56c8db2b4b1b017dee2e4 Mon Sep 17 00:00:00 2001 From: muraca Date: Mon, 30 Oct 2023 09:36:01 +0100 Subject: [PATCH] migration to v1 only checks on chain storage versions Signed-off-by: muraca --- substrate/frame/assets/src/migration/v1.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/substrate/frame/assets/src/migration/v1.rs b/substrate/frame/assets/src/migration/v1.rs index e32e3787b5360..7b8cc83b54cf5 100644 --- a/substrate/frame/assets/src/migration/v1.rs +++ b/substrate/frame/assets/src/migration/v1.rs @@ -101,9 +101,8 @@ pub(crate) struct AssetDetails { pub struct MigrateToV1(sp_std::marker::PhantomData<(T, I)>); impl, I: 'static> OnRuntimeUpgrade for MigrateToV1 { fn on_runtime_upgrade() -> Weight { - let current_version = Pallet::::current_storage_version(); let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version == 0 && current_version == 1 { + if onchain_version == 0 { let mut translated = 0u64; Asset::::translate::< old::AssetDetails>, @@ -112,14 +111,15 @@ impl, I: 'static> OnRuntimeUpgrade for MigrateToV1 { translated.saturating_inc(); Some(old_value.migrate_to_v1()) }); - current_version.put::>(); + StorageVersion::new(1).put::>(); log::info!( target: LOG_TARGET, - "Upgraded {} pools, storage to version {:?}", + "Upgraded {} pools, storage to version 1", translated, - current_version ); - T::DbWeight::get().reads_writes(translated + 1, translated + 1) + translated.saturating_inc(); + + T::DbWeight::get().reads_writes(translated, translated) } else { log::info!( target: LOG_TARGET, @@ -149,13 +149,11 @@ impl, I: 'static> OnRuntimeUpgrade for MigrateToV1 { "the asset count before and after the migration should be the same" ); - let current_version = Pallet::::current_storage_version(); let onchain_version = Pallet::::on_chain_storage_version(); - frame_support::ensure!(current_version == 1, "must_upgrade"); - ensure!( - current_version == onchain_version, - "after migration, the current_version and onchain_version should be the same" + frame_support::ensure!( + onchain_version == 1, + "on chain storage version for assets should be 1 after migration" ); Asset::::iter().try_for_each(|(_id, asset)| -> Result<(), TryRuntimeError> {