From 013efb6b58441af1badafb2524335747a1e643a3 Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Sun, 9 Jun 2024 09:22:05 +0800 Subject: [PATCH 1/7] SLPx mint support commission id --- pallets/slpx/src/benchmarking.rs | 1 + pallets/slpx/src/lib.rs | 6 +++++- pallets/slpx/src/tests.rs | 6 ++++-- pallets/slpx/src/types.rs | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pallets/slpx/src/benchmarking.rs b/pallets/slpx/src/benchmarking.rs index 3e58fb064..891d104bc 100644 --- a/pallets/slpx/src/benchmarking.rs +++ b/pallets/slpx/src/benchmarking.rs @@ -107,6 +107,7 @@ mod benchmarks { KSM, TargetChain::Astar(receiver), BoundedVec::default(), + None, ); } diff --git a/pallets/slpx/src/lib.rs b/pallets/slpx/src/lib.rs index a3915139a..f0a4e4a9b 100644 --- a/pallets/slpx/src/lib.rs +++ b/pallets/slpx/src/lib.rs @@ -442,6 +442,7 @@ pub mod pallet { currency_id: CurrencyIdOf, target_chain: TargetChain>, remark: BoundedVec>, + channel_id: Option, ) -> DispatchResultWithPostInfo { let (source_chain_caller, derivative_account, bifrost_chain_caller) = Self::ensure_singer_on_whitelist(origin.clone(), evm_caller, &target_chain)?; @@ -456,6 +457,7 @@ pub mod pallet { currency_id, remark, target_chain, + channel_id, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -515,6 +517,7 @@ pub mod pallet { bifrost_chain_caller, derivative_account, target_chain, + channel_id: None, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -738,6 +741,7 @@ pub mod pallet { currency_id, remark, target_chain, + channel_id: None, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -1000,7 +1004,7 @@ impl Pallet { order.currency_id, currency_amount, order.remark.clone(), - None, + order.channel_id, ) .map_err(|_| Error::::ArgumentsError)?; let vtoken_id = T::VtokenMintingInterface::vtoken_id(order.currency_id) diff --git a/pallets/slpx/src/tests.rs b/pallets/slpx/src/tests.rs index ee06742e8..e779f9738 100644 --- a/pallets/slpx/src/tests.rs +++ b/pallets/slpx/src/tests.rs @@ -354,7 +354,8 @@ fn test_add_order() { source_chain_caller, DOT, TargetChain::Astar(source_chain_caller), - BoundedVec::default() + BoundedVec::default(), + None )); assert_eq!(OrderQueue::::get().len(), 1usize); assert_ok!(Slpx::redeem( @@ -389,7 +390,8 @@ fn test_hook() { source_chain_caller, DOT, TargetChain::Astar(source_chain_caller), - BoundedVec::default() + BoundedVec::default(), + None )); assert_eq!(OrderQueue::::get().len(), 1usize); >::set_block_number(2u32.into()); diff --git a/pallets/slpx/src/types.rs b/pallets/slpx/src/types.rs index bcf02e857..20e7b3213 100644 --- a/pallets/slpx/src/types.rs +++ b/pallets/slpx/src/types.rs @@ -130,4 +130,5 @@ pub struct Order { pub order_type: OrderType, pub remark: BoundedVec>, pub target_chain: TargetChain, + pub channel_id: Option, } From 0c11e9bfa4ef53dc0598f01240a34a7c33281538 Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Mon, 17 Jun 2024 16:01:02 +0800 Subject: [PATCH 2/7] remove the channel_id parameter from the mint method --- pallets/slpx/src/benchmarking.rs | 1 - pallets/slpx/src/lib.rs | 3 +-- pallets/slpx/src/tests.rs | 6 ++---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pallets/slpx/src/benchmarking.rs b/pallets/slpx/src/benchmarking.rs index 891d104bc..3e58fb064 100644 --- a/pallets/slpx/src/benchmarking.rs +++ b/pallets/slpx/src/benchmarking.rs @@ -107,7 +107,6 @@ mod benchmarks { KSM, TargetChain::Astar(receiver), BoundedVec::default(), - None, ); } diff --git a/pallets/slpx/src/lib.rs b/pallets/slpx/src/lib.rs index f0a4e4a9b..f3c39654a 100644 --- a/pallets/slpx/src/lib.rs +++ b/pallets/slpx/src/lib.rs @@ -442,7 +442,6 @@ pub mod pallet { currency_id: CurrencyIdOf, target_chain: TargetChain>, remark: BoundedVec>, - channel_id: Option, ) -> DispatchResultWithPostInfo { let (source_chain_caller, derivative_account, bifrost_chain_caller) = Self::ensure_singer_on_whitelist(origin.clone(), evm_caller, &target_chain)?; @@ -457,7 +456,7 @@ pub mod pallet { currency_id, remark, target_chain, - channel_id, + channel_id: None, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { diff --git a/pallets/slpx/src/tests.rs b/pallets/slpx/src/tests.rs index e779f9738..ee06742e8 100644 --- a/pallets/slpx/src/tests.rs +++ b/pallets/slpx/src/tests.rs @@ -354,8 +354,7 @@ fn test_add_order() { source_chain_caller, DOT, TargetChain::Astar(source_chain_caller), - BoundedVec::default(), - None + BoundedVec::default() )); assert_eq!(OrderQueue::::get().len(), 1usize); assert_ok!(Slpx::redeem( @@ -390,8 +389,7 @@ fn test_hook() { source_chain_caller, DOT, TargetChain::Astar(source_chain_caller), - BoundedVec::default(), - None + BoundedVec::default() )); assert_eq!(OrderQueue::::get().len(), 1usize); >::set_block_number(2u32.into()); From bd3d04485b0db9d0893b2937d5a24a70ef935575 Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Mon, 17 Jun 2024 21:59:20 +0800 Subject: [PATCH 3/7] add mint_with_channel_id method --- pallets/slpx/src/benchmarking.rs | 15 +++++++++ pallets/slpx/src/lib.rs | 33 +++++++++++++++++++ pallets/slpx/src/tests.rs | 24 ++++++++++++++ pallets/slpx/src/weights.rs | 14 ++++++++ .../src/weights/bifrost_slpx.rs | 13 ++++++++ .../src/weights/bifrost_slpx.rs | 13 ++++++++ 6 files changed, 112 insertions(+) diff --git a/pallets/slpx/src/benchmarking.rs b/pallets/slpx/src/benchmarking.rs index 3e58fb064..cd0d4b22a 100644 --- a/pallets/slpx/src/benchmarking.rs +++ b/pallets/slpx/src/benchmarking.rs @@ -110,6 +110,21 @@ mod benchmarks { ); } + #[benchmark] + fn mint_with_channel_id() { + let (caller, receiver) = init_whitelist::(); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + receiver, + KSM, + TargetChain::Astar(receiver), + BoundedVec::default(), + 0u32 + ); + } + #[benchmark] fn redeem() { let (caller, receiver) = init_whitelist::(); diff --git a/pallets/slpx/src/lib.rs b/pallets/slpx/src/lib.rs index f3c39654a..dddde508a 100644 --- a/pallets/slpx/src/lib.rs +++ b/pallets/slpx/src/lib.rs @@ -749,6 +749,39 @@ pub mod pallet { Ok(().into()) }) } + + #[pallet::call_index(13)] + #[pallet::weight(::WeightInfo::mint_with_channel_id())] + pub fn mint_with_channel_id( + origin: OriginFor, + evm_caller: H160, + currency_id: CurrencyIdOf, + target_chain: TargetChain>, + remark: BoundedVec>, + channel_id: u32, + ) -> DispatchResultWithPostInfo { + let (source_chain_caller, derivative_account, bifrost_chain_caller) = + Self::ensure_singer_on_whitelist(origin.clone(), evm_caller, &target_chain)?; + + let order = Order { + create_block_number: >::block_number(), + order_type: OrderType::Mint, + currency_amount: Default::default(), + source_chain_caller, + bifrost_chain_caller, + derivative_account, + currency_id, + remark, + target_chain, + channel_id: Some(channel_id), + }; + + OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { + order_queue.try_push(order.clone()).map_err(|_| Error::::ArgumentsError)?; + Self::deposit_event(Event::::CreateOrder { order }); + Ok(().into()) + }) + } } } diff --git a/pallets/slpx/src/tests.rs b/pallets/slpx/src/tests.rs index ee06742e8..2ab622765 100644 --- a/pallets/slpx/src/tests.rs +++ b/pallets/slpx/src/tests.rs @@ -379,6 +379,30 @@ fn test_add_order() { }) } +#[test] +fn test_mint_with_channel_id() { + sp_io::TestExternalities::default().execute_with(|| { + assert_ok!(Slpx::add_whitelist(RuntimeOrigin::root(), SupportChain::Astar, ALICE)); + let source_chain_caller = H160::default(); + assert_ok!(Slpx::mint_with_channel_id( + RuntimeOrigin::signed(ALICE), + source_chain_caller, + DOT, + TargetChain::Astar(source_chain_caller), + BoundedVec::default(), + 0u32 + )); + assert_eq!(OrderQueue::::get().len(), 1usize); + assert_ok!(Slpx::redeem( + RuntimeOrigin::signed(ALICE), + source_chain_caller, + VDOT, + TargetChain::Astar(source_chain_caller) + )); + assert_eq!(OrderQueue::::get().len(), 2usize); + }) +} + #[test] fn test_hook() { sp_io::TestExternalities::default().execute_with(|| { diff --git a/pallets/slpx/src/weights.rs b/pallets/slpx/src/weights.rs index 0dd1a9be0..446fdaf15 100644 --- a/pallets/slpx/src/weights.rs +++ b/pallets/slpx/src/weights.rs @@ -58,6 +58,7 @@ pub trait WeightInfo { fn set_execution_fee() -> Weight; fn set_transfer_to_fee() -> Weight; fn mint() -> Weight; + fn mint_with_channel_id() -> Weight; fn redeem() -> Weight; fn zenlink_swap() -> Weight; fn stable_pool_swap() -> Weight; @@ -138,6 +139,19 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(16_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } + /// Storage: `Slpx::WhitelistAccountId` (r:1 w:0) + /// Proof: `Slpx::WhitelistAccountId` (`max_values`: None, `max_size`: Some(338), added: 2813, mode: `MaxEncodedLen`) + /// Storage: `Slpx::OrderQueue` (r:1 w:1) + /// Proof: `Slpx::OrderQueue` (`max_values`: Some(1), `max_size`: Some(203002), added: 203497, mode: `MaxEncodedLen`) + fn mint_with_channel_id() -> Weight { + // Proof Size summary in bytes: + // Measured: `81` + // Estimated: `204487` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(12_000_000, 204487) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } /// Storage: Slpx WhitelistAccountId (r:1 w:0) /// Proof: Slpx WhitelistAccountId (max_values: None, max_size: Some(338), added: 2813, mode: MaxEncodedLen) /// Storage: Tokens Accounts (r:2 w:2) diff --git a/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs b/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs index e9c0cddc2..5cc4a3e80 100644 --- a/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs +++ b/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs @@ -127,6 +127,19 @@ impl bifrost_slpx::WeightInfo for BifrostWeight { .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(8)) } + // Storage: `Slpx::WhitelistAccountId` (r:1 w:0) + // Proof: `Slpx::WhitelistAccountId` (`max_values`: None, `max_size`: Some(338), added: 2813, mode: `MaxEncodedLen`) + // Storage: `Slpx::OrderQueue` (r:1 w:1) + // Proof: `Slpx::OrderQueue` (`max_values`: Some(1), `max_size`: Some(203002), added: 203497, mode: `MaxEncodedLen`) + fn mint_with_channel_id() -> Weight { + // Proof Size summary in bytes: + // Measured: `81` + // Estimated: `204487` + // Minimum execution time: 12_000 nanoseconds. + Weight::from_parts(13_000_000, 204487) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } // Storage: Slpx WhitelistAccountId (r:1 w:0) // Proof: Slpx WhitelistAccountId (max_values: None, max_size: Some(338), added: 2813, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) diff --git a/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs b/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs index e9c0cddc2..5cc4a3e80 100644 --- a/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs +++ b/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs @@ -127,6 +127,19 @@ impl bifrost_slpx::WeightInfo for BifrostWeight { .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(8)) } + // Storage: `Slpx::WhitelistAccountId` (r:1 w:0) + // Proof: `Slpx::WhitelistAccountId` (`max_values`: None, `max_size`: Some(338), added: 2813, mode: `MaxEncodedLen`) + // Storage: `Slpx::OrderQueue` (r:1 w:1) + // Proof: `Slpx::OrderQueue` (`max_values`: Some(1), `max_size`: Some(203002), added: 203497, mode: `MaxEncodedLen`) + fn mint_with_channel_id() -> Weight { + // Proof Size summary in bytes: + // Measured: `81` + // Estimated: `204487` + // Minimum execution time: 12_000 nanoseconds. + Weight::from_parts(13_000_000, 204487) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } // Storage: Slpx WhitelistAccountId (r:1 w:0) // Proof: Slpx WhitelistAccountId (max_values: None, max_size: Some(338), added: 2813, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) From 4c0297ab27be594cd044d5583917b4876db63395 Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Wed, 19 Jun 2024 10:32:50 +0800 Subject: [PATCH 4/7] perform data migration for OrderQueue storage --- Cargo.lock | 1 + pallets/slpx/Cargo.toml | 2 + pallets/slpx/src/benchmarking.rs | 2 +- pallets/slpx/src/lib.rs | 3 + pallets/slpx/src/migration.rs | 96 ++++++++++++++++++++++++++++- pallets/slpx/src/types.rs | 13 ++++ runtime/bifrost-kusama/src/lib.rs | 34 +--------- runtime/bifrost-polkadot/src/lib.rs | 33 +--------- 8 files changed, 117 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fce5e0d9..633d06cf8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1615,6 +1615,7 @@ dependencies = [ "frame-system", "hex", "hex-literal 0.4.1", + "log", "orml-tokens", "orml-traits", "orml-xtokens", diff --git a/pallets/slpx/Cargo.toml b/pallets/slpx/Cargo.toml index ff1e4830b..ba5ed8a6b 100644 --- a/pallets/slpx/Cargo.toml +++ b/pallets/slpx/Cargo.toml @@ -36,6 +36,7 @@ bifrost-asset-registry = { workspace = true } bifrost-stable-pool = { workspace = true } bifrost-stable-asset = { workspace = true } orml-tokens = { workspace = true } +log = { workspace = true } [dev-dependencies] hex = { workspace = true } @@ -77,6 +78,7 @@ std = [ "bifrost-asset-registry/std", "bifrost-stable-pool/std", "bifrost-stable-asset/std", + "log/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/pallets/slpx/src/benchmarking.rs b/pallets/slpx/src/benchmarking.rs index cd0d4b22a..8f472681f 100644 --- a/pallets/slpx/src/benchmarking.rs +++ b/pallets/slpx/src/benchmarking.rs @@ -121,7 +121,7 @@ mod benchmarks { KSM, TargetChain::Astar(receiver), BoundedVec::default(), - 0u32 + 0u32, ); } diff --git a/pallets/slpx/src/lib.rs b/pallets/slpx/src/lib.rs index dddde508a..a4fc8440a 100644 --- a/pallets/slpx/src/lib.rs +++ b/pallets/slpx/src/lib.rs @@ -84,7 +84,10 @@ pub mod pallet { use frame_system::ensure_root; use zenlink_protocol::{AssetId, ExportZenlink}; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] diff --git a/pallets/slpx/src/migration.rs b/pallets/slpx/src/migration.rs index 91d3e9b8e..7342681b4 100644 --- a/pallets/slpx/src/migration.rs +++ b/pallets/slpx/src/migration.rs @@ -16,12 +16,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::*; -use bifrost_primitives::currency::{ASTR, BNC, DOT, GLMR, KSM, MANTA, MOVR}; -use frame_support::traits::OnRuntimeUpgrade; +use frame_support::{storage_alias, traits::OnRuntimeUpgrade}; #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; +use bifrost_primitives::currency::{ASTR, BNC, DOT, GLMR, KSM, MANTA, MOVR}; + +use crate::*; + pub struct BifrostKusamaAddCurrencyToSupportXcmFee(sp_std::marker::PhantomData); impl OnRuntimeUpgrade for BifrostKusamaAddCurrencyToSupportXcmFee { fn on_runtime_upgrade() -> Weight { @@ -73,3 +75,91 @@ impl OnRuntimeUpgrade for BifrostPolkadotAddCurrencyToSupportXcmFee = StorageValue< + Pallet, + BoundedVec< + OldOrder, CurrencyIdOf, BalanceOf, BlockNumberFor>, + ConstU32<1000>, + >, + ValueQuery, + >; +} + +pub mod v1 { + use frame_support::traits::StorageVersion; + + use super::*; + + pub struct MigrateToV1(sp_std::marker::PhantomData); + impl OnRuntimeUpgrade for MigrateToV1 { + fn on_runtime_upgrade() -> Weight { + if StorageVersion::get::>() == 0 { + let weight_consumed = migrate_to_v1::(); + log::info!("Migrating slpx storage to v1"); + StorageVersion::new(1).put::>(); + weight_consumed.saturating_add(T::DbWeight::get().writes(1)) + } else { + log::warn!("slpx migration should be removed."); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + log::info!("slpx before migration: version: {:?}", StorageVersion::get::>()); + log::info!("slpx before migration: v0 count: {}", v0::OrderQueue::::get().len()); + + Ok(Vec::new()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: Vec) -> Result<(), sp_runtime::DispatchError> { + log::info!("slpx after migration: version: {:?}", StorageVersion::get::>()); + log::info!("slpx after migration: v1 count: {}", OrderQueue::::get().len()); + + Ok(()) + } + } +} + +pub fn migrate_to_v1() -> Weight { + let mut weight: Weight = Weight::zero(); + + let old_orders = v0::OrderQueue::::get(); + + let mut new_orders: BoundedVec<_, ConstU32<1000>> = BoundedVec::default(); + for old_order in old_orders.into_iter() { + new_orders + .try_push(Order { + source_chain_caller: old_order.source_chain_caller, + bifrost_chain_caller: old_order.bifrost_chain_caller, + derivative_account: old_order.derivative_account, + create_block_number: old_order.create_block_number, + currency_id: old_order.currency_id, + currency_amount: old_order.currency_amount, + order_type: old_order.order_type, + remark: old_order.remark, + target_chain: old_order.target_chain, + channel_id: None, + }) + .expect("BoundedVec should not overflow"); + weight = weight.saturating_add(T::DbWeight::get().reads_writes(0, 1)); + } + + OrderQueue::::put(new_orders); + weight = weight.saturating_add(T::DbWeight::get().writes(1)); + + v0::OrderQueue::::kill(); + weight = weight.saturating_add(T::DbWeight::get().writes(1)); + + weight +} diff --git a/pallets/slpx/src/types.rs b/pallets/slpx/src/types.rs index 20e7b3213..afe75e315 100644 --- a/pallets/slpx/src/types.rs +++ b/pallets/slpx/src/types.rs @@ -132,3 +132,16 @@ pub struct Order { pub target_chain: TargetChain, pub channel_id: Option, } + +#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct OldOrder { + pub source_chain_caller: OrderCaller, + pub bifrost_chain_caller: AccountId, + pub derivative_account: AccountId, + pub create_block_number: BlockNumber, + pub currency_id: CurrencyId, + pub currency_amount: Balance, + pub order_type: OrderType, + pub remark: BoundedVec>, + pub target_chain: TargetChain, +} diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index e2008e9b5..22df95895 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -98,9 +98,7 @@ use frame_support::{ OnUnbalanced, }, }; -use frame_system::{ - pallet_prelude::BlockNumberFor, EnsureRoot, EnsureRootWithSuccess, EnsureSigned, -}; +use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; use hex_literal::hex; use orml_oracle::{DataFeeder, DataProvider, DataProviderExtended}; use pallet_identity::legacy::IdentityInfo; @@ -2047,11 +2045,6 @@ pub type SignedPayload = generic::SignedPayload; /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. pub type Migrations = migrations::Unreleased; -parameter_types! { - pub const TipsPalletName: &'static str = "Tips"; - pub const BountiesPalletName: &'static str = "Bounties"; -} - /// The runtime migrations per release. pub mod migrations { #![allow(unused_imports)] @@ -2059,36 +2052,13 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( - // Unlock & unreserve funds - pallet_tips::migrations::unreserve_deposits::UnreserveDeposits, cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, migration::slpx_migrates_whitelist::UpdateWhitelist, - frame_support::migrations::RemovePallet< - TipsPalletName, - ::DbWeight, - >, - frame_support::migrations::RemovePallet< - BountiesPalletName, - ::DbWeight, - >, pallet_identity::migration::versioned::V0ToV1, + bifrost_slpx::migration::v1::MigrateToV1, ); } -// Special Config for tips pallets, allowing us to run migrations for them without -// implementing their configs on [`Runtime`]. -pub struct UnlockConfigForTips; -impl pallet_tips::migrations::unreserve_deposits::UnlockConfig<()> for UnlockConfigForTips { - type Currency = Balances; - type Hash = Hash; - type DataDepositPerByte = DataDepositPerByte; - type TipReportDepositBase = TipReportDepositBase; - type AccountId = AccountId; - type BlockNumber = BlockNumberFor; - type DbWeight = ::DbWeight; - type PalletName = TipsPalletName; -} - /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index 79421fc6d..0fa8f7c6c 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -97,9 +97,7 @@ use frame_support::{ Currency, EitherOf, EitherOfDiverse, Get, LinearStoragePrice, }, }; -use frame_system::{ - pallet_prelude::BlockNumberFor, EnsureRoot, EnsureRootWithSuccess, EnsureSigned, -}; +use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; use hex_literal::hex; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; // zenlink imports @@ -1881,11 +1879,6 @@ pub type SignedPayload = generic::SignedPayload; /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. pub type Migrations = migrations::Unreleased; -parameter_types! { - pub const TipsPalletName: &'static str = "Tips"; - pub const BountiesPalletName: &'static str = "Bounties"; -} - /// The runtime migrations per release. pub mod migrations { #[allow(unused_imports)] @@ -1894,36 +1887,14 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( // Unlock & unreserve funds - pallet_tips::migrations::unreserve_deposits::UnreserveDeposits, cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, migration::slpx_migrates_whitelist::UpdateWhitelist, - frame_support::migrations::RemovePallet< - TipsPalletName, - ::DbWeight, - >, - frame_support::migrations::RemovePallet< - BountiesPalletName, - ::DbWeight, - >, pallet_identity::migration::versioned::V0ToV1, pallet_collator_selection::migration::v2::MigrationToV2, + bifrost_slpx::migration::v1::MigrateToV1, ); } -// Special Config for tips pallets, allowing us to run migrations for them without -// implementing their configs on [`Runtime`]. -pub struct UnlockConfigForTips; -impl pallet_tips::migrations::unreserve_deposits::UnlockConfig<()> for UnlockConfigForTips { - type Currency = Balances; - type Hash = Hash; - type DataDepositPerByte = DataDepositPerByte; - type TipReportDepositBase = TipReportDepositBase; - type AccountId = AccountId; - type BlockNumber = BlockNumberFor; - type DbWeight = ::DbWeight; - type PalletName = TipsPalletName; -} - /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, From d0c11e28e8ed9bf3a593cc88ea9241b8de008f2e Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Wed, 19 Jun 2024 11:41:45 +0800 Subject: [PATCH 5/7] slpx: set the default value of channel_id to 0 --- pallets/slpx/src/lib.rs | 13 ++++++++----- pallets/slpx/src/migration.rs | 3 ++- pallets/slpx/src/types.rs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pallets/slpx/src/lib.rs b/pallets/slpx/src/lib.rs index a4fc8440a..26ba5d0f4 100644 --- a/pallets/slpx/src/lib.rs +++ b/pallets/slpx/src/lib.rs @@ -459,7 +459,8 @@ pub mod pallet { currency_id, remark, target_chain, - channel_id: None, + // default to 0 + channel_id: 0u32, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -519,7 +520,8 @@ pub mod pallet { bifrost_chain_caller, derivative_account, target_chain, - channel_id: None, + // default to 0 + channel_id: 0u32, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -743,7 +745,8 @@ pub mod pallet { currency_id, remark, target_chain, - channel_id: None, + // default to 0 + channel_id: 0u32, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -776,7 +779,7 @@ pub mod pallet { currency_id, remark, target_chain, - channel_id: Some(channel_id), + channel_id, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -1039,7 +1042,7 @@ impl Pallet { order.currency_id, currency_amount, order.remark.clone(), - order.channel_id, + Some(order.channel_id), ) .map_err(|_| Error::::ArgumentsError)?; let vtoken_id = T::VtokenMintingInterface::vtoken_id(order.currency_id) diff --git a/pallets/slpx/src/migration.rs b/pallets/slpx/src/migration.rs index 7342681b4..61f99a62b 100644 --- a/pallets/slpx/src/migration.rs +++ b/pallets/slpx/src/migration.rs @@ -149,7 +149,8 @@ pub fn migrate_to_v1() -> Weight { order_type: old_order.order_type, remark: old_order.remark, target_chain: old_order.target_chain, - channel_id: None, + // default to 0 + channel_id: 0u32, }) .expect("BoundedVec should not overflow"); weight = weight.saturating_add(T::DbWeight::get().reads_writes(0, 1)); diff --git a/pallets/slpx/src/types.rs b/pallets/slpx/src/types.rs index afe75e315..e54269773 100644 --- a/pallets/slpx/src/types.rs +++ b/pallets/slpx/src/types.rs @@ -130,7 +130,7 @@ pub struct Order { pub order_type: OrderType, pub remark: BoundedVec>, pub target_chain: TargetChain, - pub channel_id: Option, + pub channel_id: u32, } #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] From d0486132be654265d13fd650cbe7d2c9b5ecb534 Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Wed, 19 Jun 2024 13:34:33 +0800 Subject: [PATCH 6/7] resolve conflicts --- pallets/slpx/src/benchmarking.rs | 1 - pallets/slpx/src/lib.rs | 1 - pallets/slpx/src/tests.rs | 6 ++---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pallets/slpx/src/benchmarking.rs b/pallets/slpx/src/benchmarking.rs index 0ab6335d9..d0c07e15d 100644 --- a/pallets/slpx/src/benchmarking.rs +++ b/pallets/slpx/src/benchmarking.rs @@ -107,7 +107,6 @@ mod benchmarks { KSM, TargetChain::Astar(receiver), BoundedVec::default(), - None, ); } diff --git a/pallets/slpx/src/lib.rs b/pallets/slpx/src/lib.rs index 247f88890..90b970239 100644 --- a/pallets/slpx/src/lib.rs +++ b/pallets/slpx/src/lib.rs @@ -445,7 +445,6 @@ pub mod pallet { currency_id: CurrencyIdOf, target_chain: TargetChain>, remark: BoundedVec>, - channel_id: Option, ) -> DispatchResultWithPostInfo { let (source_chain_caller, derivative_account, bifrost_chain_caller) = Self::ensure_singer_on_whitelist(origin.clone(), evm_caller, &target_chain)?; diff --git a/pallets/slpx/src/tests.rs b/pallets/slpx/src/tests.rs index 14b44d833..2ab622765 100644 --- a/pallets/slpx/src/tests.rs +++ b/pallets/slpx/src/tests.rs @@ -354,8 +354,7 @@ fn test_add_order() { source_chain_caller, DOT, TargetChain::Astar(source_chain_caller), - BoundedVec::default(), - None + BoundedVec::default() )); assert_eq!(OrderQueue::::get().len(), 1usize); assert_ok!(Slpx::redeem( @@ -414,8 +413,7 @@ fn test_hook() { source_chain_caller, DOT, TargetChain::Astar(source_chain_caller), - BoundedVec::default(), - None + BoundedVec::default() )); assert_eq!(OrderQueue::::get().len(), 1usize); >::set_block_number(2u32.into()); From 35d003e8d5834474b1820bb271321990b45597d3 Mon Sep 17 00:00:00 2001 From: SunTiebing <1045060705@qq.com> Date: Wed, 19 Jun 2024 15:28:26 +0800 Subject: [PATCH 7/7] change the location of the old data structure during storage migration --- pallets/slpx/src/migration.rs | 19 +++++++++++++++---- pallets/slpx/src/types.rs | 13 ------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pallets/slpx/src/migration.rs b/pallets/slpx/src/migration.rs index 61f99a62b..934c227ef 100644 --- a/pallets/slpx/src/migration.rs +++ b/pallets/slpx/src/migration.rs @@ -77,11 +77,9 @@ impl OnRuntimeUpgrade for BifrostPolkadotAddCurrencyToSupportXcmFee = StorageValue< @@ -92,6 +90,19 @@ mod v0 { >, ValueQuery, >; + + #[derive(Encode, Decode)] + pub struct OldOrder { + pub source_chain_caller: OrderCaller, + pub bifrost_chain_caller: AccountId, + pub derivative_account: AccountId, + pub create_block_number: BlockNumber, + pub currency_id: CurrencyId, + pub currency_amount: Balance, + pub order_type: OrderType, + pub remark: BoundedVec>, + pub target_chain: TargetChain, + } } pub mod v1 { diff --git a/pallets/slpx/src/types.rs b/pallets/slpx/src/types.rs index e54269773..5290126d5 100644 --- a/pallets/slpx/src/types.rs +++ b/pallets/slpx/src/types.rs @@ -132,16 +132,3 @@ pub struct Order { pub target_chain: TargetChain, pub channel_id: u32, } - -#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct OldOrder { - pub source_chain_caller: OrderCaller, - pub bifrost_chain_caller: AccountId, - pub derivative_account: AccountId, - pub create_block_number: BlockNumber, - pub currency_id: CurrencyId, - pub currency_amount: Balance, - pub order_type: OrderType, - pub remark: BoundedVec>, - pub target_chain: TargetChain, -}