diff --git a/runtime/altair/src/migrations.rs b/runtime/altair/src/migrations.rs index 036c1b7d2b..7c018fc253 100644 --- a/runtime/altair/src/migrations.rs +++ b/runtime/altair/src/migrations.rs @@ -85,9 +85,9 @@ pub type UpgradeAltair1034 = ( // see https://github.com/paritytech/substrate/pull/12813 pallet_balances::migration::MigrateToTrackInactive, // Assets were already migrated to V3 MultiLocation but version not increased from 0 to 2 - runtime_common::migrations::increase_storage_version::Migration, + runtime_common::migrations::increase_storage_version::Migration, // Data was already moved but storage version not increased from 0 to 4 - runtime_common::migrations::increase_storage_version::Migration, + runtime_common::migrations::increase_storage_version::Migration, ); #[allow(clippy::upper_case_acronyms)] diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index c686dd28b0..5d17b0acf4 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -80,7 +80,7 @@ pub type UpgradeCentrifuge1025 = ( // see https://github.com/paritytech/substrate/pull/12813 pallet_balances::migration::MigrateToTrackInactive, // Assets were already migrated to V3 MultiLocation but version not increased from 0 to 2 - runtime_common::migrations::increase_storage_version::Migration, + runtime_common::migrations::increase_storage_version::Migration, // Burns tokens from other domains that are falsly not burned when they were transferred back // to their domain burn_unburned::Migration, diff --git a/runtime/common/src/migrations/increase_storage_version.rs b/runtime/common/src/migrations/increase_storage_version.rs index 7db8087e30..3142eb83b2 100644 --- a/runtime/common/src/migrations/increase_storage_version.rs +++ b/runtime/common/src/migrations/increase_storage_version.rs @@ -14,34 +14,58 @@ use frame_support::{ traits::{GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion}, weights::{constants::RocksDbWeight, Weight}, }; +use sp_runtime::traits::Zero; + +const LOG_PREFIX: &str = "BumpStorageVersion:"; /// Simply bumps the storage version of a pallet /// /// NOTE: Use with caution! Must ensure beforehand that a migration is not /// necessary -pub struct Migration

(sp_std::marker::PhantomData

); -impl

OnRuntimeUpgrade for Migration

+pub struct Migration( + sp_std::marker::PhantomData

, +); +impl OnRuntimeUpgrade + for Migration where P: GetStorageVersion + PalletInfoAccess, { fn on_runtime_upgrade() -> Weight { - log::info!( - "BumpStorageVersion: Increasing storage version of {:?} from {:?} to {:?}", - P::name(), - P::on_chain_storage_version(), - P::current_storage_version() - ); - P::current_storage_version().put::

(); - RocksDbWeight::get().writes(1) + if P::on_chain_storage_version() == FROM_VERSION + && P::current_storage_version() == TO_VERSION + { + log::info!( + "{LOG_PREFIX} Increasing storage version of {:?} from {:?} to {:?}", + P::name(), + P::on_chain_storage_version(), + P::current_storage_version() + ); + P::current_storage_version().put::

(); + RocksDbWeight::get().writes(1) + } else { + log::error!( + "{LOG_PREFIX} Mismatching versions. Wanted to upgrade from \ + {FROM_VERSION} to {TO_VERSION} but would instead upgrade from {:?} to {:?}", + P::on_chain_storage_version(), + P::current_storage_version() + ); + Zero::zero() + } } #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - assert!( - P::on_chain_storage_version() < P::current_storage_version(), - "Onchain {:?} vs current pallet version {:?}", + assert_eq!( P::on_chain_storage_version(), + FROM_VERSION, + "Unexpected onchain version: Expected {FROM_VERSION:?}, received {:?}", + P::on_chain_storage_version(), + ); + assert_eq!( P::current_storage_version(), + TO_VERSION, + "Unexpected upgrade version: Expected {TO_VERSION:?}, latest {:?}", + P::on_chain_storage_version(), ); Ok(sp_std::vec![]) }