From 8ec41e92a8b0bd31fef1c90e6a47cbcd48e771e6 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Wed, 14 Aug 2024 19:21:14 +0200 Subject: [PATCH] fix: migration --- pallets/liquidity-pools-gateway/src/lib.rs | 2 +- runtime/altair/src/migrations.rs | 14 ++++- runtime/centrifuge/src/migrations.rs | 14 ++++- .../src/migrations/liquidity_pools_gateway.rs | 62 ++++++++++++------- runtime/development/src/migrations.rs | 5 +- 5 files changed, 66 insertions(+), 31 deletions(-) diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 2dfc01b85e..409a3cbfd7 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -61,7 +61,7 @@ mod tests; pub mod pallet { use super::*; - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] diff --git a/runtime/altair/src/migrations.rs b/runtime/altair/src/migrations.rs index d1cef70c2a..f5bfce2023 100644 --- a/runtime/altair/src/migrations.rs +++ b/runtime/altair/src/migrations.rs @@ -15,13 +15,21 @@ use crate::Runtime; /// The migration set for Altair @ Kusama. /// It includes all the migrations that have to be applied on that chain. pub type UpgradeAltair1402 = ( - // Remove deprecated DomainRouters entries - runtime_common::migrations::liquidity_pools_gateway::clear_deprecated_domain_router_entries::Migration, // Clear OutboundMessageNonceStore frame_support::migrations::VersionedMigration< 0, 1, - runtime_common::migrations::liquidity_pools_gateway::clear_outbound_nonce::Migration, + runtime_common::migrations::liquidity_pools_gateway::clear_outbound_nonce::Migration< + Runtime, + >, + pallet_liquidity_pools_gateway::Pallet, + ::DbWeight, + >, + // Remove deprecated DomainRouters entries + frame_support::migrations::VersionedMigration< + 1, + 2, + runtime_common::migrations::liquidity_pools_gateway::clear_deprecated_domain_router_entries::Migration, pallet_liquidity_pools_gateway::Pallet, ::DbWeight, >, diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index 3bd55bb315..9143e228b3 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -15,13 +15,21 @@ use crate::Runtime; /// The migration set for Centrifuge @ Polkadot. /// It includes all the migrations that have to be applied on that chain. pub type UpgradeCentrifuge1402 = ( - // Remove deprecated DomainRouters entries - runtime_common::migrations::liquidity_pools_gateway::clear_deprecated_domain_router_entries::Migration, // Clear OutboundMessageNonceStore frame_support::migrations::VersionedMigration< 0, 1, - runtime_common::migrations::liquidity_pools_gateway::clear_outbound_nonce::Migration, + runtime_common::migrations::liquidity_pools_gateway::clear_outbound_nonce::Migration< + Runtime, + >, + pallet_liquidity_pools_gateway::Pallet, + ::DbWeight, + >, + // Remove deprecated DomainRouters entries + frame_support::migrations::VersionedMigration< + 1, + 2, + runtime_common::migrations::liquidity_pools_gateway::clear_deprecated_domain_router_entries::Migration, pallet_liquidity_pools_gateway::Pallet, ::DbWeight, >, diff --git a/runtime/common/src/migrations/liquidity_pools_gateway.rs b/runtime/common/src/migrations/liquidity_pools_gateway.rs index 6c11647590..493996a00b 100644 --- a/runtime/common/src/migrations/liquidity_pools_gateway.rs +++ b/runtime/common/src/migrations/liquidity_pools_gateway.rs @@ -11,8 +11,10 @@ // GNU General Public License for more details. use cfg_types::domain_address::Domain; +#[cfg(feature = "try-runtime")] +use frame_support::pallet_prelude::{Decode, Encode}; use frame_support::{ - pallet_prelude::{Decode, Encode, ValueQuery}, + pallet_prelude::ValueQuery, storage_alias, traits::{Get, OnRuntimeUpgrade}, weights::Weight, @@ -157,21 +159,26 @@ pub mod clear_deprecated_domain_router_entries { fn on_runtime_upgrade() -> Weight { let items = v0::DomainRouters::::iter_keys().count().saturated_into(); - pallet_liquidity_pools_gateway::DomainRouters::::translate_values::< - v0::DomainRouter, - _, - >(|old| match old { - v0::DomainRouter::AxelarEVM(router) => Some( - liquidity_pools_gateway_routers::DomainRouter::::AxelarEVM(router).into(), - ), - // Remove other entries - router => { - log::info!("{LOG_PREFIX}: Removing entry {router:?}!"); - None - } - }); - - log::info!("{LOG_PREFIX}: Migration done with {items:?} items in total!"); + pallet_liquidity_pools_gateway::DomainRouters::::translate::, _>( + |key, old| { + log::debug!("{LOG_PREFIX}: Inspecting key {key:?} with value\n{old:?}"); + match old { + v0::DomainRouter::AxelarEVM(router) => Some( + liquidity_pools_gateway_routers::DomainRouter::::AxelarEVM(router) + .into(), + ), + // Remove other entries + router => { + log::info!("{LOG_PREFIX} : Removing entry {router:?}!"); + None + } + } + }, + ); + + log::info!( + "{LOG_PREFIX} ON_RUNTIME_UPGRADE: Migration done with {items:?} items in total!" + ); T::DbWeight::get().reads_writes(items, items) } @@ -179,12 +186,23 @@ pub mod clear_deprecated_domain_router_entries { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { let count_total = v0::DomainRouters::::iter_keys().count(); - let count_axelar_evm_router: u64 = v0::DomainRouters::::iter_values() - .filter(|v| matches!(v, v0::DomainRouter::AxelarEVM(_))) + let count_axelar_evm_router: u64 = v0::DomainRouters::::iter() + .filter(|(domain, router)| { + log::debug!( + "{LOG_PREFIX} PRE: Inspecting key {domain:?} with value\n{router:?}" + ); + matches!(router, v0::DomainRouter::AxelarEVM(_)) + }) .count() .saturated_into(); - log::info!("{LOG_PREFIX}: Found {count_axelar_evm_router:?} values of total {count_total:?} to migrate!"); - log::info!("{LOG_PREFIX}: Pre checks done!"); + log::info!( + "{LOG_PREFIX} PRE: Found {count_axelar_evm_router:?} values of + total {count_total:?} to migrate!" + ); + log::info!( + "{LOG_PREFIX} PRE: Checks + done!" + ); Ok(count_axelar_evm_router.encode()) } @@ -197,10 +215,10 @@ pub mod clear_deprecated_domain_router_entries { .saturated_into(); assert_eq!( pre_count, post_count, - "{LOG_PREFIX}: Mismatching number of domain routers after migration!" + "{LOG_PREFIX} POST: Mismatching number of domain routers after migration!" ); - log::info!("{LOG_PREFIX}: Post checks done!"); + log::info!("{LOG_PREFIX} POST: Checks done!"); Ok(()) } diff --git a/runtime/development/src/migrations.rs b/runtime/development/src/migrations.rs index ab9d396ea9..f154e76666 100644 --- a/runtime/development/src/migrations.rs +++ b/runtime/development/src/migrations.rs @@ -10,7 +10,8 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +use frame_support::migrations::VersionedMigration; + use crate::Runtime; -pub type UpgradeDevelopment1402 = - (runtime_common::migrations::liquidity_pools_gateway::clear_deprecated_domain_router_entries::Migration,); +pub type UpgradeDevelopment1402 = VersionedMigration<1, 2, runtime_common::migrations::liquidity_pools_gateway::clear_deprecated_domain_router_entries::Migration, pallet_liquidity_pools_gateway::Pallet, ::DbWeight>;