From 878db0c09a6026492e4b80c45cb1cb61b47fa01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Enrique=20Mu=C3=B1oz=20Mart=C3=ADn?= Date: Mon, 11 Mar 2024 09:16:42 +0100 Subject: [PATCH] Fix: Loans demo migration (#1765) * working * minimal diff changes * minor log clean * removed unused imports * add log line * bump to 1043 --- Cargo.lock | 2 +- pallets/loans/src/migrations.rs | 2 +- .../migrations/increase_storage_version.rs | 51 +++++++++++++++++++ runtime/development/Cargo.toml | 2 +- runtime/development/src/lib.rs | 4 +- runtime/development/src/migrations.rs | 35 +------------ 6 files changed, 58 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ea182404e..226abb0a14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2451,7 +2451,7 @@ dependencies = [ [[package]] name = "development-runtime" -version = "0.10.42" +version = "0.10.43" dependencies = [ "axelar-gateway-precompile", "cfg-primitives", diff --git a/pallets/loans/src/migrations.rs b/pallets/loans/src/migrations.rs index 6876ade1f2..ace3393389 100644 --- a/pallets/loans/src/migrations.rs +++ b/pallets/loans/src/migrations.rs @@ -69,7 +69,7 @@ pub fn migrate_from_v2_to_v3() -> Weight { T::DbWeight::get().reads_writes(count + 1, count + 1) } else { // wrong storage version - log::info!("Loans: Migration did not execute. This probably should be removed"); + log::warn!("Loans: Migration did not execute. This probably should be removed"); T::DbWeight::get().reads_writes(1, 0) } } diff --git a/runtime/common/src/migrations/increase_storage_version.rs b/runtime/common/src/migrations/increase_storage_version.rs index 3142eb83b2..d8e6afba11 100644 --- a/runtime/common/src/migrations/increase_storage_version.rs +++ b/runtime/common/src/migrations/increase_storage_version.rs @@ -76,3 +76,54 @@ where Ok(()) } } + +/// Simply bumps the storage version of a pallet +/// +/// NOTE: Use with extreme caution! Must ensure beforehand that a migration is +/// not necessary +pub struct ForceMigration( + sp_std::marker::PhantomData

, +); +impl OnRuntimeUpgrade + for ForceMigration +where + P: GetStorageVersion + PalletInfoAccess, +{ + fn on_runtime_upgrade() -> Weight { + if P::on_chain_storage_version() == FROM_VERSION { + log::warn!("Double-check you really want this migration!!!!",); + log::info!( + "{LOG_PREFIX} Increasing storage version of {:?} from {:?} to {TO_VERSION:?}", + P::name(), + P::on_chain_storage_version(), + ); + StorageVersion::new(TO_VERSION).put::

(); + + RocksDbWeight::get().writes(1) + } else { + log::error!( + "{LOG_PREFIX} Mismatching versions. Wanted to upgrade from \ + {FROM_VERSION} but on-chain version is {:?}", + P::on_chain_storage_version(), + ); + Zero::zero() + } + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + assert_eq!( + P::on_chain_storage_version(), + FROM_VERSION, + "Unexpected onchain version: Expected {FROM_VERSION:?}, received {:?}", + P::on_chain_storage_version(), + ); + Ok(sp_std::vec![]) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: sp_std::vec::Vec) -> Result<(), sp_runtime::DispatchError> { + assert_eq!(P::on_chain_storage_version(), TO_VERSION); + Ok(()) + } +} diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index bd1983ea42..05dff3db18 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "development-runtime" -version = "0.10.42" +version = "0.10.43" build = "build.rs" authors.workspace = true edition.workspace = true diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 820feb386d..d72d9b0878 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -157,7 +157,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("centrifuge-devel"), impl_name: create_runtime_str!("centrifuge-devel"), authoring_version: 1, - spec_version: 1042, + spec_version: 1043, impl_version: 1, #[cfg(not(feature = "disable-runtime-api"))] apis: RUNTIME_API_VERSIONS, @@ -2040,7 +2040,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - crate::migrations::UpgradeDevelopment1042, + crate::migrations::UpgradeDevelopment1043, >; // Frame Order in this block dictates the index of each one in the metadata diff --git a/runtime/development/src/migrations.rs b/runtime/development/src/migrations.rs index 4dd97c3c5b..fff72d8738 100644 --- a/runtime/development/src/migrations.rs +++ b/runtime/development/src/migrations.rs @@ -10,36 +10,5 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use cfg_types::tokens::{ - usdc::{CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LOCAL, CURRENCY_ID_LP_ETH, LOCAL_ASSET_ID}, - CurrencyId, LocalAssetId, -}; - -frame_support::parameter_types! { - pub const UsdcVariants: [CurrencyId; 1] = [CURRENCY_ID_LP_ETH]; - pub const LocalAssetIdUsdc: LocalAssetId = LOCAL_ASSET_ID; - pub const LocalCurrencyIdUsdc: CurrencyId = CURRENCY_ID_LOCAL; - pub const PoolCurrencyAnemoy: CurrencyId = CURRENCY_ID_DOT_NATIVE; - pub const AnnualTreasuryInflationPercent: u32 = 3; -} - -pub type UpgradeDevelopment1042 = ( - // Reset pallets - runtime_common::migrations::nuke::ResetPallet, - runtime_common::migrations::nuke::ResetPallet< - crate::TransferAllowList, - crate::RocksDbWeight, - 0, - >, - // Apply relative treasury inflation - pallet_block_rewards::migrations::v2::RelativeTreasuryInflationMigration< - crate::Runtime, - AnnualTreasuryInflationPercent, - >, - // Apply version bump to 1 (storage already reset) - runtime_common::migrations::increase_storage_version::Migration< - crate::ForeignInvestments, - 0, - 1, - >, -); +pub type UpgradeDevelopment1043 = + (runtime_common::migrations::increase_storage_version::ForceMigration,);