Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove spec_version check for Centrifuge 1023 migrations #1584

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions runtime/altair/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Runtime>,
);

/// 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<crate::Runtime>);

mod asset_registry {
use cfg_primitives::Balance;
Expand Down
2 changes: 1 addition & 1 deletion runtime/centrifuge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "centrifuge-runtime"
version = "0.10.22"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this has not been changed for altair because we are using development as demo now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The correct reason would be that we had not upgraded Algol or Altair yet. In contrast, Catalyst received two upgrades already from 1020 (current Centrifuge version) to 1022.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for extend!

version = "0.10.23"
authors = ["Centrifuge <admin@centrifuge.io>"]
edition = "2021"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
105 changes: 59 additions & 46 deletions runtime/centrifuge/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use crate::{Runtime, Weight};

pub type UpgradeCentrifuge1022 = (
anemoy_pool::Migration<crate::Runtime, 1021>,
add_wrapped_usdc_variants::Migration<crate::Runtime, 1021>,
anemoy_pool::Migration<crate::Runtime>,
add_wrapped_usdc_variants::Migration<crate::Runtime>,
// Sets account codes for all precompiles
runtime_common::migrations::precompile_account_codes::Migration<crate::Runtime, 1022>,
runtime_common::migrations::precompile_account_codes::Migration<crate::Runtime>,
);

/// Migrate the Anemoy Pool's currency from LpEthUSC to Circle's USDC,
Expand All @@ -40,11 +40,9 @@ mod anemoy_pool {

const ANEMOY_POOL_ID: PoolId = 4_139_607_887;

pub struct Migration<T, const BEFORE_VERSION: u32>(sp_std::marker::PhantomData<T>);
pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl<T: frame_system::Config, const BEFORE_VERSION: u32> OnRuntimeUpgrade
for Migration<T, BEFORE_VERSION>
{
impl<T: frame_system::Config> OnRuntimeUpgrade for Migration<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
let pool_details: PoolDetailsOf<Runtime> =
Expand All @@ -59,17 +57,6 @@ mod anemoy_pool {
}

fn on_runtime_upgrade() -> Weight {
let last_version = frame_system::LastRuntimeUpgrade::<T>::get()
.map(|v| v.spec_version.0)
.unwrap_or(<T::Version as frame_support::traits::Get<_>>::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");
Expand Down Expand Up @@ -165,27 +152,19 @@ pub mod add_wrapped_usdc_variants {
use crate::OrderBook;
use crate::{liquidity_pools::LiquidityPoolsPalletIndex, Balance, OrmlAssetRegistry, Runtime};

pub struct Migration<T, const BEFORE_VERSION: u32>(sp_std::marker::PhantomData<T>);
pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl<T: frame_system::Config, const BEFORE_VERSION: u32> OnRuntimeUpgrade
for Migration<T, BEFORE_VERSION>
{
impl<T: frame_system::Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> Weight {
let last_version = frame_system::LastRuntimeUpgrade::<T>::get()
.map(|v| v.spec_version.0)
.unwrap_or(<T::Version as frame_support::traits::Get<_>>::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 {:?}",
Expand All @@ -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
);
Expand All @@ -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::<Runtime>::insert(
// Add trading pair for already registered LpEthUsdc if it does not exist yet
if !pallet_order_book::TradingPair::<Runtime>::contains_key(
CURRENCY_ID_DOT_NATIVE,
CURRENCY_ID_LP_ETH,
MIN_SWAP_ORDER_AMOUNT,
);
pallet_order_book::TradingPair::<Runtime>::insert(
) {
log::info!(
"Adding trading pair from asset {:?} to USDC",
CURRENCY_ID_LP_ETH
);
pallet_order_book::TradingPair::<Runtime>::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::<Runtime>::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::<Runtime>::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();
<Runtime as frame_system::Config>::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")]
Expand Down Expand Up @@ -277,7 +290,7 @@ pub mod add_wrapped_usdc_variants {
}
}

impl<T, const BEFORE_VERSION: u32> Migration<T, BEFORE_VERSION> {
impl<T> Migration<T> {
fn get_unregistered_ids() -> Vec<CurrencyId> {
vec![CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_ARB, CURRENCY_ID_LP_CELO]
}
Expand Down
15 changes: 2 additions & 13 deletions runtime/common/src/migrations/precompile_account_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,12 @@ use sp_core::H160;

use crate::evm::precompile::PRECOMPILE_CODE_STORAGE;

pub struct Migration<T, const BEFORE_VERSION: u32>(sp_std::marker::PhantomData<T>);
pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl<T: pallet_evm::Config, const BEFORE_VERSION: u32> OnRuntimeUpgrade
for Migration<T, BEFORE_VERSION>
{
impl<T: pallet_evm::Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> Weight {
log::info!("precompile::AccountCodes: Inserting precompile account codes: on_runtime_upgrade: started");

let last_version = frame_system::LastRuntimeUpgrade::<T>::get()
.map(|v| v.spec_version.0)
.unwrap_or(<T::Version as frame_support::traits::Get<_>>::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::<T>::get(H160::from(crate::evm::precompile::ECRECOVER_ADDR))
.is_empty()
{
Expand Down
2 changes: 1 addition & 1 deletion runtime/development/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "development-runtime"
version = "0.10.31"
version = "0.10.32"
authors = ["Centrifuge <admin@centrifuge.io>"]
edition = "2021"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/development/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

pub type UpgradeDevelopment1031 = (
// Sets account codes for all precompiles
runtime_common::migrations::precompile_account_codes::Migration<crate::Runtime, 1031>,
runtime_common::migrations::precompile_account_codes::Migration<crate::Runtime>,
);