diff --git a/runtime/altair/src/migrations.rs b/runtime/altair/src/migrations.rs index 9989708fe8..d0681593e1 100644 --- a/runtime/altair/src/migrations.rs +++ b/runtime/altair/src/migrations.rs @@ -52,20 +52,15 @@ pub type UpgradeAltair1034 = ( // Sets currently unset safe XCM version to v2 xcm_v2_to_v3::SetSafeXcmVersion, // Sets account codes for all precompiles - runtime_common::migrations::precompile_account_codes::Migration< - crate::Runtime, - { crate::VERSION.spec_version }, - >, + runtime_common::migrations::precompile_account_codes::Migration, ); /// The Upgrade set for Algol - it excludes the migrations already executed in /// the side releases that only landed on Algol (1028 to 1031) but not yet on /// Altair. #[cfg(feature = "testnet-runtime")] -pub type UpgradeAltair1034 = (runtime_common::migrations::precompile_account_codes::Migration< - crate::Runtime, - { crate::VERSION.spec_version }, ->); +pub type UpgradeAltair1034 = + (runtime_common::migrations::precompile_account_codes::Migration); mod asset_registry { use cfg_primitives::Balance; diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index 882edcaeba..7aef42b688 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -12,10 +12,10 @@ use crate::{Runtime, Weight}; pub type UpgradeCentrifuge1022 = ( - anemoy_pool::Migration, - add_wrapped_usdc_variants::Migration, + anemoy_pool::Migration, + add_wrapped_usdc_variants::Migration, // Sets account codes for all precompiles - runtime_common::migrations::precompile_account_codes::Migration, + runtime_common::migrations::precompile_account_codes::Migration, ); /// Migrate the Anemoy Pool's currency from LpEthUSC to Circle's USDC, @@ -40,11 +40,9 @@ mod anemoy_pool { const ANEMOY_POOL_ID: PoolId = 4_139_607_887; - pub struct Migration(sp_std::marker::PhantomData); + pub struct Migration(sp_std::marker::PhantomData); - impl OnRuntimeUpgrade - for Migration - { + impl OnRuntimeUpgrade for Migration { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { let pool_details: PoolDetailsOf = @@ -59,17 +57,6 @@ mod anemoy_pool { } fn on_runtime_upgrade() -> Weight { - let last_version = frame_system::LastRuntimeUpgrade::::get() - .map(|v| v.spec_version.0) - .unwrap_or(>::get().spec_version); - - if last_version >= BEFORE_VERSION { - log::warn!( - "anemoy_pool::Migration: NOT execution since current version higher than BEFORE_VERSION" - ); - return Weight::zero(); - } - let (sanity_checks, weight) = verify_sanity_checks(); if !sanity_checks { log::error!("anemoy_pool::Migration: Sanity checks FAILED"); @@ -165,27 +152,19 @@ pub mod add_wrapped_usdc_variants { use crate::OrderBook; use crate::{liquidity_pools::LiquidityPoolsPalletIndex, Balance, OrmlAssetRegistry, Runtime}; - pub struct Migration(sp_std::marker::PhantomData); + pub struct Migration(sp_std::marker::PhantomData); - impl OnRuntimeUpgrade - for Migration - { + impl OnRuntimeUpgrade for Migration { fn on_runtime_upgrade() -> Weight { - let last_version = frame_system::LastRuntimeUpgrade::::get() - .map(|v| v.spec_version.0) - .unwrap_or(>::get().spec_version); - - if last_version >= BEFORE_VERSION { - log::warn!( - "add_wrapped_usdc_variants::Migration: NOT execution since current version higher than BEFORE_VERSION" - ); - return Weight::zero(); - } - + let mut writes = 0u64; // Register assets for (currency_id, metadata) in Self::get_unregistered_metadata().into_iter() { - log::debug!("Registering asset {:?}", currency_id); - OrmlAssetRegistry::do_register_asset_without_asset_processor(metadata, currency_id) + log::info!("Registering asset {:?}", currency_id); + if OrmlAssetRegistry::metadata(currency_id).is_none() { + OrmlAssetRegistry::do_register_asset_without_asset_processor( + metadata, + currency_id, + ) .map_err(|e| { log::error!( "Failed to register asset {:?} due to error {:?}", @@ -195,7 +174,7 @@ pub mod add_wrapped_usdc_variants { }) // Add trading pairs if asset was registered successfully .map(|_| { - log::debug!( + log::info!( "Adding bidirectional USDC trading pair for asset {:?}", currency_id ); @@ -209,27 +188,61 @@ pub mod add_wrapped_usdc_variants { CURRENCY_ID_DOT_NATIVE, MIN_SWAP_ORDER_AMOUNT, ); + // 2 from updating metadata and location, 2 from trading pairs + writes = writes.saturating_add(4); }) .ok(); + } else { + log::warn!("Skipping registration of asset {:?}", currency_id); + } } - // Add trading pair for already registered LpEthUsdc - pallet_order_book::TradingPair::::insert( + // Add trading pair for already registered LpEthUsdc if it does not exist yet + if !pallet_order_book::TradingPair::::contains_key( CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LP_ETH, - MIN_SWAP_ORDER_AMOUNT, - ); - pallet_order_book::TradingPair::::insert( + ) { + log::info!( + "Adding trading pair from asset {:?} to USDC", + CURRENCY_ID_LP_ETH + ); + pallet_order_book::TradingPair::::insert( + CURRENCY_ID_DOT_NATIVE, + CURRENCY_ID_LP_ETH, + MIN_SWAP_ORDER_AMOUNT, + ); + writes = writes.saturating_add(1); + } else { + log::warn!( + "Skipping adding trading pair from asset {:?} to USDC", + CURRENCY_ID_LP_ETH + ); + } + if !pallet_order_book::TradingPair::::contains_key( CURRENCY_ID_LP_ETH, CURRENCY_ID_DOT_NATIVE, - MIN_SWAP_ORDER_AMOUNT, - ); + ) { + log::info!( + "Adding trading pair from USDC to asset {:?}", + CURRENCY_ID_LP_ETH + ); + pallet_order_book::TradingPair::::insert( + CURRENCY_ID_LP_ETH, + CURRENCY_ID_DOT_NATIVE, + MIN_SWAP_ORDER_AMOUNT, + ); + writes = writes.saturating_add(1); + } else { + log::warn!( + "Skipping adding trading pair from USDC to asset {:?}", + CURRENCY_ID_LP_ETH + ); + } log::info!("add_wrapped_usdc_variants::Migration: on_runtime_upgrade succeeded ✓"); - // 2 writes for registering, 2 writes for adding trading pair let new_assets: u64 = Self::get_unregistered_ids().len().saturated_into(); ::DbWeight::get() - .reads_writes(1, new_assets.saturating_mul(4).saturating_add(2)) + .reads_writes(new_assets.saturating_add(2), writes) } #[cfg(feature = "try-runtime")] @@ -277,7 +290,7 @@ pub mod add_wrapped_usdc_variants { } } - impl Migration { + impl Migration { fn get_unregistered_ids() -> Vec { vec![CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_ARB, CURRENCY_ID_LP_CELO] } diff --git a/runtime/common/src/migrations/precompile_account_codes.rs b/runtime/common/src/migrations/precompile_account_codes.rs index c17289330f..2040083a05 100644 --- a/runtime/common/src/migrations/precompile_account_codes.rs +++ b/runtime/common/src/migrations/precompile_account_codes.rs @@ -19,23 +19,12 @@ use sp_core::H160; use crate::evm::precompile::PRECOMPILE_CODE_STORAGE; -pub struct Migration(sp_std::marker::PhantomData); +pub struct Migration(sp_std::marker::PhantomData); -impl OnRuntimeUpgrade - for Migration -{ +impl OnRuntimeUpgrade for Migration { fn on_runtime_upgrade() -> Weight { log::info!("precompile::AccountCodes: Inserting precompile account codes: on_runtime_upgrade: started"); - let last_version = frame_system::LastRuntimeUpgrade::::get() - .map(|v| v.spec_version.0) - .unwrap_or(>::get().spec_version); - - if last_version >= BEFORE_VERSION { - log::warn!("[precompile::AccountCodes: Current runtime version too high. Skipping migration. Migration can probably be removed."); - return Weight::zero(); - } - if pallet_evm::AccountCodes::::get(H160::from(crate::evm::precompile::ECRECOVER_ADDR)) .is_empty() { diff --git a/runtime/development/src/migrations.rs b/runtime/development/src/migrations.rs index ee5fee3cfc..475565ae78 100644 --- a/runtime/development/src/migrations.rs +++ b/runtime/development/src/migrations.rs @@ -12,5 +12,5 @@ pub type UpgradeDevelopment1031 = ( // Sets account codes for all precompiles - runtime_common::migrations::precompile_account_codes::Migration, + runtime_common::migrations::precompile_account_codes::Migration, );