From 160318c7189f6e35814f72768c62de6c866d3476 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Fri, 6 Oct 2023 18:40:17 +0200 Subject: [PATCH] fix: remove spec_version check for Centrifuge 1023 migrations (#1584) --- Cargo.lock | 4 +- runtime/altair/src/migrations.rs | 11 +- runtime/centrifuge/Cargo.toml | 2 +- runtime/centrifuge/src/lib.rs | 2 +- runtime/centrifuge/src/migrations.rs | 105 ++++++++++-------- .../migrations/precompile_account_codes.rs | 15 +-- runtime/development/Cargo.toml | 2 +- runtime/development/src/lib.rs | 2 +- runtime/development/src/migrations.rs | 2 +- 9 files changed, 71 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4aacc022d6..8779ab322f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1141,7 +1141,7 @@ dependencies = [ [[package]] name = "centrifuge-runtime" -version = "0.10.22" +version = "0.10.23" dependencies = [ "axelar-gateway-precompile", "cfg-primitives", @@ -2690,7 +2690,7 @@ dependencies = [ [[package]] name = "development-runtime" -version = "0.10.31" +version = "0.10.32" dependencies = [ "axelar-gateway-precompile", "cfg-primitives", 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/Cargo.toml b/runtime/centrifuge/Cargo.toml index 9697b3a293..6e83e5476d 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "centrifuge-runtime" -version = "0.10.22" +version = "0.10.23" authors = ["Centrifuge "] edition = "2021" build = "build.rs" diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index b573101928..540a7240c7 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -131,7 +131,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("centrifuge"), impl_name: create_runtime_str!("centrifuge"), authoring_version: 1, - spec_version: 1022, + spec_version: 1023, impl_version: 1, #[cfg(not(feature = "disable-runtime-api"))] apis: RUNTIME_API_VERSIONS, 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/Cargo.toml b/runtime/development/Cargo.toml index 26e53cd54d..d6b5f26d0d 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "development-runtime" -version = "0.10.31" +version = "0.10.32" authors = ["Centrifuge "] edition = "2021" build = "build.rs" diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index c7c4f0ad41..4a464a6c83 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -139,7 +139,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: 1031, + spec_version: 1032, impl_version: 1, #[cfg(not(feature = "disable-runtime-api"))] apis: RUNTIME_API_VERSIONS, 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, );