diff --git a/Cargo.lock b/Cargo.lock index 95d7f9d5b4..5f674040ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,7 +130,6 @@ dependencies = [ "cfg-utils", "chainbridge", "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", @@ -1478,7 +1477,6 @@ dependencies = [ "cfg-types", "chainbridge", "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", @@ -2552,24 +2550,6 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", ] -[[package]] -name = "cumulus-pallet-dmp-queue" -version = "0.7.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2#e73d252e3e13b27a1127bde9a7c47febf70cc9ab" -dependencies = [ - "cumulus-primitives-core", - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "scale-info", - "sp-io", - "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", - "staging-xcm", -] - [[package]] name = "cumulus-pallet-parachain-system" version = "0.7.0" @@ -3109,7 +3089,6 @@ dependencies = [ "cfg-utils", "chainbridge", "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", diff --git a/Cargo.toml b/Cargo.toml index 57dfcc703d..42d8008e8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,7 +89,6 @@ chrono = { version = "0.4", default-features = false } # Cumulus cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } diff --git a/ci/run-check.sh b/ci/run-check.sh index 0bc6dea814..e162ab5d92 100755 --- a/ci/run-check.sh +++ b/ci/run-check.sh @@ -46,18 +46,19 @@ case $TARGET in try-runtime) cargo build -p centrifuge-chain --release --features try-runtime + cargo install --git https://github.com/paritytech/try-runtime-cli --tag v0.7.0 --locked if [ "$1" == "altair" ]; then echo "Running try-runtime for altair" RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \ try-runtime \ --runtime target/release/wbuild/altair-runtime/altair_runtime.wasm \ - on-runtime-upgrade live --uri wss://fullnode.altair.centrifuge.io:443 + on-runtime-upgrade --disable-spec-version-check --checks=all live --uri wss://fullnode.altair.centrifuge.io:443 elif [ "$1" == "centrifuge" ]; then echo "Running try-runtime for centrifuge" RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \ try-runtime \ --runtime target/release/wbuild/centrifuge-runtime/centrifuge_runtime.wasm \ - on-runtime-upgrade live --uri wss://fullnode.centrifuge.io:443 + on-runtime-upgrade --disable-spec-version-check --checks=all live --uri wss://fullnode.centrifuge.io:443 else echo "Invalid argument. Please specify 'altair' or 'centrifuge'." exit 1 diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index d38415409b..97d14aa54c 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -86,7 +86,10 @@ pub mod pallet { MalformedSourceChain, MalformedSourceChainLength, }; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::origin] diff --git a/runtime/altair/Cargo.toml b/runtime/altair/Cargo.toml index ed46ef8ea1..d4353693d6 100644 --- a/runtime/altair/Cargo.toml +++ b/runtime/altair/Cargo.toml @@ -75,7 +75,6 @@ runtime-common = { workspace = true } axelar-gateway-precompile = { workspace = true } chainbridge = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } @@ -206,7 +205,6 @@ std = [ "axelar-gateway-precompile/std", "chainbridge/std", "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", @@ -382,7 +380,6 @@ try-runtime = [ "axelar-gateway-precompile/try-runtime", "chainbridge/try-runtime", "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", "cumulus-pallet-parachain-system/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index a5309f30ae..6a609b6f98 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -357,12 +357,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmpQueue = TransformOrigin; } -impl cumulus_pallet_dmp_queue::Config for Runtime { - type DmpSink = frame_support::traits::EnqueueWithOrigin; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; -} - parameter_types! { pub const MinimumPeriod: Millis = SLOT_DURATION / 2; } @@ -2149,7 +2143,7 @@ construct_runtime!( XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 120, PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Config, Event, Origin} = 121, CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 122, - DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 123, + // Removed: DmpQueue = 123 XTokens: pallet_restricted_xtokens::{Pallet, Call} = 124, XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 125, OrmlXTokens: orml_xtokens::{Pallet, Event} = 126, diff --git a/runtime/altair/src/migrations.rs b/runtime/altair/src/migrations.rs index 8872e37638..5152e11c79 100644 --- a/runtime/altair/src/migrations.rs +++ b/runtime/altair/src/migrations.rs @@ -14,5 +14,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 UpgradeAltair1401 = - runtime_common::migrations::liquidity_pools_gateway::Migration; +pub type UpgradeAltair1401 = ( + // Clear OutboundMessageNonceStore + frame_support::migrations::VersionedMigration< + 0, + 1, + runtime_common::migrations::liquidity_pools_gateway::Migration, + pallet_liquidity_pools_gateway::Pallet, + ::DbWeight, + >, + // Remove undecodable ForeignInvestmentInfo v0 entries + runtime_common::migrations::foreign_investments_v2::Migration, + // Bump to v1 + runtime_common::migrations::increase_storage_version::Migration< + pallet_foreign_investments::Pallet, + 1, + 2, + >, +); diff --git a/runtime/centrifuge/Cargo.toml b/runtime/centrifuge/Cargo.toml index 06b69a3b02..a113cbd6b2 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -73,7 +73,6 @@ runtime-common = { workspace = true } axelar-gateway-precompile = { workspace = true } chainbridge = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } @@ -199,7 +198,6 @@ std = [ "axelar-gateway-precompile/std", "chainbridge/std", "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", @@ -367,7 +365,6 @@ try-runtime = [ "axelar-gateway-precompile/try-runtime", "chainbridge/try-runtime", "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", "cumulus-pallet-parachain-system/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index ddd06bc111..2df9dff2b9 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -351,12 +351,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmpQueue = TransformOrigin; } -impl cumulus_pallet_dmp_queue::Config for Runtime { - type DmpSink = frame_support::traits::EnqueueWithOrigin; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; -} - parameter_types! { pub const NativeToken: CurrencyId = CurrencyId::Native; } @@ -2147,7 +2141,7 @@ construct_runtime!( XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 120, PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Config, Event, Origin} = 121, CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 122, - DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 123, + // Removed: DmpQueue = 123 XTokens: pallet_restricted_xtokens::{Pallet, Call} = 124, XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 125, OrmlXTokens: orml_xtokens::{Pallet, Event} = 126, diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index 9c1b895173..d8bd54eab0 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -14,5 +14,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 UpgradeCentrifuge1401 = - runtime_common::migrations::liquidity_pools_gateway::Migration; +pub type UpgradeCentrifuge1401 = ( + // Clear OutboundMessageNonceStore + frame_support::migrations::VersionedMigration< + 0, + 1, + runtime_common::migrations::liquidity_pools_gateway::Migration, + pallet_liquidity_pools_gateway::Pallet, + ::DbWeight, + >, + // Remove undecodable ForeignInvestmentInfo v0 entries + runtime_common::migrations::foreign_investments_v2::Migration, + // Bump to v1 + runtime_common::migrations::increase_storage_version::Migration< + pallet_foreign_investments::Pallet, + 1, + 2, + >, +); diff --git a/runtime/common/src/migrations/foreign_investments_v2.rs b/runtime/common/src/migrations/foreign_investments_v2.rs new file mode 100644 index 0000000000..5bb65e1428 --- /dev/null +++ b/runtime/common/src/migrations/foreign_investments_v2.rs @@ -0,0 +1,69 @@ +// Copyright 2024 Centrifuge Foundation (centrifuge.io). +// +// This file is part of the Centrifuge chain project. +// Centrifuge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version (see http://www.gnu.org/licenses). +// Centrifuge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +use frame_support::traits::{Get, OnRuntimeUpgrade}; +use pallet_order_book::weights::Weight; +use sp_io::{storage::clear_prefix, KillStorageResult}; +use sp_std::vec::Vec; + +pub struct Migration(sp_std::marker::PhantomData); + +const REMOVAL_LIMIT: u32 = 10u32; +const LOG_PREFIX: &str = "LiquidityPoolsGatewayV1"; + +impl OnRuntimeUpgrade for Migration +where + T: frame_system::Config, +{ + fn on_runtime_upgrade() -> Weight { + let mut weight = Weight::zero(); + + match clear_prefix(&get_storage_prefix(), Some(REMOVAL_LIMIT)) { + KillStorageResult::AllRemoved(n) => { + log::info!("{LOG_PREFIX}: Removed {n} ForeignInvestmentInfo V1 keys"); + weight.saturating_accrue(T::DbWeight::get().writes(n.into())); + } + KillStorageResult::SomeRemaining(n) => { + log::warn!("{LOG_PREFIX}: There are {n} remaining ForeignInvestmentInfo V1 keys!"); + weight.saturating_accrue(T::DbWeight::get().writes(REMOVAL_LIMIT.into())); + } + } + + log::info!("{LOG_PREFIX}: Migration done!"); + + weight + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + log::info!("{LOG_PREFIX}: Pre checks done!"); + + Ok(Vec::new()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + assert!( + !sp_io::storage::exists(&get_storage_prefix()), + "{LOG_PREFIX}: ForeignInvestmentV0 keys remaining!" + ); + + log::info!("{LOG_PREFIX}: Post checks done!"); + + Ok(()) + } +} + +/// Returns final storage key prefix of `ForeignInvestmentInfo` in v0 +fn get_storage_prefix() -> Vec { + hex_literal::hex!("464aed913919bab92f79f3c7b79d28f7efbac15e93f37811895e260605cdc487").to_vec() +} diff --git a/runtime/common/src/migrations/hold_reason.rs b/runtime/common/src/migrations/hold_reason.rs deleted file mode 100644 index da29b24d5a..0000000000 --- a/runtime/common/src/migrations/hold_reason.rs +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2023 Centrifuge Foundation (centrifuge.io). -// -// This file is part of the Centrifuge chain project. -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -use cfg_primitives::{AccountId, Balance}; -use frame_support::{ - pallet_prelude::ValueQuery, - storage_alias, - traits::{ConstU32, Get, Len, OnRuntimeUpgrade, VariantCountOf}, - Blake2_128Concat, BoundedVec, Parameter, -}; -use pallet_balances::IdAmount; -use pallet_order_book::weights::Weight; -use pallet_transfer_allowlist::HoldReason; -#[cfg(feature = "try-runtime")] -use parity_scale_codec::{Decode, Encode}; -use parity_scale_codec::{FullCodec, FullEncode}; -#[cfg(feature = "try-runtime")] -use sp_runtime::Saturating; -#[cfg(feature = "try-runtime")] -use sp_runtime::TryRuntimeError; -use sp_runtime::{traits::Member, SaturatedConversion}; -use sp_std::{vec, vec::Vec}; - -const LOG_PREFIX: &str = "MigrateTransferAllowList HoldReason:"; - -pub struct MigrateTransferAllowListHolds( - sp_std::marker::PhantomData<(T, RuntimeHoldReason)>, -); - -type OldHolds = BoundedVec, ConstU32<10>>; -type NewHolds = - BoundedVec, VariantCountOf>; - -#[storage_alias] -pub type Holds = - StorageMap, Blake2_128Concat, AccountId, OldHolds, ValueQuery>; - -impl OnRuntimeUpgrade for MigrateTransferAllowListHolds -where - T: pallet_balances::Config - + pallet_transfer_allowlist::Config - + frame_system::Config, - ::RuntimeHoldReason: From, - RuntimeHoldReason: frame_support::traits::VariantCount - + FullCodec - + FullEncode - + Parameter - + Member - + sp_std::fmt::Debug, -{ - fn on_runtime_upgrade() -> Weight { - let transfer_allowlist_accounts: Vec = - pallet_transfer_allowlist::AccountCurrencyTransferAllowance::::iter_keys() - .map(|(a, _, _)| a) - .collect(); - let mut weight = - T::DbWeight::get().reads(transfer_allowlist_accounts.len().saturated_into()); - - pallet_balances::Holds::::translate::(|who, holds| { - if Self::account_can_be_migrated(&who, &transfer_allowlist_accounts) { - log::info!("{LOG_PREFIX} Migrating hold for account {who:?}"); - let id_amount = IdAmount:: { - id: HoldReason::TransferAllowance.into(), - // Non-emptiness ensured above - amount: holds[0].amount, - }; - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); - - Some(NewHolds::truncate_from(vec![id_amount])) - } else { - None - } - }); - - log::info!( - "{LOG_PREFIX} migrated {:?} accounts", - transfer_allowlist_accounts.len() - ); - - weight - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, TryRuntimeError> { - let transfer_allowlist_accounts: Vec = - pallet_transfer_allowlist::AccountCurrencyTransferAllowance::::iter_keys() - .map(|(a, _, _)| a) - .collect(); - - let mut n = 0u64; - for (acc, _) in Holds::::iter() { - assert!(Self::account_can_be_migrated( - &acc, - &transfer_allowlist_accounts - )); - n.saturating_accrue(1); - } - - log::info!("{LOG_PREFIX} pre checks done"); - Ok(n.encode()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_state: Vec) -> Result<(), TryRuntimeError> { - let count_pre: u64 = Decode::decode(&mut pre_state.as_slice()) - .expect("pre_upgrade provides a valid state; qed"); - - let holds_post = pallet_balances::Holds::::iter(); - let count_post: u64 = holds_post.count().saturated_into(); - assert_eq!(count_pre, count_post); - - for (_, hold) in pallet_balances::Holds::::iter() { - assert_eq!(hold.len(), 1); - assert_eq!(hold[0].id, HoldReason::TransferAllowance.into()); - } - - log::info!("{LOG_PREFIX} post checks done"); - Ok(()) - } -} - -impl MigrateTransferAllowListHolds -where - T: pallet_balances::Config - + pallet_transfer_allowlist::Config - + frame_system::Config, -{ - fn account_can_be_migrated(who: &AccountId, whitelist: &[AccountId]) -> bool { - if !whitelist.iter().any(|a| a == who) { - log::warn!("{LOG_PREFIX} Account {who:?} is skipped due to missing AccountCurrencyTransferAllowance storage entry"); - return false; - } - - match Holds::::get(who) { - holds if holds.len() == 1 => true, - _ => { - log::warn!("{LOG_PREFIX} Account {who:?} does not meet Hold storage assumptions"); - false - } - } - } -} diff --git a/runtime/common/src/migrations/liquidity_pools_gateway.rs b/runtime/common/src/migrations/liquidity_pools_gateway.rs index a87993dff9..ab3914c43a 100644 --- a/runtime/common/src/migrations/liquidity_pools_gateway.rs +++ b/runtime/common/src/migrations/liquidity_pools_gateway.rs @@ -1,127 +1,122 @@ use cfg_types::domain_address::Domain; use frame_support::{ pallet_prelude::ValueQuery, - storage::{child::MultiRemovalResults, generator::StorageValue, unhashed}, storage_alias, traits::{Get, OnRuntimeUpgrade}, - Blake2_128Concat, StorageMap, + Blake2_128Concat, }; -use pallet_liquidity_pools_gateway::{pallet::Pallet as LPGateway, Config}; use pallet_order_book::weights::Weight; -use sp_runtime::{DispatchError, TryRuntimeError}; +use sp_runtime::DispatchError; +#[cfg(feature = "try-runtime")] use sp_std::vec::Vec; #[storage_alias] -pub type OutboundMessageNonceStore = +pub type OutboundMessageNonceStore = StorageValue, u64, ValueQuery>; #[storage_alias] -pub type OutboundMessageQueue = StorageMap< - pallet_liquidity_pools_gateway::Pallet, - Blake2_128Concat, - u64, - ( - Domain, - ::AccountId, - pallet_liquidity_pools::Message, - ), ->; +pub type OutboundMessageQueue = + StorageMap< + pallet_liquidity_pools_gateway::Pallet, + Blake2_128Concat, + u64, + ( + Domain, + ::AccountId, + pallet_liquidity_pools::Message, + ), + >; #[storage_alias] -pub type FailedOutboundMessages = StorageMap< - pallet_liquidity_pools_gateway::Pallet, - Blake2_128Concat, - u64, - ( - Domain, - ::AccountId, - pallet_liquidity_pools::Message, - DispatchError, - ), ->; +pub type FailedOutboundMessages = + StorageMap< + pallet_liquidity_pools_gateway::Pallet, + Blake2_128Concat, + u64, + ( + Domain, + ::AccountId, + pallet_liquidity_pools::Message, + DispatchError, + ), + >; + +const LOG_PREFIX: &str = "LiquidityPoolsGatewayV1"; pub struct Migration(sp_std::marker::PhantomData); impl OnRuntimeUpgrade for Migration where - T: Config + frame_system::Config, + T: pallet_liquidity_pools_gateway::Config + frame_system::Config, { fn on_runtime_upgrade() -> Weight { - let mut weight = Self::clear_storage( - OutboundMessageNonceStore::::storage_prefix(), - "OutboundMessageNonceStore", - ); + let mut weight = Weight::zero(); + OutboundMessageNonceStore::::kill(); for (nonce, entry) in OutboundMessageQueue::::iter() { - log::warn!("Found outbound message:\nnonce:{nonce}\nentry:{entry:?}"); - weight = weight.saturating_add(::DbWeight::get().reads(1)); + log::warn!("{LOG_PREFIX}: Found outbound message:\nnonce:{nonce}\nentry:{entry:?}"); + weight.saturating_accrue(T::DbWeight::get().reads(1)); } for (nonce, entry) in FailedOutboundMessages::::iter() { - log::warn!("Found failed outbound message:\nnonce:{nonce}\nentry:{entry:?}"); - weight = weight.saturating_add(::DbWeight::get().reads(1)); + log::warn!( + "{LOG_PREFIX}: Found failed outbound message:\nnonce:{nonce}\nentry:{entry:?}" + ); + weight.saturating_accrue(T::DbWeight::get().reads(1)); } + log::info!("{LOG_PREFIX}: Migration done!"); + weight } #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, TryRuntimeError> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { // Extra check to confirm that the storage alias is correct. assert!( OutboundMessageNonceStore::::get() > 0, - "OutboundMessageNonce should be > 0" + "{LOG_PREFIX}: OutboundMessageNonce should be > 0" ); assert_eq!( OutboundMessageQueue::::iter_keys().count(), 0, - "OutboundMessageQueue should be empty!" + "{LOG_PREFIX}: OutboundMessageQueue should be empty!" ); assert_eq!( FailedOutboundMessages::::iter_keys().count(), 0, - "FailedOutboundMessages should be empty!" + "{LOG_PREFIX}: FailedOutboundMessages should be empty!" ); + log::info!("{LOG_PREFIX}: Pre checks done!"); + Ok(Vec::new()) } #[cfg(feature = "try-runtime")] - fn post_upgrade(_: Vec) -> Result<(), TryRuntimeError> { + fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { assert_eq!( OutboundMessageNonceStore::::get(), 0, - "OutboundMessageNonceStore should be 0!" + "{LOG_PREFIX}: OutboundMessageNonceStore should be 0!" ); assert_eq!( OutboundMessageQueue::::iter_keys().count(), 0, - "OutboundMessageQueue should be empty!" + "{LOG_PREFIX}: OutboundMessageQueue should be empty!" ); assert_eq!( FailedOutboundMessages::::iter_keys().count(), 0, - "FailedOutboundMessages should be empty!" + "{LOG_PREFIX}: FailedOutboundMessages should be empty!" ); - Ok(()) - } -} + log::info!("{LOG_PREFIX}: Post checks done!"); -impl Migration { - fn clear_storage(prefix: &[u8], storage_name: &str) -> Weight { - let res = unhashed::clear_prefix(prefix, None, None); - - match res.maybe_cursor { - None => log::info!("{storage_name} was cleared"), - Some(_) => log::error!("{storage_name} was not completely cleared"), - }; - - ::DbWeight::get() - .reads_writes(res.loops.into(), res.unique.into()) + Ok(()) } } diff --git a/runtime/common/src/migrations/loans.rs b/runtime/common/src/migrations/loans.rs deleted file mode 100644 index 7291ae00a5..0000000000 --- a/runtime/common/src/migrations/loans.rs +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright 2024 Centrifuge Foundation (centrifuge.io). -// -// This file is part of the Centrifuge chain project. -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -use cfg_traits::PoolNAV; -#[cfg(feature = "try-runtime")] -use frame_support::pallet_prelude::{Decode, Encode}; -use frame_support::{ - pallet_prelude::StorageVersion, - traits::{Get, GetStorageVersion, OnRuntimeUpgrade}, - weights::Weight, -}; -use pallet_loans::{pallet::Pallet as Loans, Config}; -#[cfg(feature = "try-runtime")] -use sp_arithmetic::traits::SaturatedConversion; -#[cfg(feature = "try-runtime")] -use sp_runtime::TryRuntimeError; -use sp_std::vec::Vec; - -const LOG_PREFIX: &str = "LoansMigrationToV4:"; - -mod v3 { - use frame_support::{ - pallet_prelude::{OptionQuery, ValueQuery}, - storage_alias, Blake2_128Concat, BoundedVec, - }; - pub use pallet_loans::entities::loans::v3::{ - ActiveLoan, ClosedLoan as ClosedLoanV3, CreatedLoan as CreatedLoanV3, - }; - use pallet_loans::Config; - - use super::Loans; - - pub type ActiveLoansVec = - BoundedVec<(::LoanId, ActiveLoan), ::MaxActiveLoansPerPool>; - - #[storage_alias] - pub type ActiveLoans = StorageMap< - Loans, - Blake2_128Concat, - ::PoolId, - ActiveLoansVec, - ValueQuery, - >; - - #[storage_alias] - pub type CreatedLoan = StorageDoubleMap< - Loans, - Blake2_128Concat, - ::PoolId, - Blake2_128Concat, - ::LoanId, - CreatedLoanV3, - OptionQuery, - >; - - #[storage_alias] - pub type ClosedLoan = StorageDoubleMap< - Loans, - Blake2_128Concat, - ::PoolId, - Blake2_128Concat, - ::LoanId, - ClosedLoanV3, - OptionQuery, - >; -} - -pub struct AddWithLinearPricing(sp_std::marker::PhantomData); -impl OnRuntimeUpgrade for AddWithLinearPricing -where - T: Config, -{ - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, TryRuntimeError> { - assert_eq!( - Loans::::on_chain_storage_version(), - StorageVersion::new(3) - ); - - let created_loans: u64 = v3::CreatedLoan::::iter_keys().count().saturated_into(); - let closed_loans: u64 = v3::ClosedLoan::::iter_keys().count().saturated_into(); - let active_loans: u64 = v3::ActiveLoans::::iter_values() - .map(|v| v.len()) - .sum::() - .saturated_into(); - - log::info!("{LOG_PREFIX} Pre checks done!"); - - Ok((created_loans, active_loans, closed_loans).encode()) - } - - fn on_runtime_upgrade() -> Weight { - let mut weight = T::DbWeight::get().reads(1); - if Loans::::on_chain_storage_version() == StorageVersion::new(3) { - log::info!("{LOG_PREFIX} Starting migration v3 -> v4"); - - pallet_loans::CreatedLoan::::translate::, _>(|_, _, loan| { - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); - Some(loan.migrate(true)) - }); - - pallet_loans::ClosedLoan::::translate::, _>(|_, _, loan| { - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); - Some(loan.migrate(true)) - }); - - let mut changed_pools = Vec::new(); - pallet_loans::ActiveLoans::::translate::, _>( - |pool_id, active_loans| { - changed_pools.push(pool_id); - weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); - Some( - active_loans - .into_iter() - .map(|(loan_id, active_loan)| (loan_id, active_loan.migrate(true))) - .collect::>() - .try_into() - .expect("size doesn't not change, qed"), - ) - }, - ); - - for pool_id in &changed_pools { - match Loans::::update_nav(*pool_id) { - Ok(_) => log::info!("{LOG_PREFIX} updated portfolio for pool_id: {pool_id:?}"), - Err(e) => { - log::error!( - "{LOG_PREFIX} error updating the portfolio for {pool_id:?}: {e:?}" - ) - } - } - } - - Loans::::current_storage_version().put::>(); - - let count = changed_pools.len() as u64; - weight.saturating_accrue(T::DbWeight::get().reads_writes(count, count + 1)); - log::info!("{LOG_PREFIX} Migrated {} pools", count); - - weight - } else { - log::info!( - "{LOG_PREFIX} Migration to v4 did not execute. This probably should be removed" - ); - weight - } - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_state: Vec) -> Result<(), TryRuntimeError> { - assert_eq!( - Loans::::on_chain_storage_version(), - StorageVersion::new(4) - ); - - let (pre_created, pre_active, pre_closed) = - <(u64, u64, u64)>::decode(&mut pre_state.as_slice()).expect("Pre state valid; qed"); - let post_created: u64 = pallet_loans::CreatedLoan::::iter_keys() - .count() - .saturated_into(); - let post_closed: u64 = pallet_loans::ClosedLoan::::iter_keys() - .count() - .saturated_into(); - let post_active: u64 = pallet_loans::ActiveLoans::::iter_values() - .map(|v| v.len()) - .sum::() - .saturated_into(); - assert_eq!( - pre_created, post_created, - "Number of CreatedLoans mismatches: pre {pre_created} vs post {post_created}" - ); - assert_eq!( - pre_closed, post_closed, - "Number of ClosedLoans mismatches: pre {pre_closed} vs post {post_closed}" - ); - assert_eq!( - pre_active, post_active, - "Number of ActiveLoans mismatches: pre {pre_active} vs post {post_active}" - ); - - log::info!("{LOG_PREFIX} Post checks done!"); - - Ok(()) - } -} diff --git a/runtime/common/src/migrations/mod.rs b/runtime/common/src/migrations/mod.rs index 87e443b974..aefb459ac9 100644 --- a/runtime/common/src/migrations/mod.rs +++ b/runtime/common/src/migrations/mod.rs @@ -12,10 +12,9 @@ //! Centrifuge Runtime-Common Migrations -pub mod hold_reason; +pub mod foreign_investments_v2; pub mod increase_storage_version; pub mod liquidity_pools_gateway; -pub mod loans; pub mod nuke; pub mod precompile_account_codes; pub mod restricted_location; diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 6fab2e0914..b1a6719608 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -75,7 +75,6 @@ runtime-common = { workspace = true } axelar-gateway-precompile = { workspace = true } chainbridge = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } @@ -207,7 +206,6 @@ std = [ "axelar-gateway-precompile/std", "chainbridge/std", "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", @@ -384,7 +382,6 @@ try-runtime = [ "axelar-gateway-precompile/try-runtime", "chainbridge/try-runtime", "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", "cumulus-pallet-parachain-system/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 6095a1107d..9bd6f8f09c 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -361,12 +361,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmpQueue = TransformOrigin; } -impl cumulus_pallet_dmp_queue::Config for Runtime { - type DmpSink = frame_support::traits::EnqueueWithOrigin; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; -} - parameter_types! { pub const MinimumPeriod: Millis = SLOT_DURATION / 2; } @@ -2255,7 +2249,7 @@ construct_runtime!( XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 120, PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Config, Event, Origin} = 121, CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 122, - DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 123, + // Removed: DmpQueue = 123 XTokens: pallet_restricted_xtokens::{Pallet, Call} = 124, XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 125, OrmlXTokens: orml_xtokens::{Pallet, Event} = 126, diff --git a/runtime/development/src/migrations.rs b/runtime/development/src/migrations.rs index f458152c6d..f25201cc3f 100644 --- a/runtime/development/src/migrations.rs +++ b/runtime/development/src/migrations.rs @@ -12,5 +12,21 @@ use crate::Runtime; -pub type UpgradeDevelopment1401 = - runtime_common::migrations::liquidity_pools_gateway::Migration; +pub type UpgradeDevelopment1401 = ( + // Clear OutboundMessageNonceStore + frame_support::migrations::VersionedMigration< + 0, + 1, + runtime_common::migrations::liquidity_pools_gateway::Migration, + pallet_liquidity_pools_gateway::Pallet, + ::DbWeight, + >, + // Remove undecodable ForeignInvestmentInfo v0 entries + runtime_common::migrations::foreign_investments_v2::Migration, + // Bump to v1 + runtime_common::migrations::increase_storage_version::Migration< + pallet_foreign_investments::Pallet, + 1, + 2, + >, +);