From b8621376753076d0e4919e83d9c8927863ee8f90 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 4 Apr 2023 22:59:28 +0800 Subject: [PATCH 001/116] Introduce XcmFeesToAccount fee manager --- polkadot/runtime/kusama/src/xcm_config.rs | 13 +++-- polkadot/runtime/polkadot/src/xcm_config.rs | 11 ++-- polkadot/runtime/rococo/src/xcm_config.rs | 10 ++-- polkadot/runtime/westend/src/xcm_config.rs | 14 +++-- .../pallet-xcm-benchmarks/src/generic/mock.rs | 6 ++- .../xcm/xcm-builder/src/currency_adapter.rs | 6 ++- polkadot/xcm/xcm-builder/src/fee_handling.rs | 51 +++++++++++++++++++ .../xcm/xcm-builder/src/fungibles_adapter.rs | 12 ++++- polkadot/xcm/xcm-builder/src/lib.rs | 3 ++ .../xcm-builder/src/nonfungibles_adapter.rs | 12 ++++- polkadot/xcm/xcm-builder/src/tests/mock.rs | 4 +- polkadot/xcm/xcm-executor/src/lib.rs | 16 +++--- .../xcm-executor/src/traits/fee_manager.rs | 4 +- .../xcm-executor/src/traits/transact_asset.rs | 12 ++++- 14 files changed, 143 insertions(+), 31 deletions(-) create mode 100644 polkadot/xcm/xcm-builder/src/fee_handling.rs diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index c90e6c55a94b..aa040e3d26d4 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -18,8 +18,8 @@ use super::{ parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, Fellows, ParaId, Runtime, - RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, TransactionByteFee, WeightToFee, - XcmPallet, + RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, TransactionByteFee, Treasury, + WeightToFee, XcmPallet, }; use frame_support::{ match_types, parameter_types, @@ -42,7 +42,7 @@ use xcm_builder::{ CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::traits::WithOriginFilter; @@ -61,6 +61,8 @@ parameter_types! { pub CheckAccount: AccountId = XcmPallet::check_account(); /// The check account that is allowed to mint assets locally. pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local); + /// The treasury account where XCM fees would be sent to. + pub TreasuryAccount: Option = Some(Treasury::account_id()); } /// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to @@ -139,6 +141,9 @@ match_types! { pub type OnlyParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(1000)) } + } } /// The barriers one of which must be passed for an XCM message to be executed. @@ -339,7 +344,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); + type FeeManager = XcmFeesToAccount; // No bridges yet... type MessageExporter = (); type UniversalAliases = Nothing; diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs index 6c45f1cec402..934a5b8b0b05 100644 --- a/polkadot/runtime/polkadot/src/xcm_config.rs +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -19,7 +19,7 @@ use super::{ parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, FellowshipAdmin, GeneralAdmin, ParaId, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, - TransactionByteFee, WeightToFee, XcmPallet, + TransactionByteFee, Treasury, WeightToFee, XcmPallet, }; use frame_support::{ match_types, parameter_types, @@ -44,7 +44,7 @@ use xcm_builder::{ ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::traits::WithOriginFilter; @@ -61,6 +61,8 @@ parameter_types! { pub CheckAccount: AccountId = XcmPallet::check_account(); /// The Checking Account along with the indication that the local chain is able to mint tokens. pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local); + /// The treasury account where XCM fees would be sent to. + pub TreasuryAccount: Option = Some(Treasury::account_id()); } /// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to @@ -150,6 +152,9 @@ match_types! { MultiLocation { parents: 0, interior: X1(Parachain(COLLECTIVES_ID)) } | MultiLocation { parents: 0, interior: X2(Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }) } }; + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINT_ID | COLLECTIVES_ID)) } + } } /// The barriers one of which must be passed for an XCM message to be executed. @@ -340,7 +345,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); + type FeeManager = XcmFeesToAccount; // No bridges yet... type MessageExporter = (); type UniversalAliases = Nothing; diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 356cffaa0ba2..0520c16895ff 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -18,7 +18,7 @@ use super::{ parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, ParaId, Runtime, - RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmPallet, + RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, Treasury, WeightToFee, XcmPallet, }; use frame_support::{ match_types, parameter_types, @@ -41,7 +41,7 @@ use xcm_builder::{ CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete, MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, - WithUniqueTopic, + WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -51,6 +51,7 @@ parameter_types! { pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into(); pub CheckAccount: AccountId = XcmPallet::check_account(); pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local); + pub TreasuryAccount: Option = Some(Treasury::account_id()); } pub type LocationConverter = @@ -135,6 +136,9 @@ match_types! { pub type OnlyParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(1000 | 1002)) } + }; } /// The barriers one of which must be passed for an XCM message to be executed. @@ -314,7 +318,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index a83c38c9f66f..bf360116b613 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -18,10 +18,10 @@ use super::{ parachains_origin, weights, AccountId, AllPalletsWithSystem, Balances, Dmp, ParaId, Runtime, - RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmPallet, + RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, Treasury, WeightToFee, XcmPallet, }; use frame_support::{ - parameter_types, + match_types, parameter_types, traits::{Contains, Everything, Nothing}, }; use frame_system::EnsureRoot; @@ -40,6 +40,7 @@ use xcm_builder::{ CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -49,6 +50,7 @@ parameter_types! { pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into(); pub CheckAccount: AccountId = XcmPallet::check_account(); pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local); + pub TreasuryAccount: Option = Some(Treasury::account_id()); /// The asset ID for the asset that we use to pay for message delivery fees. pub FeeAssetId: AssetId = Concrete(TokenLocation::get()); /// The base fee for the message delivery fees. @@ -241,6 +243,12 @@ impl Contains for SafeCallFilter { } } +match_types! { + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(1000 | 1001)) } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -263,7 +271,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 1b244f316de9..6f9d42df553d 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -79,7 +79,11 @@ impl frame_system::Config for Test { /// The benchmarks in this pallet should never need an asset transactor to begin with. pub struct NoAssetTransactor; impl xcm_executor::traits::TransactAsset for NoAssetTransactor { - fn deposit_asset(_: &MultiAsset, _: &MultiLocation, _: &XcmContext) -> Result<(), XcmError> { + fn deposit_asset( + _: &MultiAsset, + _: &MultiLocation, + _: Option<&XcmContext>, + ) -> Result<(), XcmError> { unreachable!(); } diff --git a/polkadot/xcm/xcm-builder/src/currency_adapter.rs b/polkadot/xcm/xcm-builder/src/currency_adapter.rs index 4dbd4fe8bcd0..ff56eb392d60 100644 --- a/polkadot/xcm/xcm-builder/src/currency_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/currency_adapter.rs @@ -191,7 +191,11 @@ impl< } } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, _context: &XcmContext) -> Result { + fn deposit_asset( + what: &MultiAsset, + who: &MultiLocation, + _context: Option<&XcmContext>, + ) -> Result { log::trace!(target: "xcm::currency_adapter", "deposit_asset what: {:?}, who: {:?}", what, who); // Check we handle this asset. let amount = Matcher::matches_fungible(&what).ok_or(Error::AssetNotHandled)?; diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs new file mode 100644 index 000000000000..dc831dd81847 --- /dev/null +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -0,0 +1,51 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use core::marker::PhantomData; +use frame_support::traits::{Contains, Get}; +use xcm::prelude::*; +use xcm_executor::traits::{FeeManager, FeeReason, TransactAsset}; + +/// A `FeeManager` implementation that simply deposits the fees handled into a specific on-chain +/// `ReceiverAccount`. +/// +/// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets, and also +/// permits specifying `WaivedLocations` for locations that are privileged to not pay for fees. +pub struct XcmFeesToAccount( + PhantomData<(XcmConfig, WaivedLocations, AccountId, ReceiverAccount)>, +); +impl< + XcmConfig: xcm_executor::Config, + WaivedLocations: Contains, + AccountId: Clone + Into<[u8; 32]>, + ReceiverAccount: Get>, + > FeeManager for XcmFeesToAccount +{ + fn is_waived(origin: Option<&MultiLocation>, _: FeeReason) -> bool { + let Some(loc) = origin else { return false }; + WaivedLocations::contains(loc) + } + + fn handle_fee(fees: MultiAssets, context: Option<&XcmContext>) { + if let Some(receiver) = ReceiverAccount::get() { + let dest = AccountId32 { network: None, id: receiver.into() }.into(); + for asset in fees.into_inner() { + let ok = XcmConfig::AssetTransactor::deposit_asset(&asset, &dest, context).is_ok(); + debug_assert!(ok, "`deposit_asset` cannot generally fail"); + } + } + } +} diff --git a/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs b/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs index d7fded01e2db..655f1a3557bf 100644 --- a/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/fungibles_adapter.rs @@ -274,7 +274,11 @@ impl< } } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, _context: &XcmContext) -> XcmResult { + fn deposit_asset( + what: &MultiAsset, + who: &MultiLocation, + _context: Option<&XcmContext>, + ) -> XcmResult { log::trace!( target: "xcm::fungibles_adapter", "deposit_asset what: {:?}, who: {:?}", @@ -371,7 +375,11 @@ impl< >::check_out(dest, what, context) } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult { + fn deposit_asset( + what: &MultiAsset, + who: &MultiLocation, + context: Option<&XcmContext>, + ) -> XcmResult { FungiblesMutateAdapter::< Assets, Matcher, diff --git a/polkadot/xcm/xcm-builder/src/lib.rs b/polkadot/xcm/xcm-builder/src/lib.rs index e3f910409638..d0a31ffb6497 100644 --- a/polkadot/xcm/xcm-builder/src/lib.rs +++ b/polkadot/xcm/xcm-builder/src/lib.rs @@ -67,6 +67,9 @@ pub use process_xcm_message::ProcessXcmMessage; mod currency_adapter; pub use currency_adapter::CurrencyAdapter; +mod fee_handling; +pub use fee_handling::XcmFeesToAccount; + mod fungibles_adapter; pub use fungibles_adapter::{ AssetChecking, DualMint, FungiblesAdapter, FungiblesMutateAdapter, FungiblesTransferAdapter, diff --git a/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs b/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs index 6cf5980df0e9..5caae90333c0 100644 --- a/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs +++ b/polkadot/xcm/xcm-builder/src/nonfungibles_adapter.rs @@ -207,7 +207,11 @@ impl< } } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult { + fn deposit_asset( + what: &MultiAsset, + who: &MultiLocation, + context: Option<&XcmContext>, + ) -> XcmResult { log::trace!( target: LOG_TARGET, "deposit_asset what: {:?}, who: {:?}, context: {:?}", @@ -307,7 +311,11 @@ impl< >::check_out(dest, what, context) } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult { + fn deposit_asset( + what: &MultiAsset, + who: &MultiLocation, + context: Option<&XcmContext>, + ) -> XcmResult { NonFungiblesMutateAdapter::< Assets, Matcher, diff --git a/polkadot/xcm/xcm-builder/src/tests/mock.rs b/polkadot/xcm/xcm-builder/src/tests/mock.rs index 0e7b748106ef..ace493f31502 100644 --- a/polkadot/xcm/xcm-builder/src/tests/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/mock.rs @@ -254,7 +254,7 @@ impl TransactAsset for TestAssetTransactor { fn deposit_asset( what: &MultiAsset, who: &MultiLocation, - _context: &XcmContext, + _context: Option<&XcmContext>, ) -> Result<(), XcmError> { add_asset(*who, what.clone()); Ok(()) @@ -527,7 +527,7 @@ impl FeeManager for TestFeeManager { fn is_waived(_: Option<&MultiLocation>, r: FeeReason) -> bool { IS_WAIVED.with(|l| l.borrow().contains(&r)) } - fn handle_fee(_: MultiAssets) {} + fn handle_fee(_: MultiAssets, _: Option<&XcmContext>) {} } #[derive(Clone, Eq, PartialEq, Debug)] diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index a48cd3259d67..bddfe0884dab 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -248,7 +248,7 @@ impl ExecuteXcm for XcmExecutor XcmExecutor { let (ticket, fee) = validate_send::(dest, msg)?; if !Config::FeeManager::is_waived(self.origin_ref(), reason) { let paid = self.holding.try_take(fee.into()).map_err(|_| XcmError::NotHoldingFees)?; - Config::FeeManager::handle_fee(paid.into()); + Config::FeeManager::handle_fee(paid.into(), Some(&self.context)); } Config::XcmSender::deliver(ticket).map_err(Into::into) } @@ -618,14 +618,18 @@ impl XcmExecutor { DepositAsset { assets, beneficiary } => { let deposited = self.holding.saturating_take(assets); for asset in deposited.into_assets_iter() { - Config::AssetTransactor::deposit_asset(&asset, &beneficiary, &self.context)?; + Config::AssetTransactor::deposit_asset( + &asset, + &beneficiary, + Some(&self.context), + )?; } Ok(()) }, DepositReserveAsset { assets, dest, xcm } => { let deposited = self.holding.saturating_take(assets); for asset in deposited.assets_iter() { - Config::AssetTransactor::deposit_asset(&asset, &dest, &self.context)?; + Config::AssetTransactor::deposit_asset(&asset, &dest, Some(&self.context))?; } // Note that we pass `None` as `maybe_failed_bin` and drop any assets which cannot // be reanchored because we have already called `deposit_asset` on all assets. @@ -953,7 +957,7 @@ impl XcmExecutor { } else { self.holding.try_take(fee.into()).map_err(|_| XcmError::NotHoldingFees)?.into() }; - Config::FeeManager::handle_fee(paid); + Config::FeeManager::handle_fee(paid, Some(&self.context)); Ok(()) } @@ -988,7 +992,7 @@ impl XcmExecutor { let (ticket, fee) = validate_send::(destination, message)?; if !Config::FeeManager::is_waived(self.origin_ref(), fee_reason) { let paid = self.holding.try_take(fee.into()).map_err(|_| XcmError::NotHoldingFees)?; - Config::FeeManager::handle_fee(paid.into()); + Config::FeeManager::handle_fee(paid.into(), Some(&self.context)); } Config::XcmSender::deliver(ticket).map_err(Into::into) } diff --git a/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs b/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs index ad2e108e7dee..588a246ce17f 100644 --- a/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs +++ b/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs @@ -23,7 +23,7 @@ pub trait FeeManager { /// Do something with the fee which has been paid. Doing nothing here silently burns the /// fees. - fn handle_fee(fee: MultiAssets); + fn handle_fee(fee: MultiAssets, context: Option<&XcmContext>); } /// Context under which a fee is paid. @@ -55,5 +55,5 @@ impl FeeManager for () { fn is_waived(_: Option<&MultiLocation>, _: FeeReason) -> bool { true } - fn handle_fee(_: MultiAssets) {} + fn handle_fee(_: MultiAssets, _: Option<&XcmContext>) {} } diff --git a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs index 34cdb0c71413..f7ec3a973570 100644 --- a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs +++ b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs @@ -87,7 +87,11 @@ pub trait TransactAsset { /// Deposit the `what` asset into the account of `who`. /// /// Implementations should return `XcmError::FailedToTransactAsset` if deposit failed. - fn deposit_asset(_what: &MultiAsset, _who: &MultiLocation, _context: &XcmContext) -> XcmResult { + fn deposit_asset( + _what: &MultiAsset, + _who: &MultiLocation, + _context: &XcmContext, + ) -> XcmResult { Err(XcmError::Unimplemented) } @@ -195,7 +199,11 @@ impl TransactAsset for Tuple { )* ); } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult { + fn deposit_asset( + what: &MultiAsset, + who: &MultiLocation, + context: &XcmContext, + ) -> XcmResult { for_tuples!( #( match Tuple::deposit_asset(what, who, context) { Err(XcmError::AssetNotFound) | Err(XcmError::Unimplemented) => (), From b1ca17e092003509872eccf02f9cb5f81353a49e Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 4 Apr 2023 23:43:42 +0800 Subject: [PATCH 002/116] Put system parachain IDs into consts --- polkadot/runtime/kusama/constants/src/lib.rs | 6 ++++++ polkadot/runtime/kusama/src/xcm_config.rs | 8 ++++---- polkadot/runtime/rococo/constants/src/lib.rs | 8 ++++++++ polkadot/runtime/rococo/src/xcm_config.rs | 10 +++++----- polkadot/runtime/westend/constants/src/lib.rs | 8 ++++++++ polkadot/runtime/westend/src/xcm_config.rs | 10 +++++----- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/polkadot/runtime/kusama/constants/src/lib.rs b/polkadot/runtime/kusama/constants/src/lib.rs index 78f96b351065..aaf5f76b4818 100644 --- a/polkadot/runtime/kusama/constants/src/lib.rs +++ b/polkadot/runtime/kusama/constants/src/lib.rs @@ -97,6 +97,12 @@ pub mod fee { } } +/// System Parachains. +pub mod system_parachain { + /// Statemine parachain ID. + pub const STATEMINE_ID: u32 = 1000; +} + #[cfg(test)] mod tests { use super::{ diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index aa040e3d26d4..89529c5cee7f 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -27,7 +27,7 @@ use frame_support::{ weights::Weight, }; use frame_system::EnsureRoot; -use kusama_runtime_constants::currency::CENTS; +use kusama_runtime_constants::{currency::CENTS, system_parachain::*}; use runtime_common::{ crowdloan, paras_registrar, xcm_sender::{ChildParachainRouter, ExponentialPrice}, @@ -128,7 +128,7 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const Statemine: MultiLocation = Parachain(1000).into_location(); + pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); pub const Encointer: MultiLocation = Parachain(1001).into_location(); pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get()); pub const KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Encointer::get()); @@ -142,7 +142,7 @@ match_types! { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(1000)) } + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID)) } } } @@ -362,7 +362,7 @@ parameter_types! { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parachain(1000).into()); + pub ReachableDest: Option = Some(Parachain(STATEMINE_ID).into()); } /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 214e2f3fa980..4f8ac09d46ee 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -99,6 +99,14 @@ pub mod fee { } } +/// System Parachains. +pub mod system_parachain { + /// Statemine parachain ID. + pub const STATEMINE_ID: u32 = 1000; + /// Contracts parachain ID. + pub const CONTRACTS_ID: u32 = 1002; +} + #[cfg(test)] mod tests { use super::{ diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 0520c16895ff..6dabdee4edec 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -26,7 +26,7 @@ use frame_support::{ weights::Weight, }; use frame_system::EnsureRoot; -use rococo_runtime_constants::currency::CENTS; +use rococo_runtime_constants::{currency::CENTS, system_parachain::*}; use runtime_common::{ crowdloan, paras_registrar, xcm_sender::{ChildParachainRouter, ExponentialPrice}, @@ -108,8 +108,8 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const Rockmine: MultiLocation = Parachain(1000).into_location(); - pub const Contracts: MultiLocation = Parachain(1002).into_location(); + pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); + pub const Contracts: MultiLocation = Parachain(CONTRACTS_ID).into_location(); pub const Encointer: MultiLocation = Parachain(1003).into_location(); pub const Tick: MultiLocation = Parachain(100).into_location(); pub const Trick: MultiLocation = Parachain(110).into_location(); @@ -137,7 +137,7 @@ match_types! { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(1000 | 1002)) } + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | CONTRACTS_ID)) } }; } @@ -328,7 +328,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parachain(1000).into()); + pub ReachableDest: Option = Some(Parachain(STATEMINE_ID).into()); } /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index f9830dab3325..984a7e817440 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -96,6 +96,14 @@ pub mod fee { } } +/// System Parachains. +pub mod system_parachain { + /// Westmint parachain ID. + pub const WESTMINT_ID: u32 = 1000; + /// Collectives parachain ID. + pub const COLLECTIVES_ID: u32 = 1001; +} + #[cfg(test)] mod tests { use super::{ diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index bf360116b613..0fa79f1cf954 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -31,7 +31,7 @@ use runtime_common::{ ToAuthor, }; use sp_core::ConstU32; -use westend_runtime_constants::currency::CENTS; +use westend_runtime_constants::{currency::CENTS, system_parachain::*}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -92,8 +92,8 @@ pub type XcmRouter = WithUniqueTopic<( )>; parameter_types! { - pub const Westmint: MultiLocation = Parachain(1000).into_location(); - pub const Collectives: MultiLocation = Parachain(1001).into_location(); + pub const Westmint: MultiLocation = Parachain(WESTMINT_ID).into_location(); + pub const Collectives: MultiLocation = Parachain(COLLECTIVES_ID).into_location(); pub const Wnd: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); pub const WndForWestmint: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Westmint::get()); pub const WndForCollectives: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Collectives::get()); @@ -103,7 +103,7 @@ parameter_types! { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parachain(1000).into()); + pub ReachableDest: Option = Some(Parachain(WESTMINT_ID).into()); } pub type TrustedTeleporters = @@ -245,7 +245,7 @@ impl Contains for SafeCallFilter { match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(1000 | 1001)) } + MultiLocation { parents: 0, interior: X1(Parachain(WESTMINT_ID | COLLECTIVES_ID)) } }; } From fa6e6e24c3a7bacdb00ebb5fc7f6652ae8367c77 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 4 Apr 2023 23:50:08 +0800 Subject: [PATCH 003/116] Fixes --- polkadot/runtime/kusama/src/xcm_config.rs | 2 +- polkadot/runtime/polkadot/src/xcm_config.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index 89529c5cee7f..b73639a6baed 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -143,7 +143,7 @@ match_types! { }; pub type SystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID)) } - } + }; } /// The barriers one of which must be passed for an XCM message to be executed. diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs index 934a5b8b0b05..09c24e810bd5 100644 --- a/polkadot/runtime/polkadot/src/xcm_config.rs +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -154,7 +154,7 @@ match_types! { }; pub type SystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(STATEMINT_ID | COLLECTIVES_ID)) } - } + }; } /// The barriers one of which must be passed for an XCM message to be executed. From 48d3a187322a1162d5de6554347aeec807250654 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 4 Apr 2023 23:52:06 +0800 Subject: [PATCH 004/116] Remove XcmFeesToAccount config for Westend --- polkadot/runtime/westend/src/xcm_config.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index 0fa79f1cf954..c09ae29d9f98 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -18,10 +18,10 @@ use super::{ parachains_origin, weights, AccountId, AllPalletsWithSystem, Balances, Dmp, ParaId, Runtime, - RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, Treasury, WeightToFee, XcmPallet, + RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmPallet, }; use frame_support::{ - match_types, parameter_types, + parameter_types, traits::{Contains, Everything, Nothing}, }; use frame_system::EnsureRoot; @@ -40,7 +40,6 @@ use xcm_builder::{ CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, - XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -50,7 +49,6 @@ parameter_types! { pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into(); pub CheckAccount: AccountId = XcmPallet::check_account(); pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local); - pub TreasuryAccount: Option = Some(Treasury::account_id()); /// The asset ID for the asset that we use to pay for message delivery fees. pub FeeAssetId: AssetId = Concrete(TokenLocation::get()); /// The base fee for the message delivery fees. @@ -243,12 +241,6 @@ impl Contains for SafeCallFilter { } } -match_types! { - pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(WESTMINT_ID | COLLECTIVES_ID)) } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -271,7 +263,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = XcmFeesToAccount; + type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; From cdc288a37fc28b0ee56ae24e2744e2b683197cfd Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 5 Apr 2023 03:18:51 +0800 Subject: [PATCH 005/116] Include Encointer as a system parachain --- polkadot/runtime/kusama/constants/src/lib.rs | 2 ++ polkadot/runtime/kusama/src/xcm_config.rs | 4 ++-- polkadot/runtime/rococo/constants/src/lib.rs | 2 ++ polkadot/runtime/rococo/src/xcm_config.rs | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/kusama/constants/src/lib.rs b/polkadot/runtime/kusama/constants/src/lib.rs index aaf5f76b4818..26632a835a3f 100644 --- a/polkadot/runtime/kusama/constants/src/lib.rs +++ b/polkadot/runtime/kusama/constants/src/lib.rs @@ -101,6 +101,8 @@ pub mod fee { pub mod system_parachain { /// Statemine parachain ID. pub const STATEMINE_ID: u32 = 1000; + /// Encointer parachain ID. + pub const ENCOINTER_ID: u32 = 1001; } #[cfg(test)] diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index b73639a6baed..f848ab2a0485 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -129,7 +129,7 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); - pub const Encointer: MultiLocation = Parachain(1001).into_location(); + pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get()); pub const KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Encointer::get()); pub const MaxAssetsIntoHolding: u32 = 64; @@ -142,7 +142,7 @@ match_types! { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | ENCOINTER_ID)) } }; } diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 4f8ac09d46ee..3cf6e0875328 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -105,6 +105,8 @@ pub mod system_parachain { pub const STATEMINE_ID: u32 = 1000; /// Contracts parachain ID. pub const CONTRACTS_ID: u32 = 1002; + /// Encointer parachain ID. + pub const ENCOINTER_ID: u32 = 1003; } #[cfg(test)] diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 6dabdee4edec..044e427b60f7 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -110,7 +110,7 @@ parameter_types! { pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); pub const Contracts: MultiLocation = Parachain(CONTRACTS_ID).into_location(); - pub const Encointer: MultiLocation = Parachain(1003).into_location(); + pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const Tick: MultiLocation = Parachain(100).into_location(); pub const Trick: MultiLocation = Parachain(110).into_location(); pub const Track: MultiLocation = Parachain(120).into_location(); @@ -137,7 +137,7 @@ match_types! { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | CONTRACTS_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | CONTRACTS_ID | ENCOINTER_ID)) } }; } From dc48ba32399f002f08fea6f58e03a950bc71fcfd Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 5 Apr 2023 18:11:00 +0800 Subject: [PATCH 006/116] Emit warning when deposit_asset fails --- polkadot/xcm/xcm-builder/src/fee_handling.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs index dc831dd81847..3710210fd03b 100644 --- a/polkadot/xcm/xcm-builder/src/fee_handling.rs +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -43,8 +43,13 @@ impl< if let Some(receiver) = ReceiverAccount::get() { let dest = AccountId32 { network: None, id: receiver.into() }.into(); for asset in fees.into_inner() { - let ok = XcmConfig::AssetTransactor::deposit_asset(&asset, &dest, context).is_ok(); - debug_assert!(ok, "`deposit_asset` cannot generally fail"); + if let Err(e) = XcmConfig::AssetTransactor::deposit_asset(&asset, &dest, context) { + log::warn!( + target: "xcm::fees", + "`AssetTransactor::deposit_asset` returned error: {:?}, burning fees: {:?}", + e, asset, + ); + } } } } From 1299ad933a9dabed0e6e1316d9c425ff5ebf00fc Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 5 Apr 2023 18:12:55 +0800 Subject: [PATCH 007/116] Add comment on what happens when deposit_asset errors --- polkadot/xcm/xcm-builder/src/fee_handling.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs index 3710210fd03b..049055471d32 100644 --- a/polkadot/xcm/xcm-builder/src/fee_handling.rs +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -23,7 +23,9 @@ use xcm_executor::traits::{FeeManager, FeeReason, TransactAsset}; /// `ReceiverAccount`. /// /// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets, and also -/// permits specifying `WaivedLocations` for locations that are privileged to not pay for fees. +/// permits specifying `WaivedLocations` for locations that are privileged to not pay for fees. If +/// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be +/// logged. pub struct XcmFeesToAccount( PhantomData<(XcmConfig, WaivedLocations, AccountId, ReceiverAccount)>, ); From 8d7a4225fb44a2da0277e1070d7782f7c0b238fd Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 5 Apr 2023 18:14:23 +0800 Subject: [PATCH 008/116] Fixes --- polkadot/runtime/test-runtime/src/xcm_config.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/test-runtime/src/xcm_config.rs b/polkadot/runtime/test-runtime/src/xcm_config.rs index 2113bbae66ad..400658b13863 100644 --- a/polkadot/runtime/test-runtime/src/xcm_config.rs +++ b/polkadot/runtime/test-runtime/src/xcm_config.rs @@ -60,7 +60,11 @@ pub type Barrier = AllowUnpaidExecutionFrom; pub struct DummyAssetTransactor; impl TransactAsset for DummyAssetTransactor { - fn deposit_asset(_what: &MultiAsset, _who: &MultiLocation, _context: &XcmContext) -> XcmResult { + fn deposit_asset( + _what: &MultiAsset, + _who: &MultiLocation, + _context: Option<&XcmContext>, + ) -> XcmResult { Ok(()) } From 6f1eaacbbc98218fa7bc5552e145855d2ef0e355 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 6 Apr 2023 15:09:44 +0800 Subject: [PATCH 009/116] Move SystemParachains to constants --- Cargo.lock | 3 +++ polkadot/runtime/kusama/constants/Cargo.toml | 3 +++ polkadot/runtime/kusama/constants/src/lib.rs | 8 ++++++++ polkadot/runtime/kusama/src/xcm_config.rs | 3 --- polkadot/runtime/polkadot/constants/Cargo.toml | 3 +++ polkadot/runtime/polkadot/constants/src/lib.rs | 8 ++++++++ polkadot/runtime/polkadot/src/xcm_config.rs | 3 --- polkadot/runtime/rococo/constants/Cargo.toml | 3 +++ polkadot/runtime/rococo/constants/src/lib.rs | 12 ++++++++++-- polkadot/runtime/rococo/src/xcm_config.rs | 7 ++----- 10 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c755be63042b..646f8180c99f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7039,6 +7039,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-weights", + "xcm", ] [[package]] @@ -12904,6 +12905,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-weights", + "xcm", ] [[package]] @@ -14381,6 +14383,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-weights", + "xcm", ] [[package]] diff --git a/polkadot/runtime/kusama/constants/Cargo.toml b/polkadot/runtime/kusama/constants/Cargo.toml index f89fee42742b..0c49c9507d66 100644 --- a/polkadot/runtime/kusama/constants/Cargo.toml +++ b/polkadot/runtime/kusama/constants/Cargo.toml @@ -15,6 +15,8 @@ sp-runtime = { path = "../../../../substrate/primitives/runtime", default-featur sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } sp-core = { path = "../../../../substrate/primitives/core", default-features = false } +xcm = { package = "xcm", path = "../../../xcm", default-features = false } + [features] default = [ "std" ] std = [ @@ -24,4 +26,5 @@ std = [ "sp-core/std", "sp-runtime/std", "sp-weights/std", + "xcm/std", ] diff --git a/polkadot/runtime/kusama/constants/src/lib.rs b/polkadot/runtime/kusama/constants/src/lib.rs index 26632a835a3f..b9a84b065971 100644 --- a/polkadot/runtime/kusama/constants/src/lib.rs +++ b/polkadot/runtime/kusama/constants/src/lib.rs @@ -99,10 +99,18 @@ pub mod fee { /// System Parachains. pub mod system_parachain { + use xcm::latest::prelude::*; + /// Statemine parachain ID. pub const STATEMINE_ID: u32 = 1000; /// Encointer parachain ID. pub const ENCOINTER_ID: u32 = 1001; + + frame_support::match_types! { + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | ENCOINTER_ID)) } + }; + } } #[cfg(test)] diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index f848ab2a0485..7cc87559d6d0 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -141,9 +141,6 @@ match_types! { pub type OnlyParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; - pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | ENCOINTER_ID)) } - }; } /// The barriers one of which must be passed for an XCM message to be executed. diff --git a/polkadot/runtime/polkadot/constants/Cargo.toml b/polkadot/runtime/polkadot/constants/Cargo.toml index 2b7f8ccacebb..e11f477599ad 100644 --- a/polkadot/runtime/polkadot/constants/Cargo.toml +++ b/polkadot/runtime/polkadot/constants/Cargo.toml @@ -15,6 +15,8 @@ sp-runtime = { path = "../../../../substrate/primitives/runtime", default-featur sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } sp-core = { path = "../../../../substrate/primitives/core", default-features = false } +xcm = { package = "xcm", path = "../../../xcm", default-features = false } + [features] default = [ "std" ] std = [ @@ -24,4 +26,5 @@ std = [ "sp-core/std", "sp-runtime/std", "sp-weights/std", + "xcm/std", ] diff --git a/polkadot/runtime/polkadot/constants/src/lib.rs b/polkadot/runtime/polkadot/constants/src/lib.rs index 304d86d1dd7c..c84fe484e759 100644 --- a/polkadot/runtime/polkadot/constants/src/lib.rs +++ b/polkadot/runtime/polkadot/constants/src/lib.rs @@ -113,10 +113,18 @@ pub mod xcm { /// System Parachains. pub mod system_parachain { + use xcm::latest::prelude::*; + /// Statemint parachain ID. pub const STATEMINT_ID: u32 = 1000; /// Collectives parachain ID. pub const COLLECTIVES_ID: u32 = 1001; + + frame_support::match_types! { + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINT_ID | COLLECTIVES_ID)) } + }; + } } #[cfg(test)] diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs index 09c24e810bd5..acfa63ec1a10 100644 --- a/polkadot/runtime/polkadot/src/xcm_config.rs +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -152,9 +152,6 @@ match_types! { MultiLocation { parents: 0, interior: X1(Parachain(COLLECTIVES_ID)) } | MultiLocation { parents: 0, interior: X2(Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }) } }; - pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINT_ID | COLLECTIVES_ID)) } - }; } /// The barriers one of which must be passed for an XCM message to be executed. diff --git a/polkadot/runtime/rococo/constants/Cargo.toml b/polkadot/runtime/rococo/constants/Cargo.toml index 174e4e83a5e3..df85ed93309e 100644 --- a/polkadot/runtime/rococo/constants/Cargo.toml +++ b/polkadot/runtime/rococo/constants/Cargo.toml @@ -15,6 +15,8 @@ sp-runtime = { path = "../../../../substrate/primitives/runtime", default-featur sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } sp-core = { path = "../../../../substrate/primitives/core", default-features = false } +xcm = { package = "xcm", path = "../../../xcm", default-features = false } + [features] default = [ "std" ] std = [ @@ -24,4 +26,5 @@ std = [ "sp-core/std", "sp-runtime/std", "sp-weights/std", + "xcm/std", ] diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 3cf6e0875328..c77f4984e3fb 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -101,12 +101,20 @@ pub mod fee { /// System Parachains. pub mod system_parachain { - /// Statemine parachain ID. - pub const STATEMINE_ID: u32 = 1000; + use xcm::latest::prelude::*; + + /// Rockmine parachain ID. + pub const ROCKMINE_ID: u32 = 1000; /// Contracts parachain ID. pub const CONTRACTS_ID: u32 = 1002; /// Encointer parachain ID. pub const ENCOINTER_ID: u32 = 1003; + + frame_support::match_types! { + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(ROCKMINE_ID | CONTRACTS_ID | ENCOINTER_ID)) } + }; + } } #[cfg(test)] diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 044e427b60f7..d8207dbc37ad 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -108,7 +108,7 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); + pub const Rockmine: MultiLocation = Parachain(ROCKMINE_ID).into_location(); pub const Contracts: MultiLocation = Parachain(CONTRACTS_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const Tick: MultiLocation = Parachain(100).into_location(); @@ -136,9 +136,6 @@ match_types! { pub type OnlyParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; - pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | CONTRACTS_ID | ENCOINTER_ID)) } - }; } /// The barriers one of which must be passed for an XCM message to be executed. @@ -328,7 +325,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parachain(STATEMINE_ID).into()); + pub ReachableDest: Option = Some(Parachain(ROCKMINE_ID).into()); } /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior From 24c560e2fc91a1f34be4c631828e1c38aeb5f5b6 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 6 Apr 2023 21:28:38 +0800 Subject: [PATCH 010/116] Fixes --- polkadot/runtime/rococo/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 6894bd7bbf44..df5c27b77c26 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2145,7 +2145,10 @@ sp_api::impl_runtime_apis! { Rockmine::get(), MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, )); - pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(( + Rockmine::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, + )); } impl pallet_xcm_benchmarks::fungible::Config for Runtime { From 72b8af5f009fd13974fd56dd143a137a9d81e5c5 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 7 Apr 2023 23:37:01 +0800 Subject: [PATCH 011/116] cargo fmt --- .../xcm/xcm-executor/src/traits/transact_asset.rs | 12 ++---------- substrate/client/network/src/service.rs | 14 ++++++++------ .../rpc-spec-v2/src/chain_head/chain_head.rs | 6 ++++-- .../src/chain_head/chain_head_storage.rs | 4 +--- substrate/frame/broker/src/dispatchable_impls.rs | 4 ++-- substrate/frame/broker/src/tick_impls.rs | 4 ++-- substrate/frame/safe-mode/src/lib.rs | 2 +- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs index f7ec3a973570..34cdb0c71413 100644 --- a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs +++ b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs @@ -87,11 +87,7 @@ pub trait TransactAsset { /// Deposit the `what` asset into the account of `who`. /// /// Implementations should return `XcmError::FailedToTransactAsset` if deposit failed. - fn deposit_asset( - _what: &MultiAsset, - _who: &MultiLocation, - _context: &XcmContext, - ) -> XcmResult { + fn deposit_asset(_what: &MultiAsset, _who: &MultiLocation, _context: &XcmContext) -> XcmResult { Err(XcmError::Unimplemented) } @@ -199,11 +195,7 @@ impl TransactAsset for Tuple { )* ); } - fn deposit_asset( - what: &MultiAsset, - who: &MultiLocation, - context: &XcmContext, - ) -> XcmResult { + fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult { for_tuples!( #( match Tuple::deposit_asset(what, who, context) { Err(XcmError::AssetNotFound) | Err(XcmError::Unimplemented) => (), diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index aca0072a31de..c1df48ad7858 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -943,9 +943,10 @@ where peers: HashSet, ) -> Result<(), String> { let Some(set_id) = self.notification_protocol_ids.get(&protocol) else { - return Err( - format!("Cannot add peers to reserved set of unknown protocol: {}", protocol) - ) + return Err(format!( + "Cannot add peers to reserved set of unknown protocol: {}", + protocol + )) }; let peers = self.split_multiaddr_and_peer_id(peers)?; @@ -974,9 +975,10 @@ where peers: Vec, ) -> Result<(), String> { let Some(set_id) = self.notification_protocol_ids.get(&protocol) else { - return Err( - format!("Cannot remove peers from reserved set of unknown protocol: {}", protocol) - ) + return Err(format!( + "Cannot remove peers from reserved set of unknown protocol: {}", + protocol + )) }; for peer_id in peers.into_iter() { diff --git a/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs b/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs index bae7c84df0ed..14364c331e6c 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs @@ -462,7 +462,8 @@ where follow_subscription: String, operation_id: String, ) -> RpcResult<()> { - let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) else { + let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) + else { return Ok(()) }; @@ -479,7 +480,8 @@ where follow_subscription: String, operation_id: String, ) -> RpcResult<()> { - let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) else { + let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) + else { return Ok(()) }; diff --git a/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs b/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs index 5e1f38f9a997..48a673f47e3b 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs @@ -166,9 +166,7 @@ where let mut ret = Vec::with_capacity(self.operation_max_storage_items); for _ in 0..self.operation_max_storage_items { - let Some(key) = keys_iter.next() else { - break - }; + let Some(key) = keys_iter.next() else { break }; let result = match ty { IterQueryType::Value => self.query_storage_value(hash, &key, child_key), diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 7c1d5a786b7c..8dc0c9de393e 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -334,10 +334,10 @@ impl Pallet { contribution.length.saturating_dec(); let Some(mut pool_record) = InstaPoolHistory::::get(r) else { - continue; + continue }; let Some(total_payout) = pool_record.maybe_payout else { - break; + break }; let p = total_payout .saturating_mul(contributed_parts.into()) diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 0677d2793e21..1688d386a531 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -96,7 +96,7 @@ impl Pallet { pub(crate) fn process_revenue() -> bool { let Some((until, amount)) = T::Coretime::check_notify_revenue_info() else { - return false; + return false }; let when: Timeslice = (until / T::TimeslicePeriod::get()).saturating_sub(One::one()).saturated_into(); @@ -290,7 +290,7 @@ impl Pallet { core: CoreIndex, ) { let Some(workplan) = Workplan::::take((timeslice, core)) else { - return; + return }; let workload = Workload::::get(core); let parts_used = workplan.iter().map(|i| i.mask).fold(CoreMask::void(), |a, i| a | i); diff --git a/substrate/frame/safe-mode/src/lib.rs b/substrate/frame/safe-mode/src/lib.rs index ff045b964afb..b8e8378fa9e7 100644 --- a/substrate/frame/safe-mode/src/lib.rs +++ b/substrate/frame/safe-mode/src/lib.rs @@ -398,7 +398,7 @@ pub mod pallet { /// [`EnteredUntil`]. fn on_initialize(current: BlockNumberFor) -> Weight { let Some(limit) = EnteredUntil::::get() else { - return T::WeightInfo::on_initialize_noop(); + return T::WeightInfo::on_initialize_noop() }; if current > limit { From 655b8646b934a8a8e9654b07b8d63e31873e54f0 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 12 Apr 2023 15:54:30 +0200 Subject: [PATCH 012/116] Added BridgeHubs constants (#7053) --- polkadot/runtime/kusama/constants/src/lib.rs | 4 +++- polkadot/runtime/kusama/src/xcm_config.rs | 9 +++++++-- polkadot/runtime/polkadot/constants/src/lib.rs | 4 +++- polkadot/runtime/polkadot/src/xcm_config.rs | 8 ++++++-- polkadot/runtime/rococo/constants/src/lib.rs | 4 +++- polkadot/runtime/rococo/src/xcm_config.rs | 3 +++ polkadot/runtime/westend/constants/src/lib.rs | 2 ++ polkadot/runtime/westend/src/xcm_config.rs | 9 +++++++-- 8 files changed, 34 insertions(+), 9 deletions(-) diff --git a/polkadot/runtime/kusama/constants/src/lib.rs b/polkadot/runtime/kusama/constants/src/lib.rs index b9a84b065971..195d0135b38c 100644 --- a/polkadot/runtime/kusama/constants/src/lib.rs +++ b/polkadot/runtime/kusama/constants/src/lib.rs @@ -105,10 +105,12 @@ pub mod system_parachain { pub const STATEMINE_ID: u32 = 1000; /// Encointer parachain ID. pub const ENCOINTER_ID: u32 = 1001; + /// BridgeHub parachain ID. + pub const BRIDGE_HUB_ID: u32 = 1002; frame_support::match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | ENCOINTER_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) } }; } } diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index 7cc87559d6d0..0dbbf6e2f022 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -130,12 +130,17 @@ parameter_types! { pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); + pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get()); pub const KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Encointer::get()); + pub const KsmForBridgeHub: (MultiAssetFilter, MultiLocation) = (Ksm::get(), BridgeHub::get()); pub const MaxAssetsIntoHolding: u32 = 64; } -pub type TrustedTeleporters = - (xcm_builder::Case, xcm_builder::Case); +pub type TrustedTeleporters = ( + xcm_builder::Case, + xcm_builder::Case, + xcm_builder::Case, +); match_types! { pub type OnlyParachains: impl Contains = { diff --git a/polkadot/runtime/polkadot/constants/src/lib.rs b/polkadot/runtime/polkadot/constants/src/lib.rs index c84fe484e759..c86537f7bde5 100644 --- a/polkadot/runtime/polkadot/constants/src/lib.rs +++ b/polkadot/runtime/polkadot/constants/src/lib.rs @@ -119,10 +119,12 @@ pub mod system_parachain { pub const STATEMINT_ID: u32 = 1000; /// Collectives parachain ID. pub const COLLECTIVES_ID: u32 = 1001; + /// BridgeHub parachain ID. + pub const BRIDGE_HUB_ID: u32 = 1002; frame_support::match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINT_ID | COLLECTIVES_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(STATEMINT_ID | COLLECTIVES_ID | BRIDGE_HUB_ID)) } }; } } diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs index acfa63ec1a10..c7808cb7f6d8 100644 --- a/polkadot/runtime/polkadot/src/xcm_config.rs +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -137,12 +137,16 @@ parameter_types! { pub const DotForStatemint: (MultiAssetFilter, MultiLocation) = (Dot::get(), StatemintLocation::get()); pub const CollectivesLocation: MultiLocation = Parachain(COLLECTIVES_ID).into_location(); pub const DotForCollectives: (MultiAssetFilter, MultiLocation) = (Dot::get(), CollectivesLocation::get()); + pub const DotForBridgeHub: (MultiAssetFilter, MultiLocation) = (Dot::get(), Parachain(BRIDGE_HUB_ID).into_location()); pub const MaxAssetsIntoHolding: u32 = 64; } /// Polkadot Relay recognizes/respects the Statemint chain as a teleporter. -pub type TrustedTeleporters = - (xcm_builder::Case, xcm_builder::Case); +pub type TrustedTeleporters = ( + xcm_builder::Case, + xcm_builder::Case, + xcm_builder::Case, +); match_types! { pub type OnlyParachains: impl Contains = { diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index c77f4984e3fb..2dc775ca0e25 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -109,10 +109,12 @@ pub mod system_parachain { pub const CONTRACTS_ID: u32 = 1002; /// Encointer parachain ID. pub const ENCOINTER_ID: u32 = 1003; + /// BridgeHub parachain ID. + pub const BRIDGE_HUB_ID: u32 = 1013; frame_support::match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(ROCKMINE_ID | CONTRACTS_ID | ENCOINTER_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(ROCKMINE_ID | CONTRACTS_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) } }; } } diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index d8207dbc37ad..e1bde352e0e7 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -111,6 +111,7 @@ parameter_types! { pub const Rockmine: MultiLocation = Parachain(ROCKMINE_ID).into_location(); pub const Contracts: MultiLocation = Parachain(CONTRACTS_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); + pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); pub const Tick: MultiLocation = Parachain(100).into_location(); pub const Trick: MultiLocation = Parachain(110).into_location(); pub const Track: MultiLocation = Parachain(120).into_location(); @@ -120,6 +121,7 @@ parameter_types! { pub const RocForRockmine: (MultiAssetFilter, MultiLocation) = (Roc::get(), Rockmine::get()); pub const RocForContracts: (MultiAssetFilter, MultiLocation) = (Roc::get(), Contracts::get()); pub const RocForEncointer: (MultiAssetFilter, MultiLocation) = (Roc::get(), Encointer::get()); + pub const RocForBridgeHub: (MultiAssetFilter, MultiLocation) = (Roc::get(), BridgeHub::get()); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; } @@ -130,6 +132,7 @@ pub type TrustedTeleporters = ( xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, + xcm_builder::Case, ); match_types! { diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index 984a7e817440..7d8be78ea246 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -102,6 +102,8 @@ pub mod system_parachain { pub const WESTMINT_ID: u32 = 1000; /// Collectives parachain ID. pub const COLLECTIVES_ID: u32 = 1001; + /// BridgeHub parachain ID. + pub const BRIDGE_HUB_ID: u32 = 1002; } #[cfg(test)] diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index c09ae29d9f98..ffab79f0466d 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -92,9 +92,11 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Westmint: MultiLocation = Parachain(WESTMINT_ID).into_location(); pub const Collectives: MultiLocation = Parachain(COLLECTIVES_ID).into_location(); + pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); pub const Wnd: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); pub const WndForWestmint: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Westmint::get()); pub const WndForCollectives: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Collectives::get()); + pub const WndForBridgeHub: (MultiAssetFilter, MultiLocation) = (Wnd::get(), BridgeHub::get()); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; } @@ -104,8 +106,11 @@ parameter_types! { pub ReachableDest: Option = Some(Parachain(WESTMINT_ID).into()); } -pub type TrustedTeleporters = - (xcm_builder::Case, xcm_builder::Case); +pub type TrustedTeleporters = ( + xcm_builder::Case, + xcm_builder::Case, + xcm_builder::Case, +); /// The barriers one of which must be passed for an XCM message to be executed. pub type Barrier = TrailingSetTopicAsId<( From a89c6c2ca76932daeb3ee91aa257bd49180ea9f8 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 13 Apr 2023 19:08:55 +0800 Subject: [PATCH 013/116] Add SystemParachain type to Westmint --- Cargo.lock | 1 + polkadot/runtime/westend/constants/Cargo.toml | 3 +++ polkadot/runtime/westend/constants/src/lib.rs | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 646f8180c99f..f271fce87596 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20459,6 +20459,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-weights", + "xcm", ] [[package]] diff --git a/polkadot/runtime/westend/constants/Cargo.toml b/polkadot/runtime/westend/constants/Cargo.toml index e792a56a5461..180b701211b7 100644 --- a/polkadot/runtime/westend/constants/Cargo.toml +++ b/polkadot/runtime/westend/constants/Cargo.toml @@ -15,6 +15,8 @@ sp-runtime = { path = "../../../../substrate/primitives/runtime", default-featur sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } sp-core = { path = "../../../../substrate/primitives/core", default-features = false } +xcm = { package = "xcm", path = "../../../xcm", default-features = false } + [features] default = [ "std" ] std = [ @@ -24,4 +26,5 @@ std = [ "sp-core/std", "sp-runtime/std", "sp-weights/std", + "xcm/std", ] diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index 7d8be78ea246..66da9cfcc1d6 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -98,12 +98,20 @@ pub mod fee { /// System Parachains. pub mod system_parachain { + use xcm::latest::prelude::*; + /// Westmint parachain ID. pub const WESTMINT_ID: u32 = 1000; /// Collectives parachain ID. pub const COLLECTIVES_ID: u32 = 1001; /// BridgeHub parachain ID. pub const BRIDGE_HUB_ID: u32 = 1002; + + frame_support::match_types! { + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(WESTMINT_ID | COLLECTIVES_ID | BRIDGE_HUB_ID ))} + } + } } #[cfg(test)] From 9512b45eabf3861f82156bf61c974bd749454263 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 28 Apr 2023 17:40:34 +0800 Subject: [PATCH 014/116] Waive fee handling during benchmarking --- polkadot/xcm/xcm-builder/src/fee_handling.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs index 049055471d32..bd47a932c802 100644 --- a/polkadot/xcm/xcm-builder/src/fee_handling.rs +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -37,6 +37,10 @@ impl< > FeeManager for XcmFeesToAccount { fn is_waived(origin: Option<&MultiLocation>, _: FeeReason) -> bool { + #[cfg(feature = "runtime-benchmarks")] + { + return true + } let Some(loc) = origin else { return false }; WaivedLocations::contains(loc) } From e06740fc8998b48528e807196918264fdad7cd88 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 28 Apr 2023 17:52:16 +0800 Subject: [PATCH 015/116] Fixes --- polkadot/xcm/xcm-builder/src/fee_handling.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs index bd47a932c802..8a67d0c44eb9 100644 --- a/polkadot/xcm/xcm-builder/src/fee_handling.rs +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -41,8 +41,11 @@ impl< { return true } - let Some(loc) = origin else { return false }; - WaivedLocations::contains(loc) + #[cfg(not(feature = "runtime-benchmarks"))] + { + let Some(loc) = origin else { return false }; + WaivedLocations::contains(loc) + } } fn handle_fee(fees: MultiAssets, context: Option<&XcmContext>) { From 13226dedc244ea527dc5c9acfeb5ef977bef203a Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 28 Apr 2023 20:36:06 +0800 Subject: [PATCH 016/116] Fixes --- polkadot/xcm/xcm-builder/src/fee_handling.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs index 8a67d0c44eb9..207d58d1fa00 100644 --- a/polkadot/xcm/xcm-builder/src/fee_handling.rs +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -39,7 +39,8 @@ impl< fn is_waived(origin: Option<&MultiLocation>, _: FeeReason) -> bool { #[cfg(feature = "runtime-benchmarks")] { - return true + let _ = origin; + true } #[cfg(not(feature = "runtime-benchmarks"))] { From 2fee6e570d2ec32894a42fb4ab93d54d218a30af Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 22 Jun 2023 14:15:57 +0100 Subject: [PATCH 017/116] Rename to ASSET_HUB_ID Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- polkadot/runtime/kusama/constants/src/lib.rs | 6 +++--- polkadot/runtime/kusama/src/xcm_config.rs | 4 ++-- polkadot/runtime/polkadot/constants/src/lib.rs | 6 +++--- polkadot/runtime/rococo/constants/src/lib.rs | 6 +++--- polkadot/runtime/rococo/src/xcm_config.rs | 4 ++-- polkadot/runtime/westend/constants/src/lib.rs | 4 ++-- polkadot/runtime/westend/src/xcm_config.rs | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/polkadot/runtime/kusama/constants/src/lib.rs b/polkadot/runtime/kusama/constants/src/lib.rs index 195d0135b38c..3edac3b302ad 100644 --- a/polkadot/runtime/kusama/constants/src/lib.rs +++ b/polkadot/runtime/kusama/constants/src/lib.rs @@ -101,8 +101,8 @@ pub mod fee { pub mod system_parachain { use xcm::latest::prelude::*; - /// Statemine parachain ID. - pub const STATEMINE_ID: u32 = 1000; + /// Network's Asset Hub parachain ID. + pub const ASSET_HUB_ID: u32 = 1000; /// Encointer parachain ID. pub const ENCOINTER_ID: u32 = 1001; /// BridgeHub parachain ID. @@ -110,7 +110,7 @@ pub mod system_parachain { frame_support::match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINE_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) } }; } } diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index 0dbbf6e2f022..ab9e4cefaeff 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -128,7 +128,7 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const Statemine: MultiLocation = Parachain(STATEMINE_ID).into_location(); + pub const Statemine: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get()); @@ -364,7 +364,7 @@ parameter_types! { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parachain(STATEMINE_ID).into()); + pub ReachableDest: Option = Some(Parachain(ASSET_HUB_ID).into()); } /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior diff --git a/polkadot/runtime/polkadot/constants/src/lib.rs b/polkadot/runtime/polkadot/constants/src/lib.rs index c86537f7bde5..9c0df0bba39f 100644 --- a/polkadot/runtime/polkadot/constants/src/lib.rs +++ b/polkadot/runtime/polkadot/constants/src/lib.rs @@ -115,8 +115,8 @@ pub mod xcm { pub mod system_parachain { use xcm::latest::prelude::*; - /// Statemint parachain ID. - pub const STATEMINT_ID: u32 = 1000; + /// Network's Asset Hub parachain ID. + pub const ASSET_HUB_ID: u32 = 1000; /// Collectives parachain ID. pub const COLLECTIVES_ID: u32 = 1001; /// BridgeHub parachain ID. @@ -124,7 +124,7 @@ pub mod system_parachain { frame_support::match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(STATEMINT_ID | COLLECTIVES_ID | BRIDGE_HUB_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | COLLECTIVES_ID | BRIDGE_HUB_ID)) } }; } } diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 2dc775ca0e25..bda05db149a2 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -103,8 +103,8 @@ pub mod fee { pub mod system_parachain { use xcm::latest::prelude::*; - /// Rockmine parachain ID. - pub const ROCKMINE_ID: u32 = 1000; + /// Network's Asset Hub parachain ID. + pub const ASSET_HUB_ID: u32 = 1000; /// Contracts parachain ID. pub const CONTRACTS_ID: u32 = 1002; /// Encointer parachain ID. @@ -114,7 +114,7 @@ pub mod system_parachain { frame_support::match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(ROCKMINE_ID | CONTRACTS_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) } + MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | CONTRACTS_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) } }; } } diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index e1bde352e0e7..4474212f9c2e 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -108,7 +108,7 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const Rockmine: MultiLocation = Parachain(ROCKMINE_ID).into_location(); + pub const Rockmine: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); pub const Contracts: MultiLocation = Parachain(CONTRACTS_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); @@ -328,7 +328,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parachain(ROCKMINE_ID).into()); + pub ReachableDest: Option = Some(Parachain(ASSET_HUB_ID).into()); } /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index 66da9cfcc1d6..4a5177a4a782 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -100,8 +100,8 @@ pub mod fee { pub mod system_parachain { use xcm::latest::prelude::*; - /// Westmint parachain ID. - pub const WESTMINT_ID: u32 = 1000; + /// Network's Asset Hub parachain ID. + pub const ASSET_HUB_ID: u32 = 1000; /// Collectives parachain ID. pub const COLLECTIVES_ID: u32 = 1001; /// BridgeHub parachain ID. diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index ffab79f0466d..b34434eb4dea 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -90,7 +90,7 @@ pub type XcmRouter = WithUniqueTopic<( )>; parameter_types! { - pub const Westmint: MultiLocation = Parachain(WESTMINT_ID).into_location(); + pub const Westmint: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); pub const Collectives: MultiLocation = Parachain(COLLECTIVES_ID).into_location(); pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); pub const Wnd: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); @@ -103,7 +103,7 @@ parameter_types! { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parachain(WESTMINT_ID).into()); + pub ReachableDest: Option = Some(Parachain(ASSET_HUB_ID).into()); } pub type TrustedTeleporters = ( From 758b977e48a2bddae188e7c9c8d4bf03b4ff7495 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 22 Jun 2023 14:47:40 +0000 Subject: [PATCH 018/116] Rename all asset parachains to AssetHub --- polkadot/runtime/kusama/src/lib.rs | 12 ++++++------ polkadot/runtime/kusama/src/xcm_config.rs | 6 +++--- polkadot/runtime/polkadot/src/lib.rs | 14 ++++++++------ polkadot/runtime/polkadot/src/xcm_config.rs | 8 ++++---- polkadot/runtime/rococo/src/lib.rs | 14 +++++++------- polkadot/runtime/rococo/src/xcm_config.rs | 6 +++--- polkadot/runtime/westend/constants/src/lib.rs | 2 +- polkadot/runtime/westend/src/lib.rs | 12 ++++++------ polkadot/runtime/westend/src/xcm_config.rs | 6 +++--- polkadot/xcm/src/v3/mod.rs | 2 +- polkadot/xcm/xcm-builder/tests/mock/mod.rs | 4 ++-- polkadot/xcm/xcm-builder/tests/scenarios.rs | 12 ++++++------ 12 files changed, 50 insertions(+), 48 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index e9e3fb2d2026..1c4391083c63 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -2342,7 +2342,7 @@ sp_api::impl_runtime_apis! { use frame_benchmarking::baseline::Pallet as Baseline; use xcm::latest::prelude::*; use xcm_config::{ - LocalCheckAccount, SovereignAccountOf, Statemine, TokenLocation, XcmConfig, + AssetHub, LocalCheckAccount, SovereignAccountOf, TokenLocation, XcmConfig, }; impl pallet_session_benchmarking::Config for Runtime {} @@ -2357,7 +2357,7 @@ sp_api::impl_runtime_apis! { type XcmConfig = XcmConfig; type AccountIdConverter = SovereignAccountOf; fn valid_destination() -> Result { - Ok(Statemine::get()) + Ok(AssetHub::get()) } fn worst_case_holding(_depositable_count: u32) -> MultiAssets { // Kusama only knows about KSM. @@ -2370,7 +2370,7 @@ sp_api::impl_runtime_apis! { parameter_types! { pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( - Statemine::get(), + AssetHub::get(), MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; @@ -2409,15 +2409,15 @@ sp_api::impl_runtime_apis! { } fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { - Ok((Statemine::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) } fn subscribe_origin() -> Result { - Ok(Statemine::get()) + Ok(AssetHub::get()) } fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { - let origin = Statemine::get(); + let origin = AssetHub::get(); let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into(); let ticket = MultiLocation { parents: 0, interior: Here }; Ok((origin, ticket, assets)) diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index ab9e4cefaeff..f3d8833220ce 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -128,16 +128,16 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const Statemine: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); + pub const AssetHub: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); - pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get()); + pub const KsmForAssetHub: (MultiAssetFilter, MultiLocation) = (Ksm::get(), AssetHub::get()); pub const KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Encointer::get()); pub const KsmForBridgeHub: (MultiAssetFilter, MultiLocation) = (Ksm::get(), BridgeHub::get()); pub const MaxAssetsIntoHolding: u32 = 64; } pub type TrustedTeleporters = ( - xcm_builder::Case, + xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, ); diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index c4458076cb3d..4f6333ad8206 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -2088,7 +2088,9 @@ sp_api::impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use frame_benchmarking::baseline::Pallet as Baseline; use xcm::latest::prelude::*; - use xcm_config::{XcmConfig, StatemintLocation, TokenLocation, LocalCheckAccount, SovereignAccountOf}; + use xcm_config::{ + AssetHubLocation, TokenLocation, LocalCheckAccount, SovereignAccountOf, XcmConfig, + }; impl pallet_session_benchmarking::Config for Runtime {} impl pallet_offences_benchmarking::Config for Runtime {} @@ -2106,7 +2108,7 @@ sp_api::impl_runtime_apis! { type XcmConfig = XcmConfig; type AccountIdConverter = SovereignAccountOf; fn valid_destination() -> Result { - Ok(StatemintLocation::get()) + Ok(AssetHubLocation::get()) } fn worst_case_holding(_depositable_count: u32) -> MultiAssets { // Polkadot only knows about DOT @@ -2116,7 +2118,7 @@ sp_api::impl_runtime_apis! { parameter_types! { pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( - StatemintLocation::get(), + AssetHubLocation::get(), MultiAsset { id: Concrete(TokenLocation::get()), fun: Fungible(1 * UNITS) } )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; @@ -2155,15 +2157,15 @@ sp_api::impl_runtime_apis! { } fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { - Ok((StatemintLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + Ok((AssetHubLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) } fn subscribe_origin() -> Result { - Ok(StatemintLocation::get()) + Ok(AssetHubLocation::get()) } fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { - let origin = StatemintLocation::get(); + let origin = AssetHubLocation::get(); let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into(); let ticket = MultiLocation { parents: 0, interior: Here }; Ok((origin, ticket, assets)) diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs index c7808cb7f6d8..56d406546d38 100644 --- a/polkadot/runtime/polkadot/src/xcm_config.rs +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -133,17 +133,17 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Dot: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const StatemintLocation: MultiLocation = Parachain(STATEMINT_ID).into_location(); - pub const DotForStatemint: (MultiAssetFilter, MultiLocation) = (Dot::get(), StatemintLocation::get()); + pub const AssetHubLocation: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); + pub const DotForAssetHub: (MultiAssetFilter, MultiLocation) = (Dot::get(), AssetHubLocation::get()); pub const CollectivesLocation: MultiLocation = Parachain(COLLECTIVES_ID).into_location(); pub const DotForCollectives: (MultiAssetFilter, MultiLocation) = (Dot::get(), CollectivesLocation::get()); pub const DotForBridgeHub: (MultiAssetFilter, MultiLocation) = (Dot::get(), Parachain(BRIDGE_HUB_ID).into_location()); pub const MaxAssetsIntoHolding: u32 = 64; } -/// Polkadot Relay recognizes/respects the Statemint chain as a teleporter. +/// Polkadot Relay recognizes/respects the Asset Hub chain as a teleporter. pub type TrustedTeleporters = ( - xcm_builder::Case, + xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, ); diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index df5c27b77c26..80b0272e7b14 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2120,7 +2120,7 @@ sp_api::impl_runtime_apis! { use sp_storage::TrackedStorageKey; use xcm::latest::prelude::*; use xcm_config::{ - LocalCheckAccount, LocationConverter, Rockmine, TokenLocation, XcmConfig, + AssetHub, LocalCheckAccount, LocationConverter, TokenLocation, XcmConfig, }; impl frame_system_benchmarking::Config for Runtime {} @@ -2129,7 +2129,7 @@ sp_api::impl_runtime_apis! { type XcmConfig = XcmConfig; type AccountIdConverter = LocationConverter; fn valid_destination() -> Result { - Ok(Rockmine::get()) + Ok(AssetHub::get()) } fn worst_case_holding(_depositable_count: u32) -> MultiAssets { // Rococo only knows about ROC @@ -2142,11 +2142,11 @@ sp_api::impl_runtime_apis! { parameter_types! { pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( - Rockmine::get(), + AssetHub::get(), MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(( - Rockmine::get(), + AssetHub::get(), MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, )); } @@ -2184,15 +2184,15 @@ sp_api::impl_runtime_apis! { } fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { - Ok((Rockmine::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) } fn subscribe_origin() -> Result { - Ok(Rockmine::get()) + Ok(AssetHub::get()) } fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { - let origin = Rockmine::get(); + let origin = AssetHub::get(); let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into(); let ticket = MultiLocation { parents: 0, interior: Here }; Ok((origin, ticket, assets)) diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 4474212f9c2e..6c7ac80d729d 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -108,7 +108,7 @@ pub type XcmRouter = WithUniqueTopic<( parameter_types! { pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const Rockmine: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); + pub const AssetHub: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); pub const Contracts: MultiLocation = Parachain(CONTRACTS_ID).into_location(); pub const Encointer: MultiLocation = Parachain(ENCOINTER_ID).into_location(); pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); @@ -118,7 +118,7 @@ parameter_types! { pub const RocForTick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Tick::get()); pub const RocForTrick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Trick::get()); pub const RocForTrack: (MultiAssetFilter, MultiLocation) = (Roc::get(), Track::get()); - pub const RocForRockmine: (MultiAssetFilter, MultiLocation) = (Roc::get(), Rockmine::get()); + pub const RocForAssetHub: (MultiAssetFilter, MultiLocation) = (Roc::get(), AssetHub::get()); pub const RocForContracts: (MultiAssetFilter, MultiLocation) = (Roc::get(), Contracts::get()); pub const RocForEncointer: (MultiAssetFilter, MultiLocation) = (Roc::get(), Encointer::get()); pub const RocForBridgeHub: (MultiAssetFilter, MultiLocation) = (Roc::get(), BridgeHub::get()); @@ -129,7 +129,7 @@ pub type TrustedTeleporters = ( xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, - xcm_builder::Case, + xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index 4a5177a4a782..0e235be67827 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -109,7 +109,7 @@ pub mod system_parachain { frame_support::match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(WESTMINT_ID | COLLECTIVES_ID | BRIDGE_HUB_ID ))} + MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | COLLECTIVES_ID | BRIDGE_HUB_ID ))} } } } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9ae30c376010..ac1fa0b1ff27 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2027,13 +2027,13 @@ sp_api::impl_runtime_apis! { AssetId::*, Fungibility::*, InteriorMultiLocation, Junction, Junctions::*, MultiAsset, MultiAssets, MultiLocation, NetworkId, Response, }; - use xcm_config::{Westmint, TokenLocation}; + use xcm_config::{AssetHub, TokenLocation}; impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationConverter; fn valid_destination() -> Result { - Ok(Westmint::get()) + Ok(AssetHub::get()) } fn worst_case_holding(_depositable_count: u32) -> MultiAssets { // Westend only knows about WND. @@ -2046,7 +2046,7 @@ sp_api::impl_runtime_apis! { parameter_types! { pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( - Westmint::get(), + AssetHub::get(), MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; @@ -2085,15 +2085,15 @@ sp_api::impl_runtime_apis! { } fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { - Ok((Westmint::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) } fn subscribe_origin() -> Result { - Ok(Westmint::get()) + Ok(AssetHub::get()) } fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { - let origin = Westmint::get(); + let origin = AssetHub::get(); let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into(); let ticket = MultiLocation { parents: 0, interior: Here }; Ok((origin, ticket, assets)) diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index b34434eb4dea..06490a3e9edf 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -90,11 +90,11 @@ pub type XcmRouter = WithUniqueTopic<( )>; parameter_types! { - pub const Westmint: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); + pub const AssetHub: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); pub const Collectives: MultiLocation = Parachain(COLLECTIVES_ID).into_location(); pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location(); pub const Wnd: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); - pub const WndForWestmint: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Westmint::get()); + pub const WndForAssetHub: (MultiAssetFilter, MultiLocation) = (Wnd::get(), AssetHub::get()); pub const WndForCollectives: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Collectives::get()); pub const WndForBridgeHub: (MultiAssetFilter, MultiLocation) = (Wnd::get(), BridgeHub::get()); pub const MaxInstructions: u32 = 100; @@ -107,7 +107,7 @@ parameter_types! { } pub type TrustedTeleporters = ( - xcm_builder::Case, + xcm_builder::Case, xcm_builder::Case, xcm_builder::Case, ); diff --git a/polkadot/xcm/src/v3/mod.rs b/polkadot/xcm/src/v3/mod.rs index 360867957862..f13814cfa274 100644 --- a/polkadot/xcm/src/v3/mod.rs +++ b/polkadot/xcm/src/v3/mod.rs @@ -906,7 +906,7 @@ pub enum Instruction { /// should be sent on arrival. /// - `xcm`: The message to be exported. /// - /// As an example, to export a message for execution on Statemine (parachain #1000 in the + /// As an example, to export a message for execution on Asset Hub (parachain #1000 in the /// Kusama network), you would call with `network: NetworkId::Kusama` and /// `destination: X1(Parachain(1000))`. Alternatively, to export a message for execution on /// Polkadot, you would call with `network: NetworkId:: Polkadot` and `destination: Here`. diff --git a/polkadot/xcm/xcm-builder/tests/mock/mod.rs b/polkadot/xcm/xcm-builder/tests/mock/mod.rs index f799be7e4013..e9dba46bacd1 100644 --- a/polkadot/xcm/xcm-builder/tests/mock/mod.rs +++ b/polkadot/xcm/xcm-builder/tests/mock/mod.rs @@ -169,13 +169,13 @@ pub type Barrier = ( ); parameter_types! { - pub KusamaForStatemine: (MultiAssetFilter, MultiLocation) = + pub KusamaForAssetHub: (MultiAssetFilter, MultiLocation) = (Wild(AllOf { id: Concrete(Here.into()), fun: WildFungible }), Parachain(1000).into()); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 4; } -pub type TrustedTeleporters = (xcm_builder::Case,); +pub type TrustedTeleporters = (xcm_builder::Case,); pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { diff --git a/polkadot/xcm/xcm-builder/tests/scenarios.rs b/polkadot/xcm/xcm-builder/tests/scenarios.rs index 3e735720aa76..39af27f3ea59 100644 --- a/polkadot/xcm/xcm-builder/tests/scenarios.rs +++ b/polkadot/xcm/xcm-builder/tests/scenarios.rs @@ -174,7 +174,7 @@ fn report_holding_works() { } /// Scenario: -/// A parachain wants to move KSM from Kusama to Statemine. +/// A parachain wants to move KSM from Kusama to Asset. /// The parachain sends an XCM to withdraw funds combined with a teleport to the destination. /// /// This way of moving funds from a relay to a parachain will only work for trusted chains. @@ -182,12 +182,12 @@ fn report_holding_works() { /// /// Asserts that the balances are updated accordingly and the correct XCM is sent. #[test] -fn teleport_to_statemine_works() { +fn teleport_to_asset_hub_works() { use xcm::opaque::latest::prelude::*; let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating(); let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; kusama_like_with_balances(balances).execute_with(|| { - let statemine_id = 1000; + let asset_hub_id = 1000; let other_para_id = 3000; let amount = REGISTER_AMOUNT; let teleport_effects = vec![ @@ -222,13 +222,13 @@ fn teleport_to_statemine_works() { vec![(Parachain(other_para_id).into(), expected_msg, expected_hash,)] ); - // teleports are allowed from statemine to kusama. + // teleports are allowed from asset hub to kusama. let message = Xcm(vec![ WithdrawAsset((Here, amount).into()), buy_execution(), InitiateTeleport { assets: All.into(), - dest: Parachain(statemine_id).into(), + dest: Parachain(asset_hub_id).into(), xcm: Xcm(teleport_effects.clone()), }, ]); @@ -246,7 +246,7 @@ fn teleport_to_statemine_works() { mock::sent_xcm(), vec![ (Parachain(other_para_id).into(), expected_msg.clone(), expected_hash,), - (Parachain(statemine_id).into(), expected_msg, expected_hash,) + (Parachain(asset_hub_id).into(), expected_msg, expected_hash,) ] ); }); From 3a9bcb89ba873c1ded13027030eec3cb382c30e0 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 28 Aug 2023 14:19:05 -0700 Subject: [PATCH 019/116] Fixes --- .../xcm-executor/src/traits/transact_asset.rs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs index 34cdb0c71413..e412b15d214a 100644 --- a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs +++ b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs @@ -87,7 +87,11 @@ pub trait TransactAsset { /// Deposit the `what` asset into the account of `who`. /// /// Implementations should return `XcmError::FailedToTransactAsset` if deposit failed. - fn deposit_asset(_what: &MultiAsset, _who: &MultiLocation, _context: &XcmContext) -> XcmResult { + fn deposit_asset( + _what: &MultiAsset, + _who: &MultiLocation, + _context: Option<&XcmContext>, + ) -> XcmResult { Err(XcmError::Unimplemented) } @@ -139,7 +143,7 @@ pub trait TransactAsset { Err(XcmError::AssetNotFound | XcmError::Unimplemented) => { let assets = Self::withdraw_asset(asset, from, Some(context))?; // Not a very forgiving attitude; once we implement roll-backs then it'll be nicer. - Self::deposit_asset(asset, to, context)?; + Self::deposit_asset(asset, to, Some(context))?; Ok(assets) }, result => result, @@ -195,7 +199,7 @@ impl TransactAsset for Tuple { )* ); } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult { + fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: Option<&XcmContext>) -> XcmResult { for_tuples!( #( match Tuple::deposit_asset(what, who, context) { Err(XcmError::AssetNotFound) | Err(XcmError::Unimplemented) => (), @@ -286,7 +290,7 @@ mod tests { fn deposit_asset( _what: &MultiAsset, _who: &MultiLocation, - _context: &XcmContext, + _context: Option<&XcmContext>, ) -> XcmResult { Err(XcmError::AssetNotFound) } @@ -330,7 +334,7 @@ mod tests { fn deposit_asset( _what: &MultiAsset, _who: &MultiLocation, - _context: &XcmContext, + _context: Option<&XcmContext>, ) -> XcmResult { Err(XcmError::Overflow) } @@ -374,7 +378,7 @@ mod tests { fn deposit_asset( _what: &MultiAsset, _who: &MultiLocation, - _context: &XcmContext, + _context: Option<&XcmContext>, ) -> XcmResult { Ok(()) } @@ -406,7 +410,7 @@ mod tests { MultiTransactor::deposit_asset( &(Here, 1u128).into(), &Here.into(), - &XcmContext::with_message_id([0; 32]), + Some(&XcmContext::with_message_id([0; 32])), ), Err(XcmError::AssetNotFound) ); @@ -420,7 +424,7 @@ mod tests { MultiTransactor::deposit_asset( &(Here, 1u128).into(), &Here.into(), - &XcmContext::with_message_id([0; 32]), + Some(&XcmContext::with_message_id([0; 32])), ), Ok(()) ); @@ -434,7 +438,7 @@ mod tests { MultiTransactor::deposit_asset( &(Here, 1u128).into(), &Here.into(), - &XcmContext::with_message_id([0; 32]), + Some(&XcmContext::with_message_id([0; 32])), ), Err(XcmError::Overflow) ); @@ -448,7 +452,7 @@ mod tests { MultiTransactor::deposit_asset( &(Here, 1u128).into(), &Here.into(), - &XcmContext::with_message_id([0; 32]), + Some(&XcmContext::with_message_id([0; 32])), ), Ok(()), ); From 298ab71d8d097b428f98716d1197eaaa4cc13ed6 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Wed, 5 Apr 2023 15:13:35 +0100 Subject: [PATCH 020/116] Send xcm fees to local treaury --- cumulus/parachains/common/src/lib.rs | 8 ++++++- .../assets/asset-hub-kusama/src/xcm_config.rs | 20 ++++++++++++++--- .../asset-hub-polkadot/src/xcm_config.rs | 22 +++++++++++++++---- .../asset-hub-westend/src/xcm_config.rs | 22 +++++++++++++++---- .../bridge-hub-kusama/src/xcm_config.rs | 20 +++++++++++++++-- .../bridge-hub-polkadot/src/xcm_config.rs | 20 +++++++++++++++-- .../bridge-hub-rococo/src/xcm_config.rs | 21 +++++++++++++++--- cumulus/primitives/utility/src/lib.rs | 2 +- 8 files changed, 115 insertions(+), 20 deletions(-) diff --git a/cumulus/parachains/common/src/lib.rs b/cumulus/parachains/common/src/lib.rs index 0a9686bf8a37..fdb7ac84ed52 100644 --- a/cumulus/parachains/common/src/lib.rs +++ b/cumulus/parachains/common/src/lib.rs @@ -68,7 +68,10 @@ mod types { /// Common constants of parachains. mod constants { use super::types::BlockNumber; - use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}; + use frame_support::{ + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + PalletId, + }; use sp_runtime::Perbill; /// This determines the average expected block time that we are targeting. Blocks will be /// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by @@ -96,6 +99,9 @@ mod constants { WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), polkadot_primitives::MAX_POV_SIZE as u64, ); + + /// Treasury pallet id of the local chain, used to convert into AccountId + pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry"); } /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 25d47b55977c..59f47bceb567 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -31,9 +31,13 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{impls::ToStakingPot, xcm_config::AssetFeeAsExistentialDepositMultiplier}; +use parachains_common::{ + impls::ToStakingPot, + xcm_config::AssetFeeAsExistentialDepositMultiplier, + TREASURY_PALLET_ID, +}; use polkadot_parachain::primitives::Sibling; -use sp_runtime::traits::ConvertInto; +use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -66,6 +70,7 @@ parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); pub const FellowshipLocation: MultiLocation = MultiLocation::parent(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -470,6 +475,15 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; +match_types! { + pub type RelayOrSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + kusama_runtime_constants::system_parachain::ENCOINTER_ID | + kusama_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -516,7 +530,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index 3e40afb83f9c..98fa1bd7f23a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -27,9 +27,13 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{impls::ToStakingPot, xcm_config::AssetFeeAsExistentialDepositMultiplier}; +use parachains_common::{ + impls::ToStakingPot, + xcm_config::AssetFeeAsExistentialDepositMultiplier, + TREASURY_PALLET_ID, +}; use polkadot_parachain::primitives::Sibling; -use sp_runtime::traits::ConvertInto; +use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -39,7 +43,7 @@ use xcm_builder::{ NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -55,6 +59,7 @@ parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(1001)); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -390,6 +395,15 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; +match_types! { + pub type RelayOrSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + polkadot_runtime_constants::system_parachain::COLLECTIVES_ID) | + polkadot_runtime_constants::system_parachain::BRIDGE_HUB_ID) } | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -436,7 +450,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index e0af76d6d002..768c6c01ccb4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -31,9 +31,13 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{impls::ToStakingPot, xcm_config::AssetFeeAsExistentialDepositMultiplier}; +use parachains_common::{ + impls::ToStakingPot, + xcm_config::AssetFeeAsExistentialDepositMultiplier, + TREASURY_PALLET_ID, +}; use polkadot_parachain::primitives::Sibling; -use sp_runtime::traits::ConvertInto; +use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -42,7 +46,7 @@ use xcm_builder::{ LocalMint, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -63,6 +67,7 @@ parameter_types! { pub PoolAssetsPalletLocation: MultiLocation = PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -473,6 +478,15 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; +match_types! { + pub type RelayOrSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + westend_runtime_constants::system_parachain::COLLECTIVES_ID | + westend_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -519,7 +533,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 1fcec7b6b9c5..82ac0f800147 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -24,8 +24,13 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; +use parachains_common::{ + impls::ToStakingPot, + xcm_config::ConcreteNativeAssetFrom, + TREASURY_PALLET_ID, +}; use polkadot_parachain::primitives::Sibling; +use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -34,6 +39,7 @@ use xcm_builder::{ ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -47,6 +53,7 @@ parameter_types! { pub const MaxAssetsIntoHolding: u32 = 64; pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); pub const FellowshipLocation: MultiLocation = MultiLocation::parent(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -177,6 +184,15 @@ pub type Barrier = TrailingSetTopicAsId< >, >; +match_types! { + pub type RelayOrSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + kusama_runtime_constants::system_parachain::STATEMINE_ID | + kusama_runtime_constants::system_parachain::ENCOINTER_ID)) } | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -205,7 +221,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 0b5831f028b0..67d7b93e80ab 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -24,8 +24,13 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; +use parachains_common::{ + impls::ToStakingPot, + xcm_config::ConcreteNativeAssetFrom, + TREASURY_PALLET_ID, +}; use polkadot_parachain::primitives::Sibling; +use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -34,6 +39,7 @@ use xcm_builder::{ ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -47,6 +53,7 @@ parameter_types! { pub const MaxAssetsIntoHolding: u32 = 64; pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(1001)); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -181,6 +188,15 @@ pub type Barrier = TrailingSetTopicAsId< >, >; +match_types! { + pub type RelayOrSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + polkadot_runtime_constants::system_parachain::ASSET_HUB_ID | + polkadot_runtime_constants::system_parachain::COLLECTIVES_ID)) } | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -209,7 +225,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 170382fe5834..41b4106a0dc8 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -30,9 +30,14 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; +use parachains_common::{ + impls::ToStakingPot, + xcm_config::ConcreteNativeAssetFrom, + TREASURY_PALLET_ID, +}; use polkadot_parachain::primitives::Sibling; use sp_core::Get; +use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -41,7 +46,7 @@ use xcm_builder::{ ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::{ traits::{ExportXcm, WithOriginFilter}, @@ -55,6 +60,7 @@ parameter_types! { X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } pub struct RelayNetwork; @@ -224,6 +230,15 @@ pub type Barrier = TrailingSetTopicAsId< >, >; +match_types! { + pub type RelayOrSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(rococo_runtime_constants::system_parachain::STATEMINE_ID | + rococo_runtime_constants::system_parachain::ENCOINTER_ID | + rococo_runtime_constants::system_parachain::CONTRACTS_ID)) } | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -252,7 +267,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = PolkadotXcm; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = BridgeHubRococoOrBridgeHubWococoSwitchExporter; type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/primitives/utility/src/lib.rs b/cumulus/primitives/utility/src/lib.rs index 87be029163d6..9d6f86c4cfe8 100644 --- a/cumulus/primitives/utility/src/lib.rs +++ b/cumulus/primitives/utility/src/lib.rs @@ -290,7 +290,7 @@ impl< &(X1(AccountId32 { network: None, id: receiver.into() }).into()), // We aren't able to track the XCM that initiated the fee deposit, so we create a // fake message hash here - &XcmContext::with_message_id([0; 32]), + None, ) .is_ok(); From 13f957730364a0c9274fdf4b8b7bc9e76c8cbbf0 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Wed, 5 Apr 2023 15:41:14 +0100 Subject: [PATCH 021/116] should not include self (talking to yourself is the first sign of madness) --- .../runtimes/assets/asset-hub-kusama/src/xcm_config.rs | 5 +++-- .../runtimes/assets/asset-hub-polkadot/src/xcm_config.rs | 5 +++-- .../runtimes/assets/asset-hub-westend/src/xcm_config.rs | 5 +++-- .../bridge-hubs/bridge-hub-kusama/src/xcm_config.rs | 5 +++-- .../bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs | 5 +++-- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 8 +++++--- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 59f47bceb567..682f9e74dbca 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -476,7 +476,7 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia >; match_types! { - pub type RelayOrSystemParachains: impl Contains = { + pub type RelayOrOtherSystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain( kusama_runtime_constants::system_parachain::ENCOINTER_ID | kusama_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | @@ -530,7 +530,8 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index 98fa1bd7f23a..7d53a814b885 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -396,7 +396,7 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia >; match_types! { - pub type RelayOrSystemParachains: impl Contains = { + pub type RelayOrOtherSystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain( polkadot_runtime_constants::system_parachain::COLLECTIVES_ID) | polkadot_runtime_constants::system_parachain::BRIDGE_HUB_ID) } | @@ -450,7 +450,8 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 768c6c01ccb4..777b2126cecf 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -479,7 +479,7 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia >; match_types! { - pub type RelayOrSystemParachains: impl Contains = { + pub type RelayOrOtherSystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain( westend_runtime_constants::system_parachain::COLLECTIVES_ID | westend_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | @@ -533,7 +533,8 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 82ac0f800147..0b4864b66006 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -185,7 +185,7 @@ pub type Barrier = TrailingSetTopicAsId< >; match_types! { - pub type RelayOrSystemParachains: impl Contains = { + pub type RelayOrOtherSystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain( kusama_runtime_constants::system_parachain::STATEMINE_ID | kusama_runtime_constants::system_parachain::ENCOINTER_ID)) } | @@ -221,7 +221,8 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 67d7b93e80ab..171e213a4ad5 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -189,7 +189,7 @@ pub type Barrier = TrailingSetTopicAsId< >; match_types! { - pub type RelayOrSystemParachains: impl Contains = { + pub type RelayOrOtherSystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain( polkadot_runtime_constants::system_parachain::ASSET_HUB_ID | polkadot_runtime_constants::system_parachain::COLLECTIVES_ID)) } | @@ -225,7 +225,8 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 41b4106a0dc8..bdafe58ef85e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -231,8 +231,9 @@ pub type Barrier = TrailingSetTopicAsId< >; match_types! { - pub type RelayOrSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(rococo_runtime_constants::system_parachain::STATEMINE_ID | + pub type RelayOrOtherSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + rococo_runtime_constants::system_parachain::ASSET_HUB_ID | rococo_runtime_constants::system_parachain::ENCOINTER_ID | rococo_runtime_constants::system_parachain::CONTRACTS_ID)) } | MultiLocation { parents: 1, interior: Here } @@ -267,7 +268,8 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = PolkadotXcm; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; type MessageExporter = BridgeHubRococoOrBridgeHubWococoSwitchExporter; type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; From 898645c5fd619eb53027bf36375afeb30b9497b2 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Wed, 5 Apr 2023 16:16:38 +0100 Subject: [PATCH 022/116] Add collectives and contracts. Contracts rococo was importing kusama constants rather than rococo constants. Have corrected this. --- Cargo.lock | 2 +- .../collectives-polkadot/src/xcm_config.rs | 24 ++++++++++++++++--- .../contracts/contracts-rococo/Cargo.toml | 18 +++++++------- .../contracts-rococo/src/constants.rs | 2 +- .../contracts-rococo/src/xcm_config.rs | 19 ++++++++++++--- 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f271fce87596..19a61e6d95b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2843,7 +2843,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal 0.4.1", - "kusama-runtime-constants", "log", "pallet-aura", "pallet-authorship", @@ -2866,6 +2865,7 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain", "polkadot-runtime-common", + "rococo-runtime-constants", "scale-info", "smallvec", "sp-api", diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index e9b5c1b165a8..279c0d3e1f55 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -24,8 +24,13 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; +use parachains_common::{ + impls::ToStakingPot, + xcm_config::ConcreteNativeAssetFrom, + TREASURY_PALLET_ID, +}; use polkadot_parachain::primitives::Sibling; +use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -34,7 +39,7 @@ use xcm_builder::{ OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, WithUniqueTopic, + UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -46,6 +51,8 @@ parameter_types! { X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); + } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -227,6 +234,16 @@ pub type Barrier = TrailingSetTopicAsId< >, >; +match_types! { + pub type RelayOrOtherSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + polkadot_runtime_constants::system_parachain::ASSET_HUB_ID | + polkadot_runtime_constants::system_parachain::BRIDGE_HUB_ID + ))} | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -251,7 +268,8 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = (); + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml b/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml index 67885ded6075..bd41f845bb65 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml @@ -52,14 +52,14 @@ pallet-contracts = { path = "../../../../../substrate/frame/contracts", default- pallet-contracts-primitives = { path = "../../../../../substrate/frame/contracts/primitives", default-features = false} # Polkadot -kusama-runtime-constants = { path = "../../../../../polkadot/runtime/kusama/constants", default-features = false} -pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false} -polkadot-core-primitives = { path = "../../../../../polkadot/core-primitives", default-features = false} -polkadot-parachain = { path = "../../../../../polkadot/parachain", default-features = false} -polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false} -xcm = { path = "../../../../../polkadot/xcm", default-features = false} -xcm-builder = { path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} -xcm-executor = { path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} +pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false } +polkadot-core-primitives = { path = "../../../../../polkadot/core-primitives", default-features = false } +polkadot-parachain = { path = "../../../../../polkadot/parachain", default-features = false } +polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } +rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false } +xcm = { path = "../../../../../polkadot/xcm", default-features = false } +xcm-builder = { path = "../../../../../polkadot/xcm/xcm-builder", default-features = false } +xcm-executor = { path = "../../../../../polkadot/xcm/xcm-executor", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -90,7 +90,6 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "frame-try-runtime/std", - "kusama-runtime-constants/std", "log/std", "pallet-aura/std", "pallet-authorship/std", @@ -112,6 +111,7 @@ std = [ "polkadot-core-primitives/std", "polkadot-parachain/std", "polkadot-runtime-common/std", + "rococo-runtime-constants/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/constants.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/constants.rs index db7922ea905b..99b9a9f3845d 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/constants.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/constants.rs @@ -14,8 +14,8 @@ // limitations under the License. pub mod currency { - use kusama_runtime_constants as constants; use polkadot_core_primitives::Balance; + use rococo_runtime_constants as constants; /// The existential deposit. Set to 1/10 of its parent Relay Chain. pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index 3857c07fd03f..548b921b0b42 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -24,7 +24,9 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough}; +use parachains_common::{TREASURY_PALLET_ID}; use polkadot_parachain::primitives::Sibling; +use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -33,7 +35,7 @@ use xcm_builder::{ NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WithComputedOrigin, WithUniqueTopic, + WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::XcmExecutor; @@ -43,7 +45,7 @@ parameter_types! { pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub const ExecutiveBody: BodyId = BodyId::Executive; - pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// We allow root and the Relay Chain council to execute privileged collator selection operations. @@ -144,6 +146,16 @@ pub type Barrier = TrailingSetTopicAsId< >, >; +match_types! { + pub type RelayOrOtherSystemParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain( + rococo_runtime_constants::system_parachain::ASSET_HUB_ID | + rococo_runtime_constants::system_parachain::ENCOINTER_ID | + rococo_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | + MultiLocation { parents: 1, interior: Here } + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -164,7 +176,8 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = ConstU32<8>; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = (); + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; From 53dfe4598d090c7f608f47364efd10987935ba6b Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Fri, 7 Apr 2023 19:35:50 +0100 Subject: [PATCH 023/116] Less error-prone specifying of system parachains --- Cargo.lock | 1 + cumulus/parachains/common/Cargo.toml | 1 + cumulus/parachains/common/src/xcm_config.rs | 24 +++++++++++++++++-- .../assets/asset-hub-kusama/src/xcm_config.rs | 24 ++++++++----------- .../asset-hub-polkadot/src/xcm_config.rs | 20 +++++++--------- .../asset-hub-westend/src/xcm_config.rs | 20 +++++++--------- .../bridge-hub-kusama/src/xcm_config.rs | 20 +++++++--------- .../bridge-hub-polkadot/src/xcm_config.rs | 20 +++++++--------- .../bridge-hub-rococo/src/xcm_config.rs | 21 +++++++--------- .../collectives-polkadot/src/xcm_config.rs | 21 +++++++--------- .../contracts-rococo/src/xcm_config.rs | 21 +++++++--------- cumulus/primitives/utility/src/lib.rs | 2 -- 12 files changed, 90 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19a61e6d95b9..b5393cafb775 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11143,6 +11143,7 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-collator-selection", + "parachain-info", "parity-scale-codec", "polkadot-primitives", "scale-info", diff --git a/cumulus/parachains/common/Cargo.toml b/cumulus/parachains/common/Cargo.toml index 5900ec9f3095..e4b37ff0195b 100644 --- a/cumulus/parachains/common/Cargo.toml +++ b/cumulus/parachains/common/Cargo.toml @@ -37,6 +37,7 @@ xcm-executor = { path = "../../../polkadot/xcm/xcm-executor", default-features = pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false } cumulus-primitives-core = { path = "../../primitives/core", default-features = false } cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false } +parachain-info = { path = "../pallets/parachain-info", default-features = false } [dev-dependencies] pallet-authorship = { path = "../../../substrate/frame/authorship", default-features = false} diff --git a/cumulus/parachains/common/src/xcm_config.rs b/cumulus/parachains/common/src/xcm_config.rs index 99dd0ace0fc5..1bf429ed7ac3 100644 --- a/cumulus/parachains/common/src/xcm_config.rs +++ b/cumulus/parachains/common/src/xcm_config.rs @@ -1,10 +1,9 @@ use crate::impls::AccountIdOf; use core::marker::PhantomData; use frame_support::{ - traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, ContainsPair}, + traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, Contains, ContainsPair}, weights::Weight, }; -use log; use sp_runtime::traits::Get; use xcm::latest::prelude::*; @@ -63,3 +62,24 @@ impl> ContainsPair matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get()) } } + +pub struct RelayOrOtherSystemParachains< + SystemParachainMatcher: Contains, + Runtime: parachain_info::Config, +> { + _runtime: PhantomData<(SystemParachainMatcher, Runtime)>, +} +impl, Runtime: parachain_info::Config> + Contains for RelayOrOtherSystemParachains +{ + fn contains(l: &MultiLocation) -> bool { + let self_para_id: u32 = parachain_info::Pallet::::get().into(); + if let MultiLocation { parents: 0, interior: X1(Parachain(para_id)) } = l { + if *para_id == self_para_id { + return false + } + } + matches!(l, MultiLocation { parents: 1, interior: Here }) || + SystemParachainMatcher::contains(l) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 682f9e74dbca..2416c8e3850e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -30,13 +30,14 @@ use frame_support::{ traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, }; use frame_system::EnsureRoot; +use kusama_parachain::primitives::Sibling; +use kusama_runtime_constants::system_parachain::SystemParachains; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::AssetFeeAsExistentialDepositMultiplier, + xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; -use polkadot_parachain::primitives::Sibling; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ @@ -47,7 +48,7 @@ use xcm_builder::{ NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -475,15 +476,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - kusama_runtime_constants::system_parachain::ENCOINTER_ID | - kusama_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -530,8 +522,12 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOtherOrSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index 7d53a814b885..a1df7051c5b6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -29,10 +29,11 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::AssetFeeAsExistentialDepositMultiplier, + xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; use polkadot_parachain::primitives::Sibling; +use polkadot_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ @@ -395,15 +396,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - polkadot_runtime_constants::system_parachain::COLLECTIVES_ID) | - polkadot_runtime_constants::system_parachain::BRIDGE_HUB_ID) } | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -450,8 +442,12 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOrOtherSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 777b2126cecf..c5b94ee796a9 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -33,11 +33,12 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::AssetFeeAsExistentialDepositMultiplier, + xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; use polkadot_parachain::primitives::Sibling; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use westend_runtime_constants::system_parachain::SystemParachains; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -478,15 +479,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - westend_runtime_constants::system_parachain::COLLECTIVES_ID | - westend_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -533,8 +525,12 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOrOtherSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 0b4864b66006..1583605490cc 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -23,10 +23,11 @@ use frame_support::{ traits::{ConstU32, Contains, Everything, Nothing}, }; use frame_system::EnsureRoot; +use kusama_runtime_constants::system_parachain::SystemParachains; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::ConcreteNativeAssetFrom, + xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; use polkadot_parachain::primitives::Sibling; @@ -184,15 +185,6 @@ pub type Barrier = TrailingSetTopicAsId< >, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - kusama_runtime_constants::system_parachain::STATEMINE_ID | - kusama_runtime_constants::system_parachain::ENCOINTER_ID)) } | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -221,8 +213,12 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOrOtherSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 171e213a4ad5..7dcfcb7ffe98 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -26,10 +26,11 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::ConcreteNativeAssetFrom, + xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; use polkadot_parachain::primitives::Sibling; +use polkadot_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ @@ -188,15 +189,6 @@ pub type Barrier = TrailingSetTopicAsId< >, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - polkadot_runtime_constants::system_parachain::ASSET_HUB_ID | - polkadot_runtime_constants::system_parachain::COLLECTIVES_ID)) } | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -225,8 +217,12 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOrOtherSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index bdafe58ef85e..9cdd9a18ca0c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -32,10 +32,11 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::ConcreteNativeAssetFrom, + xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; use polkadot_parachain::primitives::Sibling; +use rococo_runtime_constants::system_parachain::SystemParachains; use sp_core::Get; use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; @@ -230,16 +231,6 @@ pub type Barrier = TrailingSetTopicAsId< >, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - rococo_runtime_constants::system_parachain::ASSET_HUB_ID | - rococo_runtime_constants::system_parachain::ENCOINTER_ID | - rococo_runtime_constants::system_parachain::CONTRACTS_ID)) } | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -268,8 +259,12 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = PolkadotXcm; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOrOtherSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = BridgeHubRococoOrBridgeHubWococoSwitchExporter; type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 279c0d3e1f55..008591e7d5dd 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -26,10 +26,11 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::ConcreteNativeAssetFrom, + xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; use polkadot_parachain::primitives::Sibling; +use polkadot_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ @@ -234,16 +235,6 @@ pub type Barrier = TrailingSetTopicAsId< >, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - polkadot_runtime_constants::system_parachain::ASSET_HUB_ID | - polkadot_runtime_constants::system_parachain::BRIDGE_HUB_ID - ))} | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -268,8 +259,12 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOrOtherSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index 548b921b0b42..6d1b89d6d7cf 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -24,8 +24,9 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough}; -use parachains_common::{TREASURY_PALLET_ID}; +use parachains_common::{xcm_config::RelayOrOtherSystemParachains, TREASURY_PALLET_ID}; use polkadot_parachain::primitives::Sibling; +use rococo_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ @@ -146,16 +147,6 @@ pub type Barrier = TrailingSetTopicAsId< >, >; -match_types! { - pub type RelayOrOtherSystemParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain( - rococo_runtime_constants::system_parachain::ASSET_HUB_ID | - rococo_runtime_constants::system_parachain::ENCOINTER_ID | - rococo_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } | - MultiLocation { parents: 1, interior: Here } - }; -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -176,8 +167,12 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = ConstU32<8>; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount< + Self, + RelayOrOtherSystemParachains, + AccountId, + TreasuryAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; diff --git a/cumulus/primitives/utility/src/lib.rs b/cumulus/primitives/utility/src/lib.rs index 9d6f86c4cfe8..0623330e3555 100644 --- a/cumulus/primitives/utility/src/lib.rs +++ b/cumulus/primitives/utility/src/lib.rs @@ -288,8 +288,6 @@ impl< let ok = FungiblesMutateAdapter::deposit_asset( &revenue, &(X1(AccountId32 { network: None, id: receiver.into() }).into()), - // We aren't able to track the XCM that initiated the fee deposit, so we create a - // fake message hash here None, ) .is_ok(); From 58ce029c34cc550e8b322d6d06f84166df8eb4d0 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 28 Aug 2023 20:15:33 -0700 Subject: [PATCH 024/116] Typo fix --- polkadot/runtime/westend/constants/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index 0e235be67827..fc29c8495fa6 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -110,7 +110,7 @@ pub mod system_parachain { frame_support::match_types! { pub type SystemParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | COLLECTIVES_ID | BRIDGE_HUB_ID ))} - } + }; } } From 8853c4ac3da4419565aa803a7344eafa8fb23f18 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 28 Aug 2023 20:45:26 -0700 Subject: [PATCH 025/116] Fixes --- .../src/fungible/benchmarking.rs | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs index 504b79540399..9e51fa83de90 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs @@ -44,15 +44,7 @@ benchmarks_instance_pallet! { let worst_case_holding = T::worst_case_holding(0); let asset = T::get_multi_asset(); - >::deposit_asset( - &asset, - &sender_location, - &XcmContext { - origin: Some(sender_location.clone()), - message_id: [0; 32], - topic: None, - }, - ).unwrap(); + >::deposit_asset(&asset, &sender_location, None).unwrap(); // check the assets of origin. assert!(!T::TransactAsset::balance(&sender_account).is_zero()); @@ -77,15 +69,7 @@ benchmarks_instance_pallet! { let dest_location = T::valid_destination()?; let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap(); - >::deposit_asset( - &asset, - &sender_location, - &XcmContext { - origin: Some(sender_location.clone()), - message_id: [0; 32], - topic: None, - }, - ).unwrap(); + >::deposit_asset(&asset, &sender_location, None).unwrap(); assert!(T::TransactAsset::balance(&dest_account).is_zero()); let mut executor = new_executor::(sender_location); @@ -104,15 +88,7 @@ benchmarks_instance_pallet! { let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap(); let asset = T::get_multi_asset(); - >::deposit_asset( - &asset, - &sender_location, - &XcmContext { - origin: Some(sender_location.clone()), - message_id: [0; 32], - topic: None, - }, - ).unwrap(); + >::deposit_asset(&asset, &sender_location, None).unwrap(); let assets: MultiAssets = vec![ asset ].into(); assert!(T::TransactAsset::balance(&dest_account).is_zero()); From bb3607735c7e0b4511817090d1691bb7eff6915a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 7 Aug 2023 14:35:05 +0200 Subject: [PATCH 026/116] Test for `pallet_xcm::reserve_transfer_assets` with paid XcmRouter --- polkadot/xcm/pallet-xcm/src/mock.rs | 57 ++++++++++++++++++--- polkadot/xcm/pallet-xcm/src/tests.rs | 74 ++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 7 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index b56b1af82def..5ca3371b4499 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -16,8 +16,8 @@ use codec::Encode; use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU32, Everything, Nothing}, + construct_runtime, match_types, parameter_types, + traits::{ConstU32, Everything, EverythingBut, Nothing}, weights::Weight, }; use frame_system::EnsureRoot; @@ -25,14 +25,16 @@ use polkadot_parachain::primitives::Id as ParaId; use polkadot_runtime_parachains::origin; use sp_core::H256; use sp_runtime::{traits::IdentityLookup, AccountId32, BuildStorage}; -pub use sp_std::{cell::RefCell, fmt::Debug, marker::PhantomData}; +pub use sp_std::{ + cell::RefCell, collections::btree_map::BTreeMap, fmt::Debug, marker::PhantomData, +}; use xcm::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, Case, ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, + SovereignSignedViaLocation, TakeWeightCredit, XcmFeesToAccount, }; use xcm_executor::XcmExecutor; @@ -143,6 +145,7 @@ construct_runtime!( thread_local! { pub static SENT_XCM: RefCell)>> = RefCell::new(Vec::new()); + pub static XCM_ROUTER_FEES: RefCell> = RefCell::new(BTreeMap::new()); } pub(crate) fn sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> { SENT_XCM.with(|q| (*q.borrow()).clone()) @@ -154,7 +157,24 @@ pub(crate) fn take_sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> { r }) } -/// Sender that never returns error, always sends +pub(crate) fn set_router_fee_for_destination(dest: MultiLocation, fees: Option) { + XCM_ROUTER_FEES.with(|q| { + if let Some(fees) = fees { + q.borrow_mut() + .entry(dest) + .and_modify(|old_value| *old_value = fees.clone()) + .or_insert(fees); + } else { + let _ = q.borrow_mut().remove_entry(&dest); + } + }) +} +pub(crate) fn get_router_fee_for_destination(dest: &MultiLocation) -> Option { + XCM_ROUTER_FEES.with(|q| q.borrow().get(dest).map(Clone::clone)) +} + +/// Sender that never returns error, always sends. +/// By default does not return **fees**, **fees** can be managed per destination with `set_router_fee_for_destination`. pub struct TestSendXcm; impl SendXcm for TestSendXcm { type Ticket = (MultiLocation, Xcm<()>); @@ -163,7 +183,17 @@ impl SendXcm for TestSendXcm { msg: &mut Option>, ) -> SendResult<(MultiLocation, Xcm<()>)> { let pair = (dest.take().unwrap(), msg.take().unwrap()); - Ok((pair, MultiAssets::new())) + + // Check if fees are configured for dest + let maybe_payment = match get_router_fee_for_destination(&pair.0) { + Some(fees) => fees, + None => { + // can be change to None, but this was here before. + MultiAssets::new() + }, + }; + + Ok((pair, maybe_payment)) } fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result { let hash = fake_message_hash(&pair.1); @@ -271,6 +301,14 @@ parameter_types! { pub TrustedAssets: (MultiAssetFilter, MultiLocation) = (All.into(), Here.into()); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + pub XcmFeesTargetAccount: AccountId = AccountId::new([167u8; 32]); +} + +pub const XCM_FEES_NOT_WAIVED_USER_ACCOUNT: [u8; 32] = [37u8; 32]; +match_types! { + pub type XcmFeesNotWaivedLocations: impl Contains = { + MultiLocation { parents: 0, interior: X1(Junction::AccountId32 {network: None, id: XCM_FEES_NOT_WAIVED_USER_ACCOUNT})} + }; } pub type Barrier = ( @@ -300,7 +338,12 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); + type FeeManager = XcmFeesToAccount< + Self, + EverythingBut, + AccountId, + XcmFeesTargetAccount, + >; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index 6ff9f1d893c8..40e2ac272142 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -522,6 +522,80 @@ fn reserve_transfer_assets_works() { }); } +/// Test `reserve_transfer_assets_with_paid_router_works` +/// +/// Asserts that the sender's balance is decreased and the beneficiary's balance +/// is increased. Verifies the correct message is sent and event is emitted. +/// Verifies that XCM router fees (`SendXcm::validate` -> `MultiAssets`) are withdrawn from correct user account +/// and deposited to a correct target account (`XcmFeesTargetAccount`). +#[test] +fn reserve_transfer_assets_with_paid_router_works() { + // set up router fees for destination + let xcm_router_fee_amount = 1; + set_router_fee_for_destination( + Parachain(PARA_ID).into(), + Some(MultiAssets::from((Here, xcm_router_fee_amount))), + ); + + let user_account = AccountId::from(XCM_FEES_NOT_WAIVED_USER_ACCOUNT); + + let balances = vec![ + (user_account.clone(), INITIAL_BALANCE), + (ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE), + (XcmFeesTargetAccount::get(), INITIAL_BALANCE), + ]; + new_test_ext_with_balances(balances).execute_with(|| { + let weight = BaseXcmWeight::get() * 2; + let dest: MultiLocation = + Junction::AccountId32 { network: None, id: user_account.clone().into() }.into(); + assert_eq!(Balances::total_balance(&user_account), INITIAL_BALANCE); + assert_ok!(XcmPallet::reserve_transfer_assets( + RuntimeOrigin::signed(user_account.clone()), + Box::new(Parachain(PARA_ID).into()), + Box::new(dest.clone().into()), + Box::new((Here, SEND_AMOUNT).into()), + 0, + )); + // check event + assert_eq!( + last_event(), + RuntimeEvent::XcmPallet(crate::Event::Attempted { outcome: Outcome::Complete(weight) }) + ); + + // XCM_FEES_NOT_WAIVED_USER_ACCOUNT spent amount + assert_eq!( + Balances::free_balance(user_account), + INITIAL_BALANCE - SEND_AMOUNT - xcm_router_fee_amount + ); + // Destination account (parachain account) has amount + let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating(); + assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT); + // XcmFeesTargetAccount where should lend xcm_router_fee_amount + assert_eq!( + Balances::free_balance(XcmFeesTargetAccount::get()), + INITIAL_BALANCE + xcm_router_fee_amount + ); + assert_eq!( + sent_xcm(), + vec![( + Parachain(PARA_ID).into(), + Xcm(vec![ + ReserveAssetDeposited((Parent, SEND_AMOUNT).into()), + ClearOrigin, + buy_limited_execution((Parent, SEND_AMOUNT), Weight::from_parts(4000, 4000)), + DepositAsset { assets: AllCounted(1).into(), beneficiary: dest }, + ]), + )] + ); + let versioned_sent = VersionedXcm::from(sent_xcm().into_iter().next().unwrap().1); + let _check_v2_ok: xcm::v2::Xcm<()> = versioned_sent.try_into().unwrap(); + assert_eq!( + last_event(), + RuntimeEvent::XcmPallet(crate::Event::Attempted { outcome: Outcome::Complete(weight) }) + ); + }); +} + /// Test `limited_reserve_transfer_assets` /// /// Asserts that the sender's balance is decreased and the beneficiary's balance From 0681ffdb139cb19ad5138864ce191f89fd6aa6e3 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 7 Aug 2023 14:42:22 +0200 Subject: [PATCH 027/116] Fix another assert --- polkadot/xcm/pallet-xcm/src/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index 40e2ac272142..0c1425c36542 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -580,9 +580,9 @@ fn reserve_transfer_assets_with_paid_router_works() { vec![( Parachain(PARA_ID).into(), Xcm(vec![ - ReserveAssetDeposited((Parent, SEND_AMOUNT).into()), + ReserveAssetDeposited((Parent, SEND_AMOUNT - xcm_router_fee_amount).into()), ClearOrigin, - buy_limited_execution((Parent, SEND_AMOUNT), Weight::from_parts(4000, 4000)), + buy_limited_execution((Parent, SEND_AMOUNT - xcm_router_fee_amount), Weight::from_parts(4000, 4000)), DepositAsset { assets: AllCounted(1).into(), beneficiary: dest }, ]), )] From 58fa19ff4399c1be65421f51d360c6c6ca81d291 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 7 Aug 2023 15:15:17 +0200 Subject: [PATCH 028/116] Potential fix? --- polkadot/xcm/pallet-xcm/src/tests.rs | 4 ++-- polkadot/xcm/xcm-executor/src/lib.rs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index 0c1425c36542..40e2ac272142 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -580,9 +580,9 @@ fn reserve_transfer_assets_with_paid_router_works() { vec![( Parachain(PARA_ID).into(), Xcm(vec![ - ReserveAssetDeposited((Parent, SEND_AMOUNT - xcm_router_fee_amount).into()), + ReserveAssetDeposited((Parent, SEND_AMOUNT).into()), ClearOrigin, - buy_limited_execution((Parent, SEND_AMOUNT - xcm_router_fee_amount), Weight::from_parts(4000, 4000)), + buy_limited_execution((Parent, SEND_AMOUNT), Weight::from_parts(4000, 4000)), DepositAsset { assets: AllCounted(1).into(), beneficiary: dest }, ]), )] diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index bddfe0884dab..e574db830dac 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -406,8 +406,7 @@ impl XcmExecutor { ) -> Result { let (ticket, fee) = validate_send::(dest, msg)?; if !Config::FeeManager::is_waived(self.origin_ref(), reason) { - let paid = self.holding.try_take(fee.into()).map_err(|_| XcmError::NotHoldingFees)?; - Config::FeeManager::handle_fee(paid.into(), Some(&self.context)); + self.take_fee(fee, reason)?; } Config::XcmSender::deliver(ticket).map_err(Into::into) } From e07bc53ff85f809447ab6c67e5d019d9b171a22a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 7 Aug 2023 15:30:14 +0200 Subject: [PATCH 029/116] Even easier --- polkadot/xcm/xcm-executor/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index e574db830dac..347f583c4919 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -405,9 +405,7 @@ impl XcmExecutor { reason: FeeReason, ) -> Result { let (ticket, fee) = validate_send::(dest, msg)?; - if !Config::FeeManager::is_waived(self.origin_ref(), reason) { - self.take_fee(fee, reason)?; - } + self.take_fee(fee, reason)?; Config::XcmSender::deliver(ticket).map_err(Into::into) } From d57a819b13250ce8e04093e617fedb00e4a86768 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 7 Aug 2023 17:33:06 +0200 Subject: [PATCH 030/116] Potential fix for `fn respond(` --- polkadot/xcm/xcm-executor/src/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 347f583c4919..4689b577bd46 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -986,12 +986,7 @@ impl XcmExecutor { let QueryResponseInfo { destination, query_id, max_weight } = info; let instruction = QueryResponse { query_id, response, max_weight, querier }; let message = Xcm(vec![instruction]); - let (ticket, fee) = validate_send::(destination, message)?; - if !Config::FeeManager::is_waived(self.origin_ref(), fee_reason) { - let paid = self.holding.try_take(fee.into()).map_err(|_| XcmError::NotHoldingFees)?; - Config::FeeManager::handle_fee(paid.into(), Some(&self.context)); - } - Config::XcmSender::deliver(ticket).map_err(Into::into) + self.send(destination, message, fee_reason) } fn try_reanchor( From 3027720f7faf930ffec9e9beba1cfc9091138678 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 7 Aug 2023 18:02:34 +0200 Subject: [PATCH 031/116] `set_router_fee_for_destination` inside `new_test_ext` --- polkadot/xcm/pallet-xcm/src/tests.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index 40e2ac272142..9ba851201d4e 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -530,21 +530,20 @@ fn reserve_transfer_assets_works() { /// and deposited to a correct target account (`XcmFeesTargetAccount`). #[test] fn reserve_transfer_assets_with_paid_router_works() { - // set up router fees for destination - let xcm_router_fee_amount = 1; - set_router_fee_for_destination( - Parachain(PARA_ID).into(), - Some(MultiAssets::from((Here, xcm_router_fee_amount))), - ); - let user_account = AccountId::from(XCM_FEES_NOT_WAIVED_USER_ACCOUNT); - let balances = vec![ (user_account.clone(), INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE), (XcmFeesTargetAccount::get(), INITIAL_BALANCE), ]; new_test_ext_with_balances(balances).execute_with(|| { + // set up router fees for destination + let xcm_router_fee_amount = 1; + set_router_fee_for_destination( + Parachain(PARA_ID).into(), + Some(MultiAssets::from((Here, xcm_router_fee_amount))), + ); + let weight = BaseXcmWeight::get() * 2; let dest: MultiLocation = Junction::AccountId32 { network: None, id: user_account.clone().into() }.into(); From 7179f08bb73f98d77523996c22c119c105584f45 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 8 Aug 2023 13:06:33 +0200 Subject: [PATCH 032/116] Added TestPaidForPara3000SendXcm to test --- polkadot/xcm/pallet-xcm/src/mock.rs | 68 +++++++++++++++------------- polkadot/xcm/pallet-xcm/src/tests.rs | 17 +++---- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index 5ca3371b4499..3dd134061517 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -145,7 +145,6 @@ construct_runtime!( thread_local! { pub static SENT_XCM: RefCell)>> = RefCell::new(Vec::new()); - pub static XCM_ROUTER_FEES: RefCell> = RefCell::new(BTreeMap::new()); } pub(crate) fn sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> { SENT_XCM.with(|q| (*q.borrow()).clone()) @@ -157,24 +156,7 @@ pub(crate) fn take_sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> { r }) } -pub(crate) fn set_router_fee_for_destination(dest: MultiLocation, fees: Option) { - XCM_ROUTER_FEES.with(|q| { - if let Some(fees) = fees { - q.borrow_mut() - .entry(dest) - .and_modify(|old_value| *old_value = fees.clone()) - .or_insert(fees); - } else { - let _ = q.borrow_mut().remove_entry(&dest); - } - }) -} -pub(crate) fn get_router_fee_for_destination(dest: &MultiLocation) -> Option { - XCM_ROUTER_FEES.with(|q| q.borrow().get(dest).map(Clone::clone)) -} - -/// Sender that never returns error, always sends. -/// By default does not return **fees**, **fees** can be managed per destination with `set_router_fee_for_destination`. +/// Sender that never returns error. pub struct TestSendXcm; impl SendXcm for TestSendXcm { type Ticket = (MultiLocation, Xcm<()>); @@ -183,17 +165,7 @@ impl SendXcm for TestSendXcm { msg: &mut Option>, ) -> SendResult<(MultiLocation, Xcm<()>)> { let pair = (dest.take().unwrap(), msg.take().unwrap()); - - // Check if fees are configured for dest - let maybe_payment = match get_router_fee_for_destination(&pair.0) { - Some(fees) => fees, - None => { - // can be change to None, but this was here before. - MultiAssets::new() - }, - }; - - Ok((pair, maybe_payment)) + Ok((pair, MultiAssets::new())) } fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result { let hash = fake_message_hash(&pair.1); @@ -223,6 +195,38 @@ impl SendXcm for TestSendXcmErrX8 { } } +parameter_types! { + pub Para3000: u32 = 3000; + pub Para3000Location: MultiLocation = Parachain(Para3000::get()).into(); + pub Para3000PaymentAmount: u128 = 1; + pub Para3000PaymentMultiAssets: MultiAssets = MultiAssets::from(MultiAsset::from((Here, Para3000PaymentAmount::get()))); +} +/// Sender only sends to `Parachain(3000)` destination requiring payment. +pub struct TestPaidForPara3000SendXcm; +impl SendXcm for TestPaidForPara3000SendXcm { + type Ticket = (MultiLocation, Xcm<()>); + fn validate( + dest: &mut Option, + msg: &mut Option>, + ) -> SendResult<(MultiLocation, Xcm<()>)> { + if let Some(dest) = dest.as_ref() { + if !dest.eq(&Para3000Location::get()) { + return Err(SendError::NotApplicable) + } + } else { + return Err(SendError::NotApplicable) + } + + let pair = (dest.take().unwrap(), msg.take().unwrap()); + Ok((pair, Para3000PaymentMultiAssets::get())) + } + fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result { + let hash = fake_message_hash(&pair.1); + SENT_XCM.with(|q| q.borrow_mut().push(pair)); + Ok(hash) + } +} + parameter_types! { pub const BlockHashCount: u64 = 250; } @@ -321,7 +325,7 @@ pub type Barrier = ( pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; - type XcmSender = TestSendXcm; + type XcmSender = (TestPaidForPara3000SendXcm, TestSendXcm); type AssetTransactor = LocalAssetTransactor; type OriginConverter = LocalOriginConverter; type IsReserve = (); @@ -365,7 +369,7 @@ parameter_types! { impl pallet_xcm::Config for Test { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmRouter = (TestSendXcmErrX8, TestSendXcm); + type XcmRouter = (TestSendXcmErrX8, TestPaidForPara3000SendXcm, TestSendXcm); type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; type XcmExecuteFilter = Everything; type XcmExecutor = XcmExecutor; diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index 9ba851201d4e..c80260b49391 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -531,26 +531,21 @@ fn reserve_transfer_assets_works() { #[test] fn reserve_transfer_assets_with_paid_router_works() { let user_account = AccountId::from(XCM_FEES_NOT_WAIVED_USER_ACCOUNT); + let paid_para_id = Para3000::get(); let balances = vec![ (user_account.clone(), INITIAL_BALANCE), - (ParaId::from(PARA_ID).into_account_truncating(), INITIAL_BALANCE), + (ParaId::from(paid_para_id).into_account_truncating(), INITIAL_BALANCE), (XcmFeesTargetAccount::get(), INITIAL_BALANCE), ]; new_test_ext_with_balances(balances).execute_with(|| { - // set up router fees for destination - let xcm_router_fee_amount = 1; - set_router_fee_for_destination( - Parachain(PARA_ID).into(), - Some(MultiAssets::from((Here, xcm_router_fee_amount))), - ); - + let xcm_router_fee_amount = Para3000PaymentAmount::get(); let weight = BaseXcmWeight::get() * 2; let dest: MultiLocation = Junction::AccountId32 { network: None, id: user_account.clone().into() }.into(); assert_eq!(Balances::total_balance(&user_account), INITIAL_BALANCE); assert_ok!(XcmPallet::reserve_transfer_assets( RuntimeOrigin::signed(user_account.clone()), - Box::new(Parachain(PARA_ID).into()), + Box::new(Parachain(paid_para_id).into()), Box::new(dest.clone().into()), Box::new((Here, SEND_AMOUNT).into()), 0, @@ -567,7 +562,7 @@ fn reserve_transfer_assets_with_paid_router_works() { INITIAL_BALANCE - SEND_AMOUNT - xcm_router_fee_amount ); // Destination account (parachain account) has amount - let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating(); + let para_acc: AccountId = ParaId::from(paid_para_id).into_account_truncating(); assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT); // XcmFeesTargetAccount where should lend xcm_router_fee_amount assert_eq!( @@ -577,7 +572,7 @@ fn reserve_transfer_assets_with_paid_router_works() { assert_eq!( sent_xcm(), vec![( - Parachain(PARA_ID).into(), + Parachain(paid_para_id).into(), Xcm(vec![ ReserveAssetDeposited((Parent, SEND_AMOUNT).into()), ClearOrigin, From 9c2636793c13ed4cf71212c0b026347a13644b4a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 8 Aug 2023 16:44:47 +0200 Subject: [PATCH 033/116] TODO: remove dependency of `is_waived` on `runtime-benchmarks` --- polkadot/xcm/xcm-builder/src/fee_handling.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs index 207d58d1fa00..049055471d32 100644 --- a/polkadot/xcm/xcm-builder/src/fee_handling.rs +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -37,16 +37,8 @@ impl< > FeeManager for XcmFeesToAccount { fn is_waived(origin: Option<&MultiLocation>, _: FeeReason) -> bool { - #[cfg(feature = "runtime-benchmarks")] - { - let _ = origin; - true - } - #[cfg(not(feature = "runtime-benchmarks"))] - { - let Some(loc) = origin else { return false }; - WaivedLocations::contains(loc) - } + let Some(loc) = origin else { return false }; + WaivedLocations::contains(loc) } fn handle_fee(fees: MultiAssets, context: Option<&XcmContext>) { From 510ebc718072eca23472bbce394e1fd44c8bd5c4 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 9 Aug 2023 16:06:00 +0200 Subject: [PATCH 034/116] Fixed benchmarks to be `FeeManager/XcmFeesToAccount` aware --- polkadot/runtime/kusama/src/lib.rs | 38 +++++++++++++++++++ polkadot/runtime/kusama/src/xcm_config.rs | 6 ++- polkadot/runtime/polkadot/src/lib.rs | 38 +++++++++++++++++++ polkadot/runtime/polkadot/src/xcm_config.rs | 6 ++- polkadot/runtime/rococo/src/lib.rs | 38 +++++++++++++++++++ polkadot/runtime/rococo/src/xcm_config.rs | 6 ++- polkadot/runtime/westend/src/lib.rs | 6 +++ .../src/fungible/benchmarking.rs | 11 +++++- .../src/fungible/mock.rs | 10 +++++ .../pallet-xcm-benchmarks/src/generic/mock.rs | 9 +++++ polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs | 13 ++++++- polkadot/xcm/xcm-executor/src/lib.rs | 8 ++++ .../xcm-executor/src/traits/fee_manager.rs | 2 +- 13 files changed, 184 insertions(+), 7 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 1c4391083c63..c66f0f7965a1 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -2344,6 +2344,7 @@ sp_api::impl_runtime_apis! { use xcm_config::{ AssetHub, LocalCheckAccount, SovereignAccountOf, TokenLocation, XcmConfig, }; + use xcm_executor::{traits::FeeReason, FeesMode}; impl pallet_session_benchmarking::Config for Runtime {} impl pallet_offences_benchmarking::Config for Runtime {} @@ -2366,6 +2367,43 @@ sp_api::impl_runtime_apis! { fun: Fungible(1_000_000 * UNITS), }].into() } + fn ensure_for_send(origin_ref: &MultiLocation, _dest: &MultiLocation, fee_reason: FeeReason) -> Option { + use xcm_executor::traits::{FeeManager, TransactAsset}; + + let mut fees_mode = None; + if !::FeeManager::is_waived(Some(origin_ref), fee_reason) { + // if not waived, we need to set up accounts for paying and receiving fees + + // mint ED to origin + let ed = MultiAsset { + id: Concrete(TokenLocation::get()), + fun: Fungible(EXISTENTIAL_DEPOSIT.into()) + }; + ::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); + + // overestimate delivery fee + use runtime_common::xcm_sender::PriceForParachainDelivery; + let overestimated_xcm = vec![ClearOrigin; 128].into(); + let overestimated_fees = runtime_common::xcm_sender::ExponentialPrice::< + xcm_config::FeeAssetId, + xcm_config::BaseDeliveryFee, + TransactionByteFee, + Dmp + >::price_for_parachain_delivery( + kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into(), + &overestimated_xcm + ); + + // mint overestimated fee to origin + for fee in overestimated_fees.inner() { + ::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); + } + + // expected worst case + fees_mode = Some(FeesMode { jit_withdraw: true }); + } + fees_mode + } } parameter_types! { diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index f3d8833220ce..16f7ff7037b1 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -146,6 +146,9 @@ match_types! { pub type OnlyParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; + pub type HereLocation: impl Contains = { + MultiLocation { parents: 0, interior: Here } + }; } /// The barriers one of which must be passed for an XCM message to be executed. @@ -346,7 +349,8 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; // No bridges yet... type MessageExporter = (); type UniversalAliases = Nothing; diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 4f6333ad8206..b93862f7eb2a 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -2091,6 +2091,7 @@ sp_api::impl_runtime_apis! { use xcm_config::{ AssetHubLocation, TokenLocation, LocalCheckAccount, SovereignAccountOf, XcmConfig, }; + use xcm_executor::{traits::FeeReason, FeesMode}; impl pallet_session_benchmarking::Config for Runtime {} impl pallet_offences_benchmarking::Config for Runtime {} @@ -2114,6 +2115,43 @@ sp_api::impl_runtime_apis! { // Polkadot only knows about DOT vec![MultiAsset { id: Concrete(TokenLocation::get()), fun: Fungible(1_000_000 * UNITS) }].into() } + fn ensure_for_send(origin_ref: &MultiLocation, _dest: &MultiLocation, fee_reason: FeeReason) -> Option { + use xcm_executor::traits::{FeeManager, TransactAsset}; + + let mut fees_mode = None; + if !::FeeManager::is_waived(Some(origin_ref), fee_reason) { + // if not waived, we need to set up accounts for paying and receiving fees + + // mint ED to origin + let ed = MultiAsset { + id: Concrete(TokenLocation::get()), + fun: Fungible(EXISTENTIAL_DEPOSIT.into()) + }; + ::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); + + // overestimate delivery fee + use runtime_common::xcm_sender::PriceForParachainDelivery; + let overestimated_xcm = vec![ClearOrigin; 128].into(); + let overestimated_fees = runtime_common::xcm_sender::ExponentialPrice::< + xcm_config::FeeAssetId, + xcm_config::BaseDeliveryFee, + TransactionByteFee, + Dmp + >::price_for_parachain_delivery( + polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into(), + &overestimated_xcm + ); + + // mint overestimated fee to origin + for fee in overestimated_fees.inner() { + ::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); + } + + // expected worst case + fees_mode = Some(FeesMode { jit_withdraw: true }); + } + fees_mode + } } parameter_types! { diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs index 56d406546d38..add570e0768a 100644 --- a/polkadot/runtime/polkadot/src/xcm_config.rs +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -156,6 +156,9 @@ match_types! { MultiLocation { parents: 0, interior: X1(Parachain(COLLECTIVES_ID)) } | MultiLocation { parents: 0, interior: X2(Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }) } }; + pub type HereLocation: impl Contains = { + MultiLocation { parents: 0, interior: Here } + }; } /// The barriers one of which must be passed for an XCM message to be executed. @@ -346,7 +349,8 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; // No bridges yet... type MessageExporter = (); type UniversalAliases = Nothing; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 80b0272e7b14..89a4f27bd542 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2122,6 +2122,7 @@ sp_api::impl_runtime_apis! { use xcm_config::{ AssetHub, LocalCheckAccount, LocationConverter, TokenLocation, XcmConfig, }; + use xcm_executor::{traits::FeeReason, FeesMode}; impl frame_system_benchmarking::Config for Runtime {} impl frame_benchmarking::baseline::Config for Runtime {} @@ -2138,6 +2139,43 @@ sp_api::impl_runtime_apis! { fun: Fungible(1_000_000 * UNITS), }].into() } + fn ensure_for_send(origin_ref: &MultiLocation, _dest: &MultiLocation, fee_reason: FeeReason) -> Option { + use xcm_executor::traits::{FeeManager, TransactAsset}; + + let mut fees_mode = None; + if !::FeeManager::is_waived(Some(origin_ref), fee_reason) { + // if not waived, we need to set up accounts for paying and receiving fees + + // mint ED to origin + let ed = MultiAsset { + id: Concrete(TokenLocation::get()), + fun: Fungible(EXISTENTIAL_DEPOSIT.into()) + }; + ::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); + + // overestimate delivery fee + use runtime_common::xcm_sender::PriceForParachainDelivery; + let overestimated_xcm = vec![ClearOrigin; 128].into(); + let overestimated_fees = runtime_common::xcm_sender::ExponentialPrice::< + xcm_config::FeeAssetId, + xcm_config::BaseDeliveryFee, + TransactionByteFee, + Dmp + >::price_for_parachain_delivery( + rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(), + &overestimated_xcm + ); + + // mint overestimated fee to origin + for fee in overestimated_fees.inner() { + ::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); + } + + // expected worst case + fees_mode = Some(FeesMode { jit_withdraw: true }); + } + fees_mode + } } parameter_types! { diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 6c7ac80d729d..4a82946ae934 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -139,6 +139,9 @@ match_types! { pub type OnlyParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; + pub type HereLocation: impl Contains = { + MultiLocation { parents: 0, interior: Here } + }; } /// The barriers one of which must be passed for an XCM message to be executed. @@ -318,7 +321,8 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = XcmFeesToAccount; + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index ac1fa0b1ff27..416a0dc692a1 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2028,6 +2028,8 @@ sp_api::impl_runtime_apis! { MultiAsset, MultiAssets, MultiLocation, NetworkId, Response, }; use xcm_config::{AssetHub, TokenLocation}; + use xcm_executor::FeesMode; + use xcm_executor::traits::FeeReason; impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; @@ -2042,6 +2044,10 @@ sp_api::impl_runtime_apis! { fun: Fungible(1_000_000 * UNITS), }].into() } + fn ensure_for_send(_origin_ref: &MultiLocation, _dest: &MultiLocation, _fee_reason: FeeReason) -> Option { + // doing nothing + None + } } parameter_types! { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs index 9e51fa83de90..3fc6fcf27812 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs @@ -24,7 +24,7 @@ use frame_support::{ use sp_runtime::traits::{Bounded, Zero}; use sp_std::{prelude::*, vec}; use xcm::latest::prelude::*; -use xcm_executor::traits::{ConvertLocation, TransactAsset}; +use xcm_executor::traits::{ConvertLocation, FeeReason, TransactAsset}; benchmarks_instance_pallet! { where_clause { where @@ -87,12 +87,19 @@ benchmarks_instance_pallet! { let dest_location = T::valid_destination()?; let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap(); + let expected_fees_mode = T::ensure_for_send(&sender_location, &dest_location, FeeReason::TransferReserveAsset); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + let asset = T::get_multi_asset(); >::deposit_asset(&asset, &sender_location, None).unwrap(); + assert!(T::TransactAsset::balance(&sender_account) > sender_account_balance_before); let assets: MultiAssets = vec![ asset ].into(); assert!(T::TransactAsset::balance(&dest_account).is_zero()); let mut executor = new_executor::(sender_location); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } let instruction = Instruction::TransferReserveAsset { assets, dest: dest_location, @@ -102,7 +109,7 @@ benchmarks_instance_pallet! { }: { executor.bench_process(xcm)?; } verify { - assert!(T::TransactAsset::balance(&sender_account).is_zero()); + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); assert!(!T::TransactAsset::balance(&dest_account).is_zero()); // TODO: Check sender queue is not empty. #4426 } diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index f5759afc0646..0fa7e56f7614 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -27,6 +27,7 @@ use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; use xcm::latest::prelude::*; use xcm_builder::{AllowUnpaidExecutionFrom, MintLocation}; +use xcm_executor::{traits::FeeReason, FeesMode}; type Block = frame_system::mocking::MockBlock; @@ -169,6 +170,15 @@ impl crate::Config for Test { ::MaxAssetsIntoHolding::get(), ) } + + fn ensure_for_send( + _origin_ref: &MultiLocation, + _dest: &MultiLocation, + _fee_reason: FeeReason, + ) -> Option { + // doing nothing + None + } } pub type TrustedTeleporters = xcm_builder::Case; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 6f9d42df553d..fd3dff051616 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -152,6 +152,15 @@ impl crate::Config for Test { ::MaxAssetsIntoHolding::get(), ) } + + fn ensure_for_send( + _origin_ref: &MultiLocation, + _dest: &MultiLocation, + _fee_reason: FeeReason, + ) -> Option { + // doing nothing + None + } } impl generic::Config for Test { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs index c6a963435953..49ab2d710fb8 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs @@ -22,7 +22,10 @@ use codec::Encode; use frame_benchmarking::{account, BenchmarkError}; use sp_std::prelude::*; use xcm::latest::prelude::*; -use xcm_executor::{traits::ConvertLocation, Config as XcmConfig}; +use xcm_executor::{ + traits::{ConvertLocation, FeeReason}, + Config as XcmConfig, FeesMode, +}; pub mod fungible; pub mod generic; @@ -47,6 +50,14 @@ pub trait Config: frame_system::Config { /// Worst case scenario for a holding account in this runtime. fn worst_case_holding(depositable_count: u32) -> MultiAssets; + + /// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances ...). + /// Returns possible `FeesMode` which is expected to be set to executor. + fn ensure_for_send( + origin_ref: &MultiLocation, + dest: &MultiLocation, + fee_reason: FeeReason, + ) -> Option; } const SEED: u32 = 0; diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 4689b577bd46..e11ec2630e43 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -945,6 +945,14 @@ impl XcmExecutor { if Config::FeeManager::is_waived(self.origin_ref(), reason) { return Ok(()) } + log::trace!( + target: "xcm::fees", + "taking fee: {:?} from origin_ref: {:?} in fees_mode: {:?} for a reason: {:?}", + fee, + self.origin_ref(), + self.fees_mode, + reason, + ); let paid = if self.fees_mode.jit_withdraw { let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?; for asset in fee.inner() { diff --git a/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs b/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs index 588a246ce17f..495f021e7252 100644 --- a/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs +++ b/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs @@ -27,7 +27,7 @@ pub trait FeeManager { } /// Context under which a fee is paid. -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum FeeReason { /// When a reporting instruction is called. Report, From 3d372ba0d49e61745e095c4bf1dbe1de4b70fb19 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Sun, 13 Aug 2023 14:19:48 +0200 Subject: [PATCH 035/116] Extract logic to common place to be reused by different runtimes (relaychains or parachains) --- Cargo.lock | 2 + polkadot/runtime/common/Cargo.toml | 5 ++ polkadot/runtime/common/src/xcm_sender.rs | 90 +++++++++++++++++++ polkadot/runtime/kusama/src/lib.rs | 53 ++++------- polkadot/runtime/kusama/src/xcm_config.rs | 9 +- polkadot/runtime/polkadot/src/lib.rs | 53 ++++------- polkadot/runtime/polkadot/src/xcm_config.rs | 9 +- polkadot/runtime/rococo/src/lib.rs | 53 ++++------- polkadot/runtime/rococo/src/xcm_config.rs | 9 +- polkadot/runtime/westend/src/lib.rs | 7 +- .../src/fungible/benchmarking.rs | 3 +- .../src/fungible/mock.rs | 11 +-- .../pallet-xcm-benchmarks/src/generic/mock.rs | 10 +-- polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs | 34 +++++-- 14 files changed, 185 insertions(+), 163 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b5393cafb775..9a0351fb2c03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12870,6 +12870,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-treasury", "pallet-vesting", + "pallet-xcm-benchmarks", "parity-scale-codec", "polkadot-primitives", "polkadot-primitives-test-helpers", @@ -12893,6 +12894,7 @@ dependencies = [ "sp-std", "static_assertions", "xcm", + "xcm-executor", ] [[package]] diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 72b07765e5e1..461318b300c1 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -50,6 +50,9 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac slot-range-helper = { path = "slot_range_helper", default-features = false } xcm = { path = "../../xcm", default-features = false } +xcm-executor = { path = "../../xcm/xcm-executor", default-features = false, optional = true } + +pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.4.1" @@ -109,7 +112,9 @@ runtime-benchmarks = [ "libsecp256k1/static-context", "pallet-babe/runtime-benchmarks", "pallet-fast-unstake/runtime-benchmarks", + "pallet-xcm-benchmarks/runtime-benchmarks", "runtime-parachains/runtime-benchmarks", + "xcm-executor", ] try-runtime = [ "pallet-authorship/try-runtime", diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index ff529143c509..449c3927166f 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -109,6 +109,96 @@ impl( + sp_std::marker::PhantomData<( + XcmConfig, + ExistentialDeposit, + PriceForDelivery, + ParaId, + ToParaIdHelper, + )>, +); + +#[cfg(feature = "runtime-benchmarks")] +impl< + XcmConfig: xcm_executor::Config, + ExistentialDeposit: Get>, + PriceForDelivery: PriceForParachainDelivery, + Parachain: Get, + ToParachainHelper: EnsureForParachain, + > pallet_xcm_benchmarks::EnsureDelivery + for ToParachainDeliveryHelper< + XcmConfig, + ExistentialDeposit, + PriceForDelivery, + Parachain, + ToParachainHelper, + > +{ + fn ensure_successful_delivery( + origin_ref: &MultiLocation, + _dest: &MultiLocation, + fee_reason: xcm_executor::traits::FeeReason, + ) -> Option { + use xcm_executor::{ + traits::{FeeManager, TransactAsset}, + FeesMode, + }; + + let mut fees_mode = None; + if !XcmConfig::FeeManager::is_waived(Some(origin_ref), fee_reason) { + // if not waived, we need to set up accounts for paying and receiving fees + + // mint ED to origin if needed + if let Some(ed) = ExistentialDeposit::get() { + XcmConfig::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); + } + + // overestimate delivery fee + let overestimated_xcm = vec![ClearOrigin; 128].into(); + let overestimated_fees = PriceForDelivery::price_for_parachain_delivery( + Parachain::get(), + &overestimated_xcm, + ); + + // mint overestimated fee to origin + for fee in overestimated_fees.inner() { + XcmConfig::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); + } + + // allow more initialization for target parachain + ToParachainHelper::ensure(Parachain::get()); + + // expected worst case + fees_mode = Some(FeesMode { jit_withdraw: true }); + } + fees_mode + } +} + +/// Ensure more initialization for `ParaId`. (e.g. open HRMP channels, ...) +#[cfg(feature = "runtime-benchmarks")] +pub trait EnsureForParachain { + fn ensure(para_id: ParaId); +} +#[cfg(feature = "runtime-benchmarks")] +impl EnsureForParachain for () { + fn ensure(_para_id: ParaId) { + // doing nothing + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index c66f0f7965a1..7f34e0213dab 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -2344,7 +2344,6 @@ sp_api::impl_runtime_apis! { use xcm_config::{ AssetHub, LocalCheckAccount, SovereignAccountOf, TokenLocation, XcmConfig, }; - use xcm_executor::{traits::FeeReason, FeesMode}; impl pallet_session_benchmarking::Config for Runtime {} impl pallet_offences_benchmarking::Config for Runtime {} @@ -2354,9 +2353,24 @@ sp_api::impl_runtime_apis! { impl pallet_nomination_pools_benchmarking::Config for Runtime {} impl runtime_parachains::disputes::slashing::benchmarking::Config for Runtime {} + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + TokenLocation::get(), + ExistentialDeposit::get() + ).into()); + pub ToParachain: ParaId = kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into(); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = XcmConfig; type AccountIdConverter = SovereignAccountOf; + type DeliveryHelper = runtime_common::xcm_sender::ToParachainDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForChildParachainDelivery, + ToParachain, + (), + >; fn valid_destination() -> Result { Ok(AssetHub::get()) } @@ -2367,43 +2381,6 @@ sp_api::impl_runtime_apis! { fun: Fungible(1_000_000 * UNITS), }].into() } - fn ensure_for_send(origin_ref: &MultiLocation, _dest: &MultiLocation, fee_reason: FeeReason) -> Option { - use xcm_executor::traits::{FeeManager, TransactAsset}; - - let mut fees_mode = None; - if !::FeeManager::is_waived(Some(origin_ref), fee_reason) { - // if not waived, we need to set up accounts for paying and receiving fees - - // mint ED to origin - let ed = MultiAsset { - id: Concrete(TokenLocation::get()), - fun: Fungible(EXISTENTIAL_DEPOSIT.into()) - }; - ::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); - - // overestimate delivery fee - use runtime_common::xcm_sender::PriceForParachainDelivery; - let overestimated_xcm = vec![ClearOrigin; 128].into(); - let overestimated_fees = runtime_common::xcm_sender::ExponentialPrice::< - xcm_config::FeeAssetId, - xcm_config::BaseDeliveryFee, - TransactionByteFee, - Dmp - >::price_for_parachain_delivery( - kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into(), - &overestimated_xcm - ); - - // mint overestimated fee to origin - for fee in overestimated_fees.inner() { - ::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); - } - - // expected worst case - fees_mode = Some(FeesMode { jit_withdraw: true }); - } - fees_mode - } } parameter_types! { diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index 16f7ff7037b1..e1093029f1ad 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -115,15 +115,14 @@ parameter_types! { pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } +pub type PriceForChildParachainDelivery = + ExponentialPrice; + /// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our /// individual routers. pub type XcmRouter = WithUniqueTopic<( // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter< - Runtime, - XcmPallet, - ExponentialPrice, - >, + ChildParachainRouter, )>; parameter_types! { diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index b93862f7eb2a..e4e0ca8fe8ea 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -2091,7 +2091,6 @@ sp_api::impl_runtime_apis! { use xcm_config::{ AssetHubLocation, TokenLocation, LocalCheckAccount, SovereignAccountOf, XcmConfig, }; - use xcm_executor::{traits::FeeReason, FeesMode}; impl pallet_session_benchmarking::Config for Runtime {} impl pallet_offences_benchmarking::Config for Runtime {} @@ -2105,9 +2104,24 @@ sp_api::impl_runtime_apis! { let treasury_key = frame_system::Account::::hashed_key_for(Treasury::account_id()); whitelist.push(treasury_key.to_vec().into()); + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + TokenLocation::get(), + ExistentialDeposit::get() + ).into()); + pub ToParachain: ParaId = polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into(); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = XcmConfig; type AccountIdConverter = SovereignAccountOf; + type DeliveryHelper = runtime_common::xcm_sender::ToParachainDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForChildParachainDelivery, + ToParachain, + (), + >; fn valid_destination() -> Result { Ok(AssetHubLocation::get()) } @@ -2115,43 +2129,6 @@ sp_api::impl_runtime_apis! { // Polkadot only knows about DOT vec![MultiAsset { id: Concrete(TokenLocation::get()), fun: Fungible(1_000_000 * UNITS) }].into() } - fn ensure_for_send(origin_ref: &MultiLocation, _dest: &MultiLocation, fee_reason: FeeReason) -> Option { - use xcm_executor::traits::{FeeManager, TransactAsset}; - - let mut fees_mode = None; - if !::FeeManager::is_waived(Some(origin_ref), fee_reason) { - // if not waived, we need to set up accounts for paying and receiving fees - - // mint ED to origin - let ed = MultiAsset { - id: Concrete(TokenLocation::get()), - fun: Fungible(EXISTENTIAL_DEPOSIT.into()) - }; - ::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); - - // overestimate delivery fee - use runtime_common::xcm_sender::PriceForParachainDelivery; - let overestimated_xcm = vec![ClearOrigin; 128].into(); - let overestimated_fees = runtime_common::xcm_sender::ExponentialPrice::< - xcm_config::FeeAssetId, - xcm_config::BaseDeliveryFee, - TransactionByteFee, - Dmp - >::price_for_parachain_delivery( - polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into(), - &overestimated_xcm - ); - - // mint overestimated fee to origin - for fee in overestimated_fees.inner() { - ::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); - } - - // expected worst case - fees_mode = Some(FeesMode { jit_withdraw: true }); - } - fees_mode - } } parameter_types! { diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs index add570e0768a..3a8bee4ce75d 100644 --- a/polkadot/runtime/polkadot/src/xcm_config.rs +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -120,15 +120,14 @@ parameter_types! { pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } +pub type PriceForChildParachainDelivery = + ExponentialPrice; + /// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our /// individual routers. pub type XcmRouter = WithUniqueTopic<( // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter< - Runtime, - XcmPallet, - ExponentialPrice, - >, + ChildParachainRouter, )>; parameter_types! { diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 89a4f27bd542..4d863e1a78d7 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2122,13 +2122,27 @@ sp_api::impl_runtime_apis! { use xcm_config::{ AssetHub, LocalCheckAccount, LocationConverter, TokenLocation, XcmConfig, }; - use xcm_executor::{traits::FeeReason, FeesMode}; + + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + TokenLocation::get(), + ExistentialDeposit::get() + ).into()); + pub ToParachain: ParaId = rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(); + } impl frame_system_benchmarking::Config for Runtime {} impl frame_benchmarking::baseline::Config for Runtime {} impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = XcmConfig; type AccountIdConverter = LocationConverter; + type DeliveryHelper = runtime_common::xcm_sender::ToParachainDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForChildParachainDelivery, + ToParachain, + (), + >; fn valid_destination() -> Result { Ok(AssetHub::get()) } @@ -2139,43 +2153,6 @@ sp_api::impl_runtime_apis! { fun: Fungible(1_000_000 * UNITS), }].into() } - fn ensure_for_send(origin_ref: &MultiLocation, _dest: &MultiLocation, fee_reason: FeeReason) -> Option { - use xcm_executor::traits::{FeeManager, TransactAsset}; - - let mut fees_mode = None; - if !::FeeManager::is_waived(Some(origin_ref), fee_reason) { - // if not waived, we need to set up accounts for paying and receiving fees - - // mint ED to origin - let ed = MultiAsset { - id: Concrete(TokenLocation::get()), - fun: Fungible(EXISTENTIAL_DEPOSIT.into()) - }; - ::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); - - // overestimate delivery fee - use runtime_common::xcm_sender::PriceForParachainDelivery; - let overestimated_xcm = vec![ClearOrigin; 128].into(); - let overestimated_fees = runtime_common::xcm_sender::ExponentialPrice::< - xcm_config::FeeAssetId, - xcm_config::BaseDeliveryFee, - TransactionByteFee, - Dmp - >::price_for_parachain_delivery( - rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(), - &overestimated_xcm - ); - - // mint overestimated fee to origin - for fee in overestimated_fees.inner() { - ::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); - } - - // expected worst case - fees_mode = Some(FeesMode { jit_withdraw: true }); - } - fees_mode - } } parameter_types! { diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 4a82946ae934..9342b52ce15d 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -95,15 +95,14 @@ parameter_types! { pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } +pub type PriceForChildParachainDelivery = + ExponentialPrice; + /// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our /// individual routers. pub type XcmRouter = WithUniqueTopic<( // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter< - Runtime, - XcmPallet, - ExponentialPrice, - >, + ChildParachainRouter, )>; parameter_types! { diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 416a0dc692a1..373dcb7bc06e 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2028,12 +2028,11 @@ sp_api::impl_runtime_apis! { MultiAsset, MultiAssets, MultiLocation, NetworkId, Response, }; use xcm_config::{AssetHub, TokenLocation}; - use xcm_executor::FeesMode; - use xcm_executor::traits::FeeReason; impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationConverter; + type DeliveryHelper = (); fn valid_destination() -> Result { Ok(AssetHub::get()) } @@ -2044,10 +2043,6 @@ sp_api::impl_runtime_apis! { fun: Fungible(1_000_000 * UNITS), }].into() } - fn ensure_for_send(_origin_ref: &MultiLocation, _dest: &MultiLocation, _fee_reason: FeeReason) -> Option { - // doing nothing - None - } } parameter_types! { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs index 3fc6fcf27812..e5e77ea88216 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs @@ -87,7 +87,8 @@ benchmarks_instance_pallet! { let dest_location = T::valid_destination()?; let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap(); - let expected_fees_mode = T::ensure_for_send(&sender_location, &dest_location, FeeReason::TransferReserveAsset); + use crate::EnsureDelivery; + let expected_fees_mode = T::DeliveryHelper::ensure_successful_delivery(&sender_location, &dest_location, FeeReason::TransferReserveAsset); let sender_account_balance_before = T::TransactAsset::balance(&sender_account); let asset = T::get_multi_asset(); diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index 0fa7e56f7614..dd23f9222772 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -27,7 +27,6 @@ use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; use xcm::latest::prelude::*; use xcm_builder::{AllowUnpaidExecutionFrom, MintLocation}; -use xcm_executor::{traits::FeeReason, FeesMode}; type Block = frame_system::mocking::MockBlock; @@ -158,6 +157,7 @@ impl xcm_executor::Config for XcmConfig { impl crate::Config for Test { type XcmConfig = XcmConfig; type AccountIdConverter = AccountIdConverter; + type DeliveryHelper = (); fn valid_destination() -> Result { let valid_destination: MultiLocation = X1(AccountId32 { network: None, id: [0u8; 32] }).into(); @@ -170,15 +170,6 @@ impl crate::Config for Test { ::MaxAssetsIntoHolding::get(), ) } - - fn ensure_for_send( - _origin_ref: &MultiLocation, - _dest: &MultiLocation, - _fee_reason: FeeReason, - ) -> Option { - // doing nothing - None - } } pub type TrustedTeleporters = xcm_builder::Case; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index fd3dff051616..7099542dd415 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -140,6 +140,7 @@ impl xcm_executor::Config for XcmConfig { impl crate::Config for Test { type XcmConfig = XcmConfig; type AccountIdConverter = AccountIdConverter; + type DeliveryHelper = (); fn valid_destination() -> Result { let valid_destination: MultiLocation = Junction::AccountId32 { network: None, id: [0u8; 32] }.into(); @@ -152,15 +153,6 @@ impl crate::Config for Test { ::MaxAssetsIntoHolding::get(), ) } - - fn ensure_for_send( - _origin_ref: &MultiLocation, - _dest: &MultiLocation, - _fee_reason: FeeReason, - ) -> Option { - // doing nothing - None - } } impl generic::Config for Test { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs index 49ab2d710fb8..e9455145165e 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs @@ -44,20 +44,15 @@ pub trait Config: frame_system::Config { /// A converter between a multi-location to a sovereign account. type AccountIdConverter: ConvertLocation; + /// Helper that ensures successful delivery for XCM instructions which need `SendXcm`. + type DeliveryHelper: EnsureDelivery; + /// Does any necessary setup to create a valid destination for XCM messages. /// Returns that destination's multi-location to be used in benchmarks. fn valid_destination() -> Result; /// Worst case scenario for a holding account in this runtime. fn worst_case_holding(depositable_count: u32) -> MultiAssets; - - /// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances ...). - /// Returns possible `FeesMode` which is expected to be set to executor. - fn ensure_for_send( - origin_ref: &MultiLocation, - dest: &MultiLocation, - fee_reason: FeeReason, - ) -> Option; } const SEED: u32 = 0; @@ -119,3 +114,26 @@ pub fn account_and_location(index: u32) -> (T::AccountId, MultiLocati (account, location) } + +/// Trait for a type which ensures all requirements for successful delivery with XCM transport layers. +pub trait EnsureDelivery { + /// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances, channels ...). + /// Returns possible `FeesMode` which is expected to be set to executor. + fn ensure_successful_delivery( + origin_ref: &MultiLocation, + dest: &MultiLocation, + fee_reason: FeeReason, + ) -> Option; +} + +/// `()` implementation does nothing which means no special requirements for environment. +impl EnsureDelivery for () { + fn ensure_successful_delivery( + _origin_ref: &MultiLocation, + _dest: &MultiLocation, + _fee_reason: FeeReason, + ) -> Option { + // doing nothing + None + } +} From db595f9c0f91a812fc48a125490e1becdbc1f921 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 14 Aug 2023 10:27:51 +0200 Subject: [PATCH 036/116] Fix rococo xcm benchmarks --- polkadot/runtime/rococo/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4d863e1a78d7..ae8e736f03bd 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2160,10 +2160,7 @@ sp_api::impl_runtime_apis! { AssetHub::get(), MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, )); - pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(( - AssetHub::get(), - MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) }, - )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; } impl pallet_xcm_benchmarks::fungible::Config for Runtime { From 2f64173354f8a5f65b6de6a368680906afe7430f Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 16 Aug 2023 20:28:35 +0000 Subject: [PATCH 037/116] ".git/.scripts/commands/fmt/fmt.sh" --- polkadot/runtime/common/src/xcm_sender.rs | 4 ++-- polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs | 7 ++++--- polkadot/xcm/pallet-xcm/src/tests.rs | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index 449c3927166f..4e560516f8ff 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -109,8 +109,8 @@ impl(index: u32) -> (T::AccountId, MultiLocati (account, location) } -/// Trait for a type which ensures all requirements for successful delivery with XCM transport layers. +/// Trait for a type which ensures all requirements for successful delivery with XCM transport +/// layers. pub trait EnsureDelivery { - /// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances, channels ...). - /// Returns possible `FeesMode` which is expected to be set to executor. + /// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances, + /// channels ...). Returns possible `FeesMode` which is expected to be set to executor. fn ensure_successful_delivery( origin_ref: &MultiLocation, dest: &MultiLocation, diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index c80260b49391..0f067110bed1 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -526,8 +526,8 @@ fn reserve_transfer_assets_works() { /// /// Asserts that the sender's balance is decreased and the beneficiary's balance /// is increased. Verifies the correct message is sent and event is emitted. -/// Verifies that XCM router fees (`SendXcm::validate` -> `MultiAssets`) are withdrawn from correct user account -/// and deposited to a correct target account (`XcmFeesTargetAccount`). +/// Verifies that XCM router fees (`SendXcm::validate` -> `MultiAssets`) are withdrawn from correct +/// user account and deposited to a correct target account (`XcmFeesTargetAccount`). #[test] fn reserve_transfer_assets_with_paid_router_works() { let user_account = AccountId::from(XCM_FEES_NOT_WAIVED_USER_ACCOUNT); From caa703c8c280265d9510b3798fa84822bb6455e2 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 16 Aug 2023 23:09:41 +0200 Subject: [PATCH 038/116] Nits --- polkadot/runtime/common/src/xcm_sender.rs | 6 +++--- .../pallet-xcm-benchmarks/src/fungible/benchmarking.rs | 10 +++++++++- polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs | 10 ++++++---- polkadot/xcm/pallet-xcm/src/tests.rs | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index 4e560516f8ff..1dfa83f57deb 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -150,7 +150,7 @@ impl< origin_ref: &MultiLocation, _dest: &MultiLocation, fee_reason: xcm_executor::traits::FeeReason, - ) -> Option { + ) -> (Option, Option) { use xcm_executor::{ traits::{FeeManager, TransactAsset}, FeesMode, @@ -180,10 +180,10 @@ impl< // allow more initialization for target parachain ToParachainHelper::ensure(Parachain::get()); - // expected worst case + // expected worst case - direct withdraw fees_mode = Some(FeesMode { jit_withdraw: true }); } - fees_mode + (fees_mode, None) } } diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs index e5e77ea88216..89c6e5e4325c 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs @@ -88,7 +88,11 @@ benchmarks_instance_pallet! { let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap(); use crate::EnsureDelivery; - let expected_fees_mode = T::DeliveryHelper::ensure_successful_delivery(&sender_location, &dest_location, FeeReason::TransferReserveAsset); + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &sender_location, + &dest_location, + FeeReason::TransferReserveAsset + ); let sender_account_balance_before = T::TransactAsset::balance(&sender_account); let asset = T::get_multi_asset(); @@ -101,6 +105,10 @@ benchmarks_instance_pallet! { if let Some(expected_fees_mode) = expected_fees_mode { executor.set_fees_mode(expected_fees_mode); } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } + let instruction = Instruction::TransferReserveAsset { assets, dest: dest_location, diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs index 60786a3ede13..3bf4aea1b25e 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs @@ -119,12 +119,14 @@ pub fn account_and_location(index: u32) -> (T::AccountId, MultiLocati /// layers. pub trait EnsureDelivery { /// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances, - /// channels ...). Returns possible `FeesMode` which is expected to be set to executor. + /// channels ...). Returns: + /// - possible `FeesMode` which is expected to be set to executor + /// - possible `MultiAssets` which are expected to be subsume to the Holding Register fn ensure_successful_delivery( origin_ref: &MultiLocation, dest: &MultiLocation, fee_reason: FeeReason, - ) -> Option; + ) -> (Option, Option); } /// `()` implementation does nothing which means no special requirements for environment. @@ -133,8 +135,8 @@ impl EnsureDelivery for () { _origin_ref: &MultiLocation, _dest: &MultiLocation, _fee_reason: FeeReason, - ) -> Option { + ) -> (Option, Option) { // doing nothing - None + (None, None) } } diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index 0f067110bed1..88454c1758a6 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -546,7 +546,7 @@ fn reserve_transfer_assets_with_paid_router_works() { assert_ok!(XcmPallet::reserve_transfer_assets( RuntimeOrigin::signed(user_account.clone()), Box::new(Parachain(paid_para_id).into()), - Box::new(dest.clone().into()), + Box::new(dest.into()), Box::new((Here, SEND_AMOUNT).into()), 0, )); From 2f0161e19343def405ed5862c4f3c2c46307c018 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 28 Aug 2023 22:41:45 -0700 Subject: [PATCH 039/116] Update polkadot/xcm/xcm-builder/tests/scenarios.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- polkadot/xcm/xcm-builder/tests/scenarios.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/xcm/xcm-builder/tests/scenarios.rs b/polkadot/xcm/xcm-builder/tests/scenarios.rs index 39af27f3ea59..07c2f3a75b25 100644 --- a/polkadot/xcm/xcm-builder/tests/scenarios.rs +++ b/polkadot/xcm/xcm-builder/tests/scenarios.rs @@ -174,7 +174,7 @@ fn report_holding_works() { } /// Scenario: -/// A parachain wants to move KSM from Kusama to Asset. +/// A parachain wants to move KSM from Kusama to Asset Hub. /// The parachain sends an XCM to withdraw funds combined with a teleport to the destination. /// /// This way of moving funds from a relay to a parachain will only work for trusted chains. From 84cf8ce3f83aba459f6f658d54a6f7a23e0c7e27 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 28 Aug 2023 23:16:42 -0700 Subject: [PATCH 040/116] Fixes --- .../runtimes/assets/asset-hub-kusama/src/xcm_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 2416c8e3850e..0f01eeb724f2 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -30,7 +30,6 @@ use frame_support::{ traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, }; use frame_system::EnsureRoot; -use kusama_parachain::primitives::Sibling; use kusama_runtime_constants::system_parachain::SystemParachains; use pallet_xcm::XcmPassthrough; use parachains_common::{ @@ -38,6 +37,7 @@ use parachains_common::{ xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; +use polkadot_parachain::primitives::Sibling; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ @@ -524,7 +524,7 @@ impl xcm_executor::Config for XcmConfig { type AssetExchanger = (); type FeeManager = XcmFeesToAccount< Self, - RelayOtherOrSystemParachains, + RelayOrOtherSystemParachains, AccountId, TreasuryAccount, >; From 78357aada58cafc6bd37a163fd747c9353877581 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 29 Aug 2023 09:59:57 -0700 Subject: [PATCH 041/116] Improve docs --- polkadot/runtime/common/src/xcm_sender.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index 1dfa83f57deb..347047d87d09 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -50,11 +50,19 @@ impl> PriceForParachainDelivery for ConstantPrice { } /// Implementation of `PriceForParachainDelivery` which returns an exponentially increasing price. -/// The `A` type parameter is used to denote the asset ID that will be used for paying the delivery -/// fee. -/// /// The formula for the fee is based on the sum of a base fee plus a message length fee, multiplied -/// by a specified factor. In mathematical form, it is `F * (B + encoded_msg_len * M)`. +/// by a specified factor. In mathematical form: +/// +/// `F * (B + encoded_msg_len * M)` +/// +/// Thus, if F = 1 and M = 1, this type is equivalent to `ConstantPrice`. +/// +/// The type parameters are understood as follows: +/// +/// - `A`: Used to denote the asset ID that will be used for paying the delivery fee. +/// - `B`: The base fee to pay for message delivery. +/// - `M`: The fee to pay for each and every byte of the message after encoding it. +/// - `F`: A fee factor multiplier. It can be understood as the exponent term in the formula. pub struct ExponentialPrice(sp_std::marker::PhantomData<(A, B, M, F)>); impl, B: Get, M: Get, F: FeeTracker> PriceForParachainDelivery for ExponentialPrice From a9a3f7ed6673161fbed3819b1deff3c9759baf3b Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 29 Aug 2023 10:03:37 -0700 Subject: [PATCH 042/116] Doc link --- polkadot/runtime/common/src/xcm_sender.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index 347047d87d09..c95e97de8610 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -55,7 +55,7 @@ impl> PriceForParachainDelivery for ConstantPrice { /// /// `F * (B + encoded_msg_len * M)` /// -/// Thus, if F = 1 and M = 1, this type is equivalent to `ConstantPrice`. +/// Thus, if F = 1 and M = 1, this type is equivalent to [`ConstantPrice`]. /// /// The type parameters are understood as follows: /// From a343a07d7a871149272b8c3de2a852249168e53d Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 29 Aug 2023 10:05:17 -0700 Subject: [PATCH 043/116] cargo fmt --- polkadot/runtime/common/src/xcm_sender.rs | 4 ++-- polkadot/xcm/xcm-executor/src/traits/transact_asset.rs | 6 +++++- substrate/frame/broker/src/dispatchable_impls.rs | 8 ++------ substrate/frame/broker/src/tick_impls.rs | 8 ++------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index c95e97de8610..c67dc3b3ab23 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -41,7 +41,7 @@ impl PriceForParachainDelivery for () { } } -/// Implementation of `PriceForParachainDelivery` which returns a fixed price. +/// Implementation of [`PriceForParachainDelivery`] which returns a fixed price. pub struct ConstantPrice(sp_std::marker::PhantomData); impl> PriceForParachainDelivery for ConstantPrice { fn price_for_parachain_delivery(_: ParaId, _: &Xcm<()>) -> MultiAssets { @@ -49,7 +49,7 @@ impl> PriceForParachainDelivery for ConstantPrice { } } -/// Implementation of `PriceForParachainDelivery` which returns an exponentially increasing price. +/// Implementation of [`PriceForParachainDelivery`] which returns an exponentially increasing price. /// The formula for the fee is based on the sum of a base fee plus a message length fee, multiplied /// by a specified factor. In mathematical form: /// diff --git a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs index e412b15d214a..c51befff88a6 100644 --- a/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs +++ b/polkadot/xcm/xcm-executor/src/traits/transact_asset.rs @@ -199,7 +199,11 @@ impl TransactAsset for Tuple { )* ); } - fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: Option<&XcmContext>) -> XcmResult { + fn deposit_asset( + what: &MultiAsset, + who: &MultiLocation, + context: Option<&XcmContext>, + ) -> XcmResult { for_tuples!( #( match Tuple::deposit_asset(what, who, context) { Err(XcmError::AssetNotFound) | Err(XcmError::Unimplemented) => (), diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 8dc0c9de393e..54cf5d71dcad 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -333,12 +333,8 @@ impl Pallet { region.begin = r + 1; contribution.length.saturating_dec(); - let Some(mut pool_record) = InstaPoolHistory::::get(r) else { - continue - }; - let Some(total_payout) = pool_record.maybe_payout else { - break - }; + let Some(mut pool_record) = InstaPoolHistory::::get(r) else { continue }; + let Some(total_payout) = pool_record.maybe_payout else { break }; let p = total_payout .saturating_mul(contributed_parts.into()) .checked_div(&pool_record.private_contributions.into()) diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 1688d386a531..def47c7c57c8 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -95,9 +95,7 @@ impl Pallet { } pub(crate) fn process_revenue() -> bool { - let Some((until, amount)) = T::Coretime::check_notify_revenue_info() else { - return false - }; + let Some((until, amount)) = T::Coretime::check_notify_revenue_info() else { return false }; let when: Timeslice = (until / T::TimeslicePeriod::get()).saturating_sub(One::one()).saturated_into(); let mut revenue = T::ConvertBalance::convert_back(amount); @@ -289,9 +287,7 @@ impl Pallet { rc_begin: RelayBlockNumberOf, core: CoreIndex, ) { - let Some(workplan) = Workplan::::take((timeslice, core)) else { - return - }; + let Some(workplan) = Workplan::::take((timeslice, core)) else { return }; let workload = Workload::::get(core); let parts_used = workplan.iter().map(|i| i.mask).fold(CoreMask::void(), |a, i| a | i); let mut workplan = workplan.into_inner(); From 680b32199af1df1df109400486093ff80f87f3e5 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 29 Aug 2023 23:50:10 -0700 Subject: [PATCH 044/116] Implement FeeTracker on the XCMP queue pallet --- Cargo.lock | 1 + cumulus/pallets/xcmp-queue/Cargo.toml | 6 ++- cumulus/pallets/xcmp-queue/src/lib.rs | 69 +++++++++++++++++++++++--- polkadot/runtime/parachains/src/dmp.rs | 2 +- polkadot/runtime/parachains/src/lib.rs | 1 + 5 files changed, 71 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5cb226d43dff..6511cb163907 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3661,6 +3661,7 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "polkadot-runtime-common", + "polkadot-runtime-parachains", "rand_chacha 0.3.1", "scale-info", "sp-core", diff --git a/cumulus/pallets/xcmp-queue/Cargo.toml b/cumulus/pallets/xcmp-queue/Cargo.toml index 21ba4a2a935c..a7bb344d5a9a 100644 --- a/cumulus/pallets/xcmp-queue/Cargo.toml +++ b/cumulus/pallets/xcmp-queue/Cargo.toml @@ -18,7 +18,8 @@ sp-runtime = { path = "../../../substrate/primitives/runtime", default-features sp-std = { path = "../../../substrate/primitives/std", default-features = false} # Polkadot -polkadot-runtime-common = { path = "../../../polkadot/runtime/common", default-features = false} +polkadot-runtime-common = { path = "../../../polkadot/runtime/common", default-features = false } +polkadot-runtime-parachains = { path = "../../../polkadot/runtime/parachains", default-features = false } xcm = { path = "../../../polkadot/xcm", default-features = false} xcm-executor = { path = "../../../polkadot/xcm/xcm-executor", default-features = false} @@ -50,6 +51,7 @@ std = [ "frame-system/std", "log/std", "polkadot-runtime-common/std", + "polkadot-runtime-parachains/std", "scale-info/std", "sp-io/std", "sp-runtime/std", @@ -65,6 +67,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", + "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", @@ -75,5 +78,6 @@ try-runtime = [ "frame-system/try-runtime", "pallet-balances/try-runtime", "polkadot-runtime-common/try-runtime", + "polkadot-runtime-parachains/try-runtime", "sp-runtime/try-runtime", ] diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index 960af9b5b772..3b8427a05cd6 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -48,12 +48,13 @@ use frame_support::{ weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight}, }; use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; +use polkadot_runtime_parachains::FeeTracker; use rand_chacha::{ rand_core::{RngCore, SeedableRng}, ChaChaRng, }; use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; +use sp_runtime::{FixedU128, RuntimeDebug, Saturating}; use sp_std::{convert::TryFrom, prelude::*}; use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH}; use xcm_executor::traits::ConvertOrigin; @@ -65,6 +66,8 @@ pub type OverweightIndex = u64; const LOG_TARGET: &str = "xcmp_queue"; const DEFAULT_POV_SIZE: u64 = 64 * 1024; // 64 KB +const EXPONENTIAL_FEE_BASE: FixedU128 = FixedU128::from_rational(105, 100); // 1.05 +const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0.001 // Maximum amount of messages to process per block. This is a temporary measure until we properly // account for proof size weights. @@ -75,7 +78,7 @@ const MAX_OVERWEIGHT_MESSAGES: u32 = 1000; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; + use frame_support::{pallet_prelude::*, Twox64Concat}; use frame_system::pallet_prelude::*; #[pallet::pallet] @@ -372,6 +375,17 @@ pub mod pallet { /// Whether or not the XCMP queue is suspended from executing incoming XCMs or not. #[pallet::storage] pub(super) type QueueSuspended = StorageValue<_, bool, ValueQuery>; + + /// Initialization value for the DeliveryFee factor. + #[pallet::type_value] + pub fn InitialFactor() -> FixedU128 { + FixedU128::from_u32(1) + } + + /// The factor to multiply the base delivery fee by. + #[pallet::storage] + pub(super) type DeliveryFeeFactor = + StorageMap<_, Twox64Concat, ParaId, FixedU128, ValueQuery, InitialFactor>; } #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -655,6 +669,7 @@ impl Pallet { messages_processed: &mut u8, max_weight: Weight, max_individual_weight: Weight, + should_decrement_fee_factor: bool, ) -> (Weight, bool) { let data = >::get(sender, sent_at); let mut last_remaining_fragments; @@ -719,6 +734,10 @@ impl Pallet { debug_assert!(false, "Invalid incoming XCMP message data"); remaining_fragments = &b""[..]; } + + if should_decrement_fee_factor { + Self::decrement_fee_factor(sender); + } } }, XcmpMessageFormat::ConcatenatedEncodedBlob => { @@ -814,6 +833,7 @@ impl Pallet { let QueueConfigData { resume_threshold, + suspend_threshold, threshold_weight, weight_restrict_decay, xcmp_max_individual_weight, @@ -872,12 +892,15 @@ impl Pallet { } else { // Process up to one block's worth for now. let weight_remaining = weight_available.saturating_sub(weight_used); + let should_decrement_fee_factor = + (status[index].message_metadata.len() as u32) <= suspend_threshold; let (weight_processed, is_empty) = Self::process_xcmp_message( sender, status[index].message_metadata[0], &mut messages_processed, weight_remaining, xcmp_max_individual_weight, + should_decrement_fee_factor, ); if is_empty { status[index].message_metadata.remove(0); @@ -947,6 +970,28 @@ impl Pallet { } }); } + + /// Raise the delivery fee factor by a multiplicative factor and stores the resulting value. + /// + /// Returns the new delivery fee factor after the increment. + pub(crate) fn increment_fee_factor(para: ParaId, message_size_factor: FixedU128) -> FixedU128 { + >::mutate(para, |f| { + *f = f.saturating_mul(EXPONENTIAL_FEE_BASE + message_size_factor); + *f + }) + } + + /// Reduce the delivery fee factor by a multiplicative factor and stores the resulting value. + /// + /// Does not reduce the fee factor below the initial value, which is currently set as 1. + /// + /// Returns the new delivery fee factor after the decrement. + pub(crate) fn decrement_fee_factor(para: ParaId) -> FixedU128 { + >::mutate(para, |f| { + *f = InitialFactor::get().max(*f / EXPONENTIAL_FEE_BASE); + *f + }) + } } impl XcmpMessageHandler for Pallet { @@ -984,9 +1029,8 @@ impl XcmpMessageHandler for Pallet { // Record the fact we received it. match status.binary_search_by_key(&sender, |item| item.sender) { Ok(i) => { - let count = status[i].message_metadata.len(); - if count as u32 >= suspend_threshold && status[i].state == InboundState::Ok - { + let count = status[i].message_metadata.len() as u32; + if count >= suspend_threshold && status[i].state == InboundState::Ok { status[i].state = InboundState::Suspended; let r = Self::send_signal(sender, ChannelSignal::Suspend); if r.is_err() { @@ -995,7 +1039,7 @@ impl XcmpMessageHandler for Pallet { ); } } - if (count as u32) < drop_threshold { + if count < drop_threshold { status[i].message_metadata.push((sent_at, format)); } else { debug_assert!( @@ -1003,6 +1047,13 @@ impl XcmpMessageHandler for Pallet { "XCMP channel queue full. Silently dropping message" ); } + // Update the delivery fee factor, if applicable. + if count > suspend_threshold { + let message_size_factor = + FixedU128::from_u32(data_ref.len().saturating_div(1024) as u32) + .saturating_mul(MESSAGE_SIZE_FEE_BASE); + Self::increment_fee_factor(sender, message_size_factor); + } }, Err(_) => status.push(InboundChannelDetails { sender, @@ -1178,3 +1229,9 @@ impl SendXcm for Pallet { } } } + +impl FeeTracker for Pallet { + fn get_fee_factor(para: ParaId) -> FixedU128 { + >::get(para) + } +} diff --git a/polkadot/runtime/parachains/src/dmp.rs b/polkadot/runtime/parachains/src/dmp.rs index 490c2fa1cd09..5e279bd7e297 100644 --- a/polkadot/runtime/parachains/src/dmp.rs +++ b/polkadot/runtime/parachains/src/dmp.rs @@ -144,7 +144,7 @@ pub mod pallet { FixedU128::from_u32(1) } - /// The number to multiply the base delivery fee by. + /// The factor to multiply the base delivery fee by. #[pallet::storage] pub(crate) type DeliveryFeeFactor = StorageMap<_, Twox64Concat, ParaId, FixedU128, ValueQuery, InitialFactor>; diff --git a/polkadot/runtime/parachains/src/lib.rs b/polkadot/runtime/parachains/src/lib.rs index 056eef354260..6770fdc02ae9 100644 --- a/polkadot/runtime/parachains/src/lib.rs +++ b/polkadot/runtime/parachains/src/lib.rs @@ -59,6 +59,7 @@ use sp_runtime::{DispatchResult, FixedU128}; /// Trait for tracking message delivery fees on a transport protocol. pub trait FeeTracker { + /// The evolving exponential fee factor which will be used to calculate the delivery fees. fn get_fee_factor(para: ParaId) -> FixedU128; } From 4a9a309f8c7f0c6d8672003b58525690c5d65119 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sat, 9 Sep 2023 01:59:33 -0400 Subject: [PATCH 045/116] Fixes --- cumulus/pallets/xcmp-queue/src/tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cumulus/pallets/xcmp-queue/src/tests.rs b/cumulus/pallets/xcmp-queue/src/tests.rs index 2929e8452bef..17b72c9a5045 100644 --- a/cumulus/pallets/xcmp-queue/src/tests.rs +++ b/cumulus/pallets/xcmp-queue/src/tests.rs @@ -49,6 +49,7 @@ fn bad_message_is_handled() { &mut 0, Weight::from_parts(10_000_000_000, 0), Weight::from_parts(10_000_000_000, 0), + true, ); }); } @@ -73,6 +74,7 @@ fn handle_blob_message() { &mut 0, Weight::from_parts(10_000_000_000, 0), Weight::from_parts(10_000_000_000, 0), + true, ); }); } @@ -91,6 +93,7 @@ fn handle_invalid_data() { &mut 0, Weight::from_parts(10_000_000_000, 0), Weight::from_parts(10_000_000_000, 0), + true, ); }); } From 42c80f1dfa181d5ba382653c5d1583c22800eae8 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sat, 9 Sep 2023 02:19:22 -0400 Subject: [PATCH 046/116] Formatting --- polkadot/runtime/common/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 4191c15c7a19..ed2058eae367 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -126,7 +126,7 @@ runtime-benchmarks = [ "runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", - "xcm-executor", + "xcm-executor", ] try-runtime = [ "frame-election-provider-support/try-runtime", From 8ceea3464ab5a09e584e213d46555ac3d5fb4e6c Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 13 Sep 2023 20:54:09 -0300 Subject: [PATCH 047/116] Add default DeliveryHelper for system parachains --- cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 1 + cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs | 1 + cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 1 + .../parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs | 1 + .../runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs | 1 + .../parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 1 + 6 files changed, 6 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 828d1b4750a3..94c6fe90f47b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -1213,6 +1213,7 @@ impl_runtime_apis! { impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = (); // No requirements for UMP fn valid_destination() -> Result { Ok(KsmLocation::get()) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index 0051af21f9a3..dc12db7bb683 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -1092,6 +1092,7 @@ impl_runtime_apis! { impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = (); // No requirements for UMP fn valid_destination() -> Result { Ok(DotLocation::get()) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 4887fce1b0a4..10a30dba0bac 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1226,6 +1226,7 @@ impl_runtime_apis! { impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = (); // No requirements for UMP fn valid_destination() -> Result { Ok(WestendLocation::get()) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 54b15e6b327b..67d407f28646 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -673,6 +673,7 @@ impl_runtime_apis! { impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = (); // No requirements for UMP fn valid_destination() -> Result { Ok(KsmRelayLocation::get()) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index dbfdc249a3cd..10f463c36316 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -673,6 +673,7 @@ impl_runtime_apis! { impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = (); // No requirements for UMP fn valid_destination() -> Result { Ok(DotRelayLocation::get()) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 309a5cfb0b1d..a54b21a7618c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -953,6 +953,7 @@ impl_runtime_apis! { impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = (); // No requirements for UMP fn valid_destination() -> Result { Ok(RelayLocation::get()) } From d0df1261cebd9c01abe5f8323c9106649250184d Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 14 Sep 2023 11:53:02 +0800 Subject: [PATCH 048/116] Typo --- polkadot/runtime/common/src/xcm_sender.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index c67dc3b3ab23..846206cd88b5 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -55,7 +55,7 @@ impl> PriceForParachainDelivery for ConstantPrice { /// /// `F * (B + encoded_msg_len * M)` /// -/// Thus, if F = 1 and M = 1, this type is equivalent to [`ConstantPrice`]. +/// Thus, if F = 1 and M = 0, this type is equivalent to [`ConstantPrice`]. /// /// The type parameters are understood as follows: /// From ca699365236b5e57492b0b188091fdd3128fd29e Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 14 Sep 2023 11:55:42 +0800 Subject: [PATCH 049/116] Create DeliveryHelper for reserve chains --- .../assets/asset-hub-kusama/src/lib.rs | 34 +++++++++++++++++-- .../assets/asset-hub-polkadot/src/lib.rs | 31 +++++++++++++++-- .../assets/asset-hub-westend/src/lib.rs | 33 ++++++++++++++++-- polkadot/runtime/westend/src/lib.rs | 16 ++++++++- polkadot/runtime/westend/src/xcm_config.rs | 9 +++-- 5 files changed, 109 insertions(+), 14 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 94c6fe90f47b..d1dc0358042d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -87,7 +87,7 @@ pub use sp_runtime::BuildStorage; // Polkadot imports use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use xcm::latest::BodyId; +use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; use crate::xcm_config::{ @@ -632,6 +632,20 @@ parameter_types! { pub const FellowsBodyId: BodyId = BodyId::Technical; } +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::KsmLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -644,7 +658,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { >; type ControllerOriginConverter = xcm_config::XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -1210,10 +1224,24 @@ impl_runtime_apis! { use xcm_config::{KsmLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + xcm_config::KsmLocation::get(), + ExistentialDeposit::get() + ).into()); + pub ToParachain: ParaId = kusama_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); // No requirements for UMP + type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + PriceForSiblingParachainDelivery, + ToParachain, + (), + >; fn valid_destination() -> Result { Ok(KsmLocation::get()) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index dc12db7bb683..60ec8afc5106 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -117,7 +117,7 @@ pub use sp_runtime::BuildStorage; // Polkadot imports use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use xcm::latest::BodyId; +use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; use crate::xcm_config::ForeignCreatorsSovereignAccountOf; @@ -566,8 +566,19 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types! { // Fellows pluralistic body. pub const FellowsBodyId: BodyId = BodyId::Technical; + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::DotLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; type RuntimeEvent = RuntimeEvent; @@ -580,7 +591,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { EnsureXcm>, >; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -1089,10 +1100,24 @@ impl_runtime_apis! { use xcm_config::{DotLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + xcm_config::DotLocation::get(), + ExistentialDeposit::get() + ).into()); + pub ToParachain: ParaId = polkadot_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); // No requirements for UMP + type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + PriceForSiblingParachainDelivery, + ToParachain, + (), + >; fn valid_destination() -> Result { Ok(DotLocation::get()) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 10a30dba0bac..be38e7b9cb1f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -87,6 +87,7 @@ use assets_common::{ foreign_creators::ForeignCreators, matching::FromSiblingParachain, MultiLocationForAssetId, }; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; +use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; use crate::xcm_config::ForeignCreatorsSovereignAccountOf; @@ -603,6 +604,20 @@ impl parachain_info::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {} +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::WestendLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -612,7 +627,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -1223,10 +1238,24 @@ impl_runtime_apis! { use xcm_config::{MaxAssetsIntoHolding, WestendLocation}; use pallet_xcm_benchmarks::asset_instance_from; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + xcm_config::WestendLocation::get(), + ExistentialDeposit::get() + ).into()); + pub ToParachain: ParaId = westend_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); // No requirements for UMP + type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + PriceForSiblingParachainDelivery, + ToParachain, + (), + >; fn valid_destination() -> Result { Ok(WestendLocation::get()) } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index e2eef0b01ee7..96b9f213f2b3 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2035,10 +2035,24 @@ sp_api::impl_runtime_apis! { }; use xcm_config::{AssetHub, TokenLocation}; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + TokenLocation::get(), + ExistentialDeposit::get() + ).into()); + pub ToParachain: ParaId = westend_runtime_constants::system_parachain::ASSET_HUB_ID.into(); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationConverter; - type DeliveryHelper = (); + type DeliveryHelper = runtime_common::xcm_sender::ToParachainDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForChildParachainDelivery, + ToParachain, + (), + >; fn valid_destination() -> Result { Ok(AssetHub::get()) } diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index 6ad899bcab0f..39246d55406b 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -77,15 +77,14 @@ type LocalOriginConverter = ( ChildSystemParachainAsSuperuser, ); +pub type PriceForChildParachainDelivery = + ExponentialPrice; + /// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our /// individual routers. pub type XcmRouter = WithUniqueTopic<( // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter< - Runtime, - XcmPallet, - ExponentialPrice, - >, + ChildParachainRouter, )>; parameter_types! { From 646996292a48fe7432cb05fad155c9c3d3e21041 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 14 Sep 2023 14:59:23 +0800 Subject: [PATCH 050/116] Fixes --- cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index be38e7b9cb1f..3a424d65c753 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1402,7 +1402,6 @@ pub mod migrations { }; use parachains_common::impls::AccountIdOf; use sp_runtime::{traits::StaticLookup, Saturating}; - use xcm::latest::prelude::*; /// Temporary migration because of bug with native asset, it can be removed once applied on /// `AssetHubWestend`. Migrates pools with `MultiLocation { parents: 0, interior: Here }` to From 4f98070c86ede30111ce3e54bcec14aecfbd3026 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 15 Sep 2023 19:37:33 -0300 Subject: [PATCH 051/116] Fix teleports_for_foreign_assets_works test --- Cargo.lock | 1 + .../runtimes/assets/test-utils/Cargo.toml | 10 +++-- .../assets/test-utils/src/test_cases.rs | 41 +++++++++++++++++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fca70b4e3adb..8e2322fa2ef2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1001,6 +1001,7 @@ dependencies = [ "parachains-runtimes-test-utils", "parity-scale-codec", "polkadot-parachain-primitives", + "polkadot-runtime-common", "sp-consensus-aura", "sp-core", "sp-io", diff --git a/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml b/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml index 0a27535ed22b..db4e4a11e759 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml @@ -34,10 +34,11 @@ parachain-info = { path = "../../../pallets/parachain-info", default-features = parachains-runtimes-test-utils = { path = "../../test-utils", default-features = false } # Polkadot -xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} -xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} -pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false} -polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false} +xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false } +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false } +pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false } +polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false } +polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } [dev-dependencies] hex-literal = "0.4.1" @@ -66,6 +67,7 @@ std = [ "parachains-common/std", "parachains-runtimes-test-utils/std", "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", "sp-consensus-aura/std", "sp-core/std", "sp-io/std", diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 7a8d571403c6..e632c9e7a4a6 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -18,7 +18,7 @@ use codec::Encode; use frame_support::{ assert_noop, assert_ok, - traits::{fungibles::InspectEnumerable, Get, OnFinalize, OnInitialize, OriginTrait}, + traits::{fungibles::InspectEnumerable, fungible::Mutate, Get, OnFinalize, OnInitialize, OriginTrait}, weights::Weight, }; use frame_system::pallet_prelude::BlockNumberFor; @@ -27,11 +27,12 @@ use parachains_runtimes_test_utils::{ assert_metadata, assert_total, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, ValidatorIdOf, XcmReceivedFrom, }; +use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; use sp_runtime::{ traits::{MaybeEquivalence, StaticLookup, Zero}, DispatchError, Saturating, }; -use xcm::latest::prelude::*; +use xcm::{latest::prelude::*, VersionedXcm}; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; type RuntimeHelper = @@ -368,7 +369,7 @@ pub fn teleports_for_foreign_assets_works< fun: Fungible(buy_execution_fee_amount), }; - let teleported_foreign_asset_amount = 10000000000000; + let teleported_foreign_asset_amount = 10_000_000_000_000; let runtime_para_id = 1000; ExtBuilder::::default() .with_collators(collator_session_keys.collators()) @@ -398,11 +399,11 @@ pub fn teleports_for_foreign_assets_works< >::free_balance(&target_account), existential_deposit ); + // check `CheckingAccount` before assert_eq!( >::free_balance(&CheckingAccount::get()), existential_deposit ); - // check `CheckingAccount` before assert_eq!( >::balance( foreign_asset_id_multilocation.into(), @@ -538,6 +539,31 @@ pub fn teleports_for_foreign_assets_works< .into() ); + // Build expected message sent by the `teleport_assets` extrinsic + let context = ::UniversalLocation::get(); + let assets_to_teleport: MultiAsset = (foreign_asset_id_multilocation.clone(), asset_to_teleport_away.clone()).into(); + let assets_to_teleport = assets_to_teleport + .reanchored(&dest, context).expect("We know location is invertible; qed"); + let topic = [ + 107u8, 174, 76, 190, 37, 87, 84, 110, 10, 244, 5, 222, 143, 53, 203, 227, + 9, 9, 142, 76, 177, 63, 74, 39, 66, 99, 249, 239, 166, 208, 164, 191, + ]; + let weight_limit = Limited(Weight::from_parts(163_503_000, 0)); + let expected_message = Xcm::<()>(vec![ + ReceiveTeleportedAsset(assets_to_teleport.clone().into()), + ClearOrigin, + BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, + DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, + SetTopic(topic), + ]); + + // Make sure the target account has enough native asset to pay for delivery fees + let delivery_fees = < + ::PriceForSiblingDelivery as PriceForParachainDelivery + >::price_for_parachain_delivery(foreign_para_id.into(), &expected_message); + let Fungible(amount_to_mint) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible; qed") }; + >::mint_into(&target_account, amount_to_mint.into()).unwrap(); + assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -548,6 +574,13 @@ pub fn teleports_for_foreign_assets_works< &alice, )); + // Real xcm sent should match the expected + let real_xcm = RuntimeHelper::< + ::OutboundXcmpMessageSource, + AllPalletsWithoutSystem + >::take_xcm(foreign_para_id.into()).unwrap(); + assert_eq!(&VersionedXcm::V3(expected_message), &real_xcm); + // check balances assert_eq!( >::balance( From af687906673ca8ca74a2cf1a7f9b67ae689c05ca Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 15 Sep 2023 19:52:21 -0300 Subject: [PATCH 052/116] Fix teleports_for_native_asset_works --- .../assets/test-utils/src/test_cases.rs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index e632c9e7a4a6..b35a122352cf 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -222,6 +222,30 @@ pub fn teleports_for_native_asset_works< target_account_balance_before_teleport - existential_deposit ); + // Build expected message sent by the `teleport_assets` extrinsic + let context = ::UniversalLocation::get(); + let assets_to_teleport: MultiAsset = (native_asset_id.clone(), native_asset_to_teleport_away.into()).into(); + let assets_to_teleport = assets_to_teleport + .reanchored(&dest, context).expect("We know location is invertible; qed"); + let topic = [ + 233, 54, 126, 48, 202, 61, 104, 83, 26, 134, 191, 227, 183, 110, 21, 231, + 224, 241, 220, 54, 22, 206, 9, 95, 65, 171, 80, 148, 77, 121, 225, 188, + ]; + let weight_limit = Limited(Weight::from_parts(163_503_000, 0)); + let expected_message = Xcm::<()>(vec![ + ReceiveTeleportedAsset(assets_to_teleport.clone().into()), + ClearOrigin, + BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, + DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, + SetTopic(topic), + ]); + + // Make sure the target account has enough native asset to pay for delivery fees + let delivery_fees = < + ::PriceForSiblingDelivery as PriceForParachainDelivery + >::price_for_parachain_delivery(other_para_id.into(), &expected_message); + let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; + assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -232,10 +256,17 @@ pub fn teleports_for_native_asset_works< &alice, )); + // Real xcm sent should match the expected + let real_xcm = RuntimeHelper::< + ::OutboundXcmpMessageSource, + AllPalletsWithoutSystem + >::take_xcm(other_para_id.into()).unwrap(); + assert_eq!(&VersionedXcm::V3(expected_message), &real_xcm); + // check balances assert_eq!( >::free_balance(&target_account), - target_account_balance_before_teleport - native_asset_to_teleport_away + target_account_balance_before_teleport - native_asset_to_teleport_away - delivery_fees_amount.into() ); assert_eq!( >::free_balance(&CheckingAccount::get()), From 0ccb3482ee135663f2b06cadc57c7da737676b2b Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 15 Sep 2023 19:55:04 -0300 Subject: [PATCH 053/116] Fix some clippy issues --- .../parachains/runtimes/assets/test-utils/src/test_cases.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index b35a122352cf..ae92a8b189a4 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -224,7 +224,7 @@ pub fn teleports_for_native_asset_works< // Build expected message sent by the `teleport_assets` extrinsic let context = ::UniversalLocation::get(); - let assets_to_teleport: MultiAsset = (native_asset_id.clone(), native_asset_to_teleport_away.into()).into(); + let assets_to_teleport: MultiAsset = (native_asset_id, native_asset_to_teleport_away.into()).into(); let assets_to_teleport = assets_to_teleport .reanchored(&dest, context).expect("We know location is invertible; qed"); let topic = [ @@ -572,7 +572,7 @@ pub fn teleports_for_foreign_assets_works< // Build expected message sent by the `teleport_assets` extrinsic let context = ::UniversalLocation::get(); - let assets_to_teleport: MultiAsset = (foreign_asset_id_multilocation.clone(), asset_to_teleport_away.clone()).into(); + let assets_to_teleport: MultiAsset = (foreign_asset_id_multilocation, asset_to_teleport_away).into(); let assets_to_teleport = assets_to_teleport .reanchored(&dest, context).expect("We know location is invertible; qed"); let topic = [ From 8a815218772c4cfddca3ec6aae8cdf577af20bd5 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 15 Sep 2023 20:33:38 -0300 Subject: [PATCH 054/116] Fix faulty import --- polkadot/runtime/westend/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 96b9f213f2b3..ec9c61bbbe05 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2047,7 +2047,7 @@ sp_api::impl_runtime_apis! { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationConverter; type DeliveryHelper = runtime_common::xcm_sender::ToParachainDeliveryHelper< - XcmConfig, + xcm_config::XcmConfig, ExistentialDepositMultiAsset, xcm_config::PriceForChildParachainDelivery, ToParachain, From 678effb074b77c26ba9dd97c263e1493dbbc81a1 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 18 Sep 2023 12:06:47 -0300 Subject: [PATCH 055/116] Fix topic issue in tests --- .../assets/test-utils/src/test_cases.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index ae92a8b189a4..d26f91493fa1 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -227,17 +227,14 @@ pub fn teleports_for_native_asset_works< let assets_to_teleport: MultiAsset = (native_asset_id, native_asset_to_teleport_away.into()).into(); let assets_to_teleport = assets_to_teleport .reanchored(&dest, context).expect("We know location is invertible; qed"); - let topic = [ - 233, 54, 126, 48, 202, 61, 104, 83, 26, 134, 191, 227, 183, 110, 21, 231, - 224, 241, 220, 54, 22, 206, 9, 95, 65, 171, 80, 148, 77, 121, 225, 188, - ]; let weight_limit = Limited(Weight::from_parts(163_503_000, 0)); let expected_message = Xcm::<()>(vec![ ReceiveTeleportedAsset(assets_to_teleport.clone().into()), ClearOrigin, BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, - SetTopic(topic), + // Not real topic, used for calculating fees, will be dropped before checking real message + SetTopic([0u8; 32]), ]); // Make sure the target account has enough native asset to pay for delivery fees @@ -246,6 +243,9 @@ pub fn teleports_for_native_asset_works< >::price_for_parachain_delivery(other_para_id.into(), &expected_message); let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; + // Drop the topic before we check against real message + let expected_message = Xcm::<()>(expected_message.inner()[..expected_message.len() - 1].into()); + assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -257,11 +257,12 @@ pub fn teleports_for_native_asset_works< )); // Real xcm sent should match the expected - let real_xcm = RuntimeHelper::< + let real_xcm: Xcm::<()> = RuntimeHelper::< ::OutboundXcmpMessageSource, AllPalletsWithoutSystem - >::take_xcm(other_para_id.into()).unwrap(); - assert_eq!(&VersionedXcm::V3(expected_message), &real_xcm); + >::take_xcm(other_para_id.into()).unwrap().try_into().unwrap(); + let real_xcm = Xcm::<()>(real_xcm.inner()[..real_xcm.len() - 1].into()); + assert_eq!(&expected_message, &real_xcm); // check balances assert_eq!( From 36b5833075ee69f6821d7de26bd88ec8eafedece Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 18 Sep 2023 12:52:33 -0300 Subject: [PATCH 056/116] Fix topic issue in another test --- .../assets/test-utils/src/test_cases.rs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index d26f91493fa1..5fdf9124159a 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -32,7 +32,7 @@ use sp_runtime::{ traits::{MaybeEquivalence, StaticLookup, Zero}, DispatchError, Saturating, }; -use xcm::{latest::prelude::*, VersionedXcm}; +use xcm::latest::prelude::*; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; type RuntimeHelper = @@ -227,8 +227,8 @@ pub fn teleports_for_native_asset_works< let assets_to_teleport: MultiAsset = (native_asset_id, native_asset_to_teleport_away.into()).into(); let assets_to_teleport = assets_to_teleport .reanchored(&dest, context).expect("We know location is invertible; qed"); - let weight_limit = Limited(Weight::from_parts(163_503_000, 0)); - let expected_message = Xcm::<()>(vec![ + let weight_limit = Limited(Weight::from_parts(161_592_000, 0)); + let mut expected_message = Xcm::<()>(vec![ ReceiveTeleportedAsset(assets_to_teleport.clone().into()), ClearOrigin, BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, @@ -244,7 +244,7 @@ pub fn teleports_for_native_asset_works< let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; // Drop the topic before we check against real message - let expected_message = Xcm::<()>(expected_message.inner()[..expected_message.len() - 1].into()); + expected_message = Xcm::<()>(expected_message.inner()[..expected_message.len() - 1].into()); assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), @@ -257,11 +257,11 @@ pub fn teleports_for_native_asset_works< )); // Real xcm sent should match the expected - let real_xcm: Xcm::<()> = RuntimeHelper::< + let mut real_xcm: Xcm::<()> = RuntimeHelper::< ::OutboundXcmpMessageSource, AllPalletsWithoutSystem >::take_xcm(other_para_id.into()).unwrap().try_into().unwrap(); - let real_xcm = Xcm::<()>(real_xcm.inner()[..real_xcm.len() - 1].into()); + real_xcm = Xcm::<()>(real_xcm.inner()[..real_xcm.len() - 1].into()); assert_eq!(&expected_message, &real_xcm); // check balances @@ -576,17 +576,14 @@ pub fn teleports_for_foreign_assets_works< let assets_to_teleport: MultiAsset = (foreign_asset_id_multilocation, asset_to_teleport_away).into(); let assets_to_teleport = assets_to_teleport .reanchored(&dest, context).expect("We know location is invertible; qed"); - let topic = [ - 107u8, 174, 76, 190, 37, 87, 84, 110, 10, 244, 5, 222, 143, 53, 203, 227, - 9, 9, 142, 76, 177, 63, 74, 39, 66, 99, 249, 239, 166, 208, 164, 191, - ]; let weight_limit = Limited(Weight::from_parts(163_503_000, 0)); - let expected_message = Xcm::<()>(vec![ + let mut expected_message = Xcm::<()>(vec![ ReceiveTeleportedAsset(assets_to_teleport.clone().into()), ClearOrigin, BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, - SetTopic(topic), + // Not real topic, used for calculating fees, will be dropped before checking real message + SetTopic([0u8; 32]), ]); // Make sure the target account has enough native asset to pay for delivery fees @@ -596,6 +593,9 @@ pub fn teleports_for_foreign_assets_works< let Fungible(amount_to_mint) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible; qed") }; >::mint_into(&target_account, amount_to_mint.into()).unwrap(); + // Drop the topic before we check against real message + expected_message = Xcm::<()>(expected_message.inner()[..expected_message.len() - 1].into()); + assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -607,11 +607,12 @@ pub fn teleports_for_foreign_assets_works< )); // Real xcm sent should match the expected - let real_xcm = RuntimeHelper::< + let mut real_xcm: Xcm::<()> = RuntimeHelper::< ::OutboundXcmpMessageSource, AllPalletsWithoutSystem - >::take_xcm(foreign_para_id.into()).unwrap(); - assert_eq!(&VersionedXcm::V3(expected_message), &real_xcm); + >::take_xcm(foreign_para_id.into()).unwrap().try_into().unwrap(); + real_xcm = Xcm::<()>(real_xcm.inner()[..real_xcm.len() - 1].into()); + assert_eq!(&expected_message, &real_xcm); // check balances assert_eq!( From 1d439b9a40f30aa1d83595b0c3d030ed5d8037c2 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 18 Sep 2023 13:20:18 -0300 Subject: [PATCH 057/116] Stop asserting the expected message --- .../assets/test-utils/src/test_cases.rs | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 5fdf9124159a..8046411ec820 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -222,18 +222,17 @@ pub fn teleports_for_native_asset_works< target_account_balance_before_teleport - existential_deposit ); - // Build expected message sent by the `teleport_assets` extrinsic + // Build expected message sent by the `teleport_assets` extrinsic to calculate delivery fees let context = ::UniversalLocation::get(); let assets_to_teleport: MultiAsset = (native_asset_id, native_asset_to_teleport_away.into()).into(); let assets_to_teleport = assets_to_teleport .reanchored(&dest, context).expect("We know location is invertible; qed"); let weight_limit = Limited(Weight::from_parts(161_592_000, 0)); - let mut expected_message = Xcm::<()>(vec![ + let expected_message = Xcm::<()>(vec![ ReceiveTeleportedAsset(assets_to_teleport.clone().into()), ClearOrigin, BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, - // Not real topic, used for calculating fees, will be dropped before checking real message SetTopic([0u8; 32]), ]); @@ -243,9 +242,6 @@ pub fn teleports_for_native_asset_works< >::price_for_parachain_delivery(other_para_id.into(), &expected_message); let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; - // Drop the topic before we check against real message - expected_message = Xcm::<()>(expected_message.inner()[..expected_message.len() - 1].into()); - assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -256,14 +252,6 @@ pub fn teleports_for_native_asset_works< &alice, )); - // Real xcm sent should match the expected - let mut real_xcm: Xcm::<()> = RuntimeHelper::< - ::OutboundXcmpMessageSource, - AllPalletsWithoutSystem - >::take_xcm(other_para_id.into()).unwrap().try_into().unwrap(); - real_xcm = Xcm::<()>(real_xcm.inner()[..real_xcm.len() - 1].into()); - assert_eq!(&expected_message, &real_xcm); - // check balances assert_eq!( >::free_balance(&target_account), @@ -571,7 +559,7 @@ pub fn teleports_for_foreign_assets_works< .into() ); - // Build expected message sent by the `teleport_assets` extrinsic + // Build expected message sent by the `teleport_assets` extrinsic to calculate delivery fees let context = ::UniversalLocation::get(); let assets_to_teleport: MultiAsset = (foreign_asset_id_multilocation, asset_to_teleport_away).into(); let assets_to_teleport = assets_to_teleport @@ -582,7 +570,6 @@ pub fn teleports_for_foreign_assets_works< ClearOrigin, BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, - // Not real topic, used for calculating fees, will be dropped before checking real message SetTopic([0u8; 32]), ]); @@ -593,9 +580,6 @@ pub fn teleports_for_foreign_assets_works< let Fungible(amount_to_mint) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible; qed") }; >::mint_into(&target_account, amount_to_mint.into()).unwrap(); - // Drop the topic before we check against real message - expected_message = Xcm::<()>(expected_message.inner()[..expected_message.len() - 1].into()); - assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -606,14 +590,6 @@ pub fn teleports_for_foreign_assets_works< &alice, )); - // Real xcm sent should match the expected - let mut real_xcm: Xcm::<()> = RuntimeHelper::< - ::OutboundXcmpMessageSource, - AllPalletsWithoutSystem - >::take_xcm(foreign_para_id.into()).unwrap().try_into().unwrap(); - real_xcm = Xcm::<()>(real_xcm.inner()[..real_xcm.len() - 1].into()); - assert_eq!(&expected_message, &real_xcm); - // check balances assert_eq!( >::balance( From 6c0e859f3acbffc79c49536d0803442d7dde1905 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 18 Sep 2023 13:34:34 -0300 Subject: [PATCH 058/116] Remove unnecessary mut --- cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 8046411ec820..bd780ff5d366 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -565,7 +565,7 @@ pub fn teleports_for_foreign_assets_works< let assets_to_teleport = assets_to_teleport .reanchored(&dest, context).expect("We know location is invertible; qed"); let weight_limit = Limited(Weight::from_parts(163_503_000, 0)); - let mut expected_message = Xcm::<()>(vec![ + let expected_message = Xcm::<()>(vec![ ReceiveTeleportedAsset(assets_to_teleport.clone().into()), ClearOrigin, BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, From 1a20dbb1cc4d4ea07a1cd66caad8a73f5dd2cb3a Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 18 Sep 2023 16:36:24 +0000 Subject: [PATCH 059/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../runtimes/assets/test-utils/src/test_cases.rs | 4 +++- polkadot/runtime/kusama/src/xcm_config.rs | 6 +++--- polkadot/runtime/rococo/src/xcm_config.rs | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index bd780ff5d366..8e6757568d87 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -18,7 +18,9 @@ use codec::Encode; use frame_support::{ assert_noop, assert_ok, - traits::{fungibles::InspectEnumerable, fungible::Mutate, Get, OnFinalize, OnInitialize, OriginTrait}, + traits::{ + fungible::Mutate, fungibles::InspectEnumerable, Get, OnFinalize, OnInitialize, OriginTrait, + }, weights::Weight, }; use frame_system::pallet_prelude::BlockNumberFor; diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs index e82d28e8e769..fb37b518ad70 100644 --- a/polkadot/runtime/kusama/src/xcm_config.rs +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -38,9 +38,9 @@ use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, - IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, + IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; parameter_types! { diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 1ed5fb163cac..6dae00436e53 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -36,10 +36,10 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, - ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, - IsConcrete, MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, - TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, - WithUniqueTopic, XcmFeesToAccount, + ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, + IsChildSystemParachain, IsConcrete, MintLocation, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::XcmExecutor; From ed5fd90be1675b35cf4ca41c7edbbca9fc77fa19 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 13:07:33 -0300 Subject: [PATCH 060/116] Fix asset-hub-kusama-integration-tests tests --- Cargo.lock | 3 + .../assets/asset-hub-kusama/Cargo.toml | 2 + .../assets/asset-hub-kusama/src/lib.rs | 2 +- .../src/tests/reserve_transfer.rs | 68 +++++++++++++++++-- .../assets/asset-hub-kusama/src/tests/swap.rs | 8 +++ .../asset-hub-kusama/src/tests/teleport.rs | 28 +++++++- .../emulated/common/Cargo.toml | 1 + .../emulated/common/src/xcm_helpers.rs | 28 ++++++-- .../assets/test-utils/src/test_cases.rs | 20 +++--- .../collectives-polkadot/src/xcm_config.rs | 3 +- cumulus/xcm/xcm-emulator/src/lib.rs | 6 +- 11 files changed, 142 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02600dc3e17c..e77cfd3cea55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,8 +710,10 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime", + "polkadot-runtime-common", "polkadot-runtime-parachains", "sp-runtime", + "staging-kusama-runtime", "staging-xcm", "xcm-emulator", ] @@ -6386,6 +6388,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime", + "polkadot-runtime-common", "polkadot-runtime-constants", "polkadot-runtime-parachains", "polkadot-service", diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml index 788b2482be87..c705877ca21b 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml @@ -23,7 +23,9 @@ pallet-asset-conversion = { path = "../../../../../../substrate/frame/asset-conv polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false} polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false} polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } +polkadot-runtime-common = { path = "../../../../../../polkadot/runtime/common" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } +kusama-runtime = { package = "staging-kusama-runtime", path = "../../../../../../polkadot/runtime/kusama" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs index ad74aa2301fc..c850381a9e8a 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs @@ -25,7 +25,7 @@ pub use integration_tests_common::{ asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, kusama::ED as KUSAMA_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, + xcm_helpers::{self, xcm_transact_paid_execution, xcm_transact_unpaid_execution}, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, Kusama, KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusamaA, PenpalKusamaAPallet, PenpalKusamaAReceiver, PenpalKusamaASender, PenpalKusamaB, PenpalKusamaBPallet, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs index 645dca5035b1..6462126ae3d4 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs @@ -14,12 +14,22 @@ // limitations under the License. use crate::*; +use kusama_runtime::xcm_config::{ + TreasuryAccount as KusamaTreasuryAccount, + PriceForChildParachainDelivery, +}; +use asset_hub_kusama_runtime::{ + PriceForSiblingParachainDelivery, + xcm_config::TreasuryAccount as AssetHubKusamaTreasuryAccount, +}; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(630_092_000, 6_196))); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + assert_expected_events!( Kusama, vec![ @@ -31,6 +41,16 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { ), amount: *amount == t.args.amount, }, + // Delivery fees are withdrawn from Sender + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => { + who: *who == t.sender.account_id, + amount: *amount == delivery_fees_amount, + }, + // Delivery fees are deposited to Treasury account + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, amount }) => { + who: *who == KusamaTreasuryAccount::get().unwrap(), + amount: *amount == delivery_fees_amount, + }, ] ); } @@ -54,6 +74,8 @@ fn system_para_to_para_assertions(t: SystemParaToParaTest) { 6_196, ))); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + assert_expected_events!( AssetHubKusama, vec![ @@ -67,6 +89,16 @@ fn system_para_to_para_assertions(t: SystemParaToParaTest) { ), amount: *amount == t.args.amount, }, + // Delivery fees are withdrawn from Sender + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => { + who: *who == t.sender.account_id, + amount: *amount == delivery_fees_amount, + }, + // Delivery fees are deposited to Treasury account + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, amount }) => { + who: *who == AssetHubKusamaTreasuryAccount::get().unwrap(), + amount: *amount == delivery_fees_amount, + }, ] ); } @@ -79,6 +111,8 @@ fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) { 6196, ))); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + assert_expected_events!( AssetHubKusama, vec![ @@ -93,6 +127,16 @@ fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) { ), amount: *amount == t.args.amount, }, + // Delivery fees are withdrawn from Sender + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => { + who: *who == t.sender.account_id, + amount: *amount == delivery_fees_amount, + }, + // Delivery fees are deposited to Treasury account + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, amount }) => { + who: *who == KusamaTreasuryAccount::get().unwrap(), + amount: *amount == delivery_fees_amount, + }, ] ); } @@ -185,7 +229,11 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = Kusama::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } @@ -244,7 +292,11 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = Kusama::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } @@ -306,7 +358,11 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubKusama::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } @@ -338,7 +394,11 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubKusama::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs index 3a67b5435828..707fb349ad0d 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs @@ -17,6 +17,7 @@ use crate::*; use frame_support::{instances::Instance2, BoundedVec}; use parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; use sp_runtime::{DispatchError, ModuleError}; +use asset_hub_kusama_runtime::AssetDeposit; #[test] fn swap_locally_on_chain_using_local_assets() { @@ -29,6 +30,13 @@ fn swap_locally_on_chain_using_local_assets() { AssetHubKusama::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + // Make sure account has enough to create an asset in `pallet_assets` + assert_ok!(::Balances::force_set_balance( + ::RuntimeOrigin::root(), + AssetHubKusamaSender::get().into(), + EXISTENTIAL_DEPOSIT + AssetDeposit::get(), + )); + assert_ok!(::Assets::create( ::RuntimeOrigin::signed(AssetHubKusamaSender::get()), ASSET_ID.into(), diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs index f69878f35435..f6cd83a3e1b7 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs @@ -16,12 +16,18 @@ #![allow(dead_code)] // use crate::*; +use kusama_runtime::xcm_config::{ + TreasuryAccount as KusamaTreasuryAccount, + PriceForChildParachainDelivery, +}; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + assert_expected_events!( Kusama, vec![ @@ -35,6 +41,16 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { who: *who == ::XcmPallet::check_account(), amount: *amount == t.args.amount, }, + // Delivery fees are withdrawn from Sender + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who, amount }) => { + who: *who == t.sender.account_id, + amount: *amount == delivery_fees_amount, + }, + // Delivery fees are deposited to Treasury account + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, amount }) => { + who: *who == KusamaTreasuryAccount::get().unwrap(), + amount: *amount == delivery_fees_amount, + }, ] ); } @@ -177,8 +193,12 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = Kusama::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -280,8 +300,12 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = Kusama::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } diff --git a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml index f1db26c2a540..437cf53104ea 100644 --- a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml @@ -32,6 +32,7 @@ polkadot-primitives = { path = "../../../../../polkadot/primitives", default-fea polkadot-runtime-parachains = { path = "../../../../../polkadot/runtime/parachains" } polkadot-runtime = { path = "../../../../../polkadot/runtime/polkadot" } polkadot-runtime-constants = { path = "../../../../../polkadot/runtime/polkadot/constants" } +polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common" } kusama-runtime = { package = "staging-kusama-runtime", path = "../../../../../polkadot/runtime/kusama" } kusama-runtime-constants = { path = "../../../../../polkadot/runtime/kusama/constants" } rococo-runtime = { path = "../../../../../polkadot/runtime/rococo" } diff --git a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs index 4096cdbba0b9..5a751f64ca96 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs @@ -16,13 +16,11 @@ use parachains_common::AccountId; use xcm::{ - prelude::{ - AccountId32, All, BuyExecution, DepositAsset, MultiAsset, MultiAssets, MultiLocation, - OriginKind, RefundSurplus, Transact, UnpaidExecution, VersionedXcm, Weight, WeightLimit, - WithdrawAsset, Xcm, X1, - }, + prelude::*, DoubleEncoded, }; +use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; +use xcm_emulator::TestArgs; /// Helper method to build a XCM with a `Transact` instruction and paying for its execution pub fn xcm_transact_paid_execution( @@ -64,3 +62,23 @@ pub fn xcm_transact_unpaid_execution( Transact { require_weight_at_most, origin_kind, call }, ])) } + +/// Returns the delivery fees amount for pallet xcm's `teleport_assets` and `reserve_transfer_assets` extrinsics. +pub fn transfer_assets_delivery_fees( + test_args: TestArgs, +) -> u128 { + // Approximation of the actual message sent by the extrinsic. + // The assets are not reanchored and the topic is a dummy one. + // However, it should have the same encoded size, which is what matters for delivery fees. + let message = Xcm(vec![ + ReceiveTeleportedAsset(test_args.assets.clone()), // Same encoded size as `ReserveAssetDeposited` + ClearOrigin, + BuyExecution { fees: test_args.assets.get(test_args.fee_asset_item as usize).unwrap().clone(), weight_limit: test_args.weight_limit }, + DepositAsset { assets: Wild(AllCounted(test_args.assets.len() as u32)), beneficiary: test_args.beneficiary }, + SetTopic([0u8; 32]), // Dummy topic + ]); + let Parachain(para_id) = test_args.dest.interior().last().unwrap() else { unreachable!("Location is parachain") }; + let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); + let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; + delivery_fees_amount +} diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 8e6757568d87..6efc23b6a81f 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -242,7 +242,7 @@ pub fn teleports_for_native_asset_works< let delivery_fees = < ::PriceForSiblingDelivery as PriceForParachainDelivery >::price_for_parachain_delivery(other_para_id.into(), &expected_message); - let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; + let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible; qed") }; assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), @@ -562,18 +562,16 @@ pub fn teleports_for_foreign_assets_works< ); // Build expected message sent by the `teleport_assets` extrinsic to calculate delivery fees - let context = ::UniversalLocation::get(); + let universal_location = ::UniversalLocation::get(); let assets_to_teleport: MultiAsset = (foreign_asset_id_multilocation, asset_to_teleport_away).into(); let assets_to_teleport = assets_to_teleport - .reanchored(&dest, context).expect("We know location is invertible; qed"); - let weight_limit = Limited(Weight::from_parts(163_503_000, 0)); - let expected_message = Xcm::<()>(vec![ - ReceiveTeleportedAsset(assets_to_teleport.clone().into()), - ClearOrigin, - BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, - DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, - SetTopic([0u8; 32]), - ]); + .reanchored(&dest, universal_location).expect("We know location is invertible; qed"); + let mut expected_message = >::get_teleport_assets_message( + assets_to_teleport.clone(), + assets_to_teleport.clone(), + dest_beneficiary, + None, + ); // Make sure the target account has enough native asset to pay for delivery fees let delivery_fees = < diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 914317be6755..7ecced56ca65 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -29,8 +29,9 @@ use parachains_common::{ xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; +use sp_runtime::traits::AccountIdConversion; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_constants::xcm::body::FELLOWSHIP_ADMIN_INDEX; +use polkadot_runtime_constants::{system_parachain::SystemParachains, xcm::body::FELLOWSHIP_ADMIN_INDEX}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index 9fda0632bae4..ea46d524abd2 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1332,10 +1332,10 @@ pub struct TestContext { pub args: T, } -/// Struct that help with tests where either dispatchables or assertions need +/// Struct that helps with tests where either dispatchables or assertions need /// to be reused. The struct keeps the test's arguments of your choice in the generic `Args`. -/// These arguments can be easily reused and shared between the assertions functions -/// and dispatchables functions, which are also stored in `Test`. +/// These arguments can be easily reused and shared between the assertion functions +/// and dispatchable functions, which are also stored in `Test`. /// `Origin` corresponds to the chain where the XCM interaction starts with an initial execution. /// `Destination` corresponds to the last chain where an effect of the intial execution is expected /// happen. `Hops` refer all the ordered intermediary chains an initial XCM execution can provoke From 1cfec4908e6ccc3428d6a2a4ec590366eb579e08 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 13:18:04 -0300 Subject: [PATCH 061/116] Fix asset-hub-westend-integration-tests tests --- .../emulated/assets/asset-hub-westend/src/lib.rs | 2 +- .../asset-hub-westend/src/tests/reserve_transfer.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs index 6e0f3434aedf..2cf7fa155de3 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs @@ -27,7 +27,7 @@ pub use integration_tests_common::{ asset_hub_westend::ED as ASSET_HUB_WESTEND_ED, westend::ED as WESTEND_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution, self}, AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender, PenpalWestendA, PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend, WestendPallet, WestendReceiver, WestendSender, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 51fac43be125..16995d4b6731 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -14,6 +14,7 @@ // limitations under the License. use crate::*; +use asset_hub_westend_runtime::PriceForSiblingParachainDelivery; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -306,7 +307,11 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubWestend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } @@ -338,7 +343,11 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubWestend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } From 59eb4fb5175e82890689560752a30638baaea8ff Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 13:32:07 -0300 Subject: [PATCH 062/116] Fix asset-hub-polkadot-integration-tests tests --- Cargo.lock | 2 +- .../assets/asset-hub-polkadot/Cargo.toml | 4 +-- .../assets/asset-hub-polkadot/src/lib.rs | 2 +- .../src/tests/reserve_transfer.rs | 26 ++++++++++++++++--- .../asset-hub-polkadot/src/tests/teleport.rs | 13 ++++++++-- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e77cfd3cea55..1ac9e2664437 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -795,7 +795,7 @@ dependencies = [ name = "asset-hub-polkadot-integration-tests" version = "1.0.0" dependencies = [ - "asset-hub-kusama-runtime", + "asset-hub-polkadot-runtime", "frame-support", "frame-system", "integration-tests-common", diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml index 023e8b84f11b..eb88abb7b2a2 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml @@ -28,7 +28,7 @@ pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-featu # Cumulus parachains-common = { path = "../../../../common" } -asset-hub-kusama-runtime = { path = "../../../../runtimes/assets/asset-hub-kusama" } +asset-hub-polkadot-runtime = { path = "../../../../runtimes/assets/asset-hub-polkadot" } # Local xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} @@ -36,7 +36,7 @@ integration-tests-common = { path = "../../common", default-features = false} [features] runtime-benchmarks = [ - "asset-hub-kusama-runtime/runtime-benchmarks", + "asset-hub-polkadot-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "integration-tests-common/runtime-benchmarks", diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs index e8ba8e44f25c..7e2b6b834060 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs @@ -25,7 +25,7 @@ pub use integration_tests_common::{ asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED, polkadot::ED as POLKADOT_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution, self}, AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender, PenpalPolkadotA, PenpalPolkadotAPallet, PenpalPolkadotAReceiver, PenpalPolkadotB, PenpalPolkadotBPallet, Polkadot, PolkadotPallet, PolkadotReceiver, PolkadotSender, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs index e53693d85d2b..0c9fdd5b167b 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs @@ -14,6 +14,8 @@ // limitations under the License. use crate::*; +use polkadot_runtime::xcm_config::PriceForChildParachainDelivery; +use asset_hub_polkadot_runtime::PriceForSiblingParachainDelivery; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -185,7 +187,11 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = Polkadot::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } @@ -244,7 +250,11 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = Polkadot::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } @@ -306,7 +316,11 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubPolkadot::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } @@ -338,7 +352,11 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubPolkadot::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs index 644c51d75b66..58900d76e774 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs @@ -16,6 +16,7 @@ #![allow(dead_code)] // use crate::*; +use polkadot_runtime::xcm_config::PriceForChildParachainDelivery; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -177,8 +178,12 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = Polkadot::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -280,8 +285,12 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = Polkadot::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } From b1b7ce88e58d99c1672ab87d93d376b76d3883b8 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 14:21:54 -0300 Subject: [PATCH 063/116] Refactor xcm helper to a common crate --- Cargo.lock | 3 + .../assets/asset-hub-kusama/Cargo.toml | 1 + .../assets/asset-hub-kusama/src/lib.rs | 3 +- .../src/tests/reserve_transfer.rs | 56 ++++++++++++++++--- .../asset-hub-kusama/src/tests/teleport.rs | 24 +++++++- .../assets/asset-hub-polkadot/Cargo.toml | 1 + .../assets/asset-hub-polkadot/src/lib.rs | 3 +- .../src/tests/reserve_transfer.rs | 32 +++++++++-- .../asset-hub-polkadot/src/tests/teleport.rs | 16 +++++- .../assets/asset-hub-westend/Cargo.toml | 1 + .../assets/asset-hub-westend/src/lib.rs | 3 +- .../src/tests/reserve_transfer.rs | 16 +++++- .../emulated/common/src/xcm_helpers.rs | 22 -------- .../runtimes/assets/test-utils/src/lib.rs | 1 + .../assets/test-utils/src/test_cases.rs | 26 ++++----- .../assets/test-utils/src/xcm_helpers.rs | 42 ++++++++++++++ 16 files changed, 191 insertions(+), 59 deletions(-) create mode 100644 cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs diff --git a/Cargo.lock b/Cargo.lock index 1ac9e2664437..e449ec258e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,6 +698,7 @@ version = "1.0.0" dependencies = [ "assert_matches", "asset-hub-kusama-runtime", + "asset-test-utils", "frame-support", "frame-system", "integration-tests-common", @@ -796,6 +797,7 @@ name = "asset-hub-polkadot-integration-tests" version = "1.0.0" dependencies = [ "asset-hub-polkadot-runtime", + "asset-test-utils", "frame-support", "frame-system", "integration-tests-common", @@ -889,6 +891,7 @@ version = "1.0.0" dependencies = [ "assert_matches", "asset-hub-westend-runtime", + "asset-test-utils", "frame-support", "frame-system", "integration-tests-common", diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml index c705877ca21b..7c45d4ba1f31 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml @@ -32,6 +32,7 @@ pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-featu # Cumulus parachains-common = { path = "../../../../common" } asset-hub-kusama-runtime = { path = "../../../../runtimes/assets/asset-hub-kusama" } +asset-test-utils = { path = "../../../../runtimes/assets/test-utils" } # Local xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs index c850381a9e8a..7d438d7e044f 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs @@ -25,11 +25,12 @@ pub use integration_tests_common::{ asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, kusama::ED as KUSAMA_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - xcm_helpers::{self, xcm_transact_paid_execution, xcm_transact_unpaid_execution}, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, Kusama, KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusamaA, PenpalKusamaAPallet, PenpalKusamaAReceiver, PenpalKusamaASender, PenpalKusamaB, PenpalKusamaBPallet, }; +pub use asset_test_utils::xcm_helpers; pub use parachains_common::{AccountId, Balance}; pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs index 6462126ae3d4..021062c0ffa5 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs @@ -28,7 +28,13 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(630_092_000, 6_196))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( Kusama, @@ -74,7 +80,13 @@ fn system_para_to_para_assertions(t: SystemParaToParaTest) { 6_196, ))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( AssetHubKusama, @@ -111,7 +123,13 @@ fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) { 6196, ))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( AssetHubKusama, @@ -230,7 +248,13 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -293,7 +317,13 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -359,7 +389,13 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -395,7 +431,13 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs index f6cd83a3e1b7..b1f4817acfa1 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs @@ -26,7 +26,13 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::(t.args.clone()); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( Kusama, @@ -194,7 +200,13 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); // Sender's balance is reduced @@ -301,7 +313,13 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml index eb88abb7b2a2..ee2839928f25 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml @@ -29,6 +29,7 @@ pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-featu # Cumulus parachains-common = { path = "../../../../common" } asset-hub-polkadot-runtime = { path = "../../../../runtimes/assets/asset-hub-polkadot" } +asset-test-utils = { path = "../../../../runtimes/assets/test-utils" } # Local xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs index 7e2b6b834060..62dd1b332770 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs @@ -25,11 +25,12 @@ pub use integration_tests_common::{ asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED, polkadot::ED as POLKADOT_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution, self}, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender, PenpalPolkadotA, PenpalPolkadotAPallet, PenpalPolkadotAReceiver, PenpalPolkadotB, PenpalPolkadotBPallet, Polkadot, PolkadotPallet, PolkadotReceiver, PolkadotSender, }; +pub use asset_test_utils::xcm_helpers; pub use parachains_common::{AccountId, Balance}; pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs index 0c9fdd5b167b..b270dd187d7d 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs @@ -188,7 +188,13 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -251,7 +257,13 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -317,7 +329,13 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -353,7 +371,13 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs index 58900d76e774..67a622031b6b 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs @@ -179,7 +179,13 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); // Sender's balance is reduced @@ -286,7 +292,13 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml index 80c41c24aa75..1bba515684f3 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml @@ -30,6 +30,7 @@ pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-featu # Cumulus parachains-common = { path = "../../../../common" } asset-hub-westend-runtime = { path = "../../../../runtimes/assets/asset-hub-westend" } +asset-test-utils = { path = "../../../../runtimes/assets/test-utils" } # Local xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs index 2cf7fa155de3..022903e0655a 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs @@ -27,11 +27,12 @@ pub use integration_tests_common::{ asset_hub_westend::ED as ASSET_HUB_WESTEND_ED, westend::ED as WESTEND_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution, self}, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender, PenpalWestendA, PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend, WestendPallet, WestendReceiver, WestendSender, }; +pub use asset_test_utils::xcm_helpers; pub use parachains_common::{AccountId, Balance}; pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 16995d4b6731..edf3d3e7a629 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -308,7 +308,13 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubWestend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -344,7 +350,13 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubWestend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::(test.args.clone()) + xcm_helpers::transfer_assets_delivery_fees::( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); diff --git a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs index 5a751f64ca96..527d8266b699 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs @@ -19,8 +19,6 @@ use xcm::{ prelude::*, DoubleEncoded, }; -use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; -use xcm_emulator::TestArgs; /// Helper method to build a XCM with a `Transact` instruction and paying for its execution pub fn xcm_transact_paid_execution( @@ -62,23 +60,3 @@ pub fn xcm_transact_unpaid_execution( Transact { require_weight_at_most, origin_kind, call }, ])) } - -/// Returns the delivery fees amount for pallet xcm's `teleport_assets` and `reserve_transfer_assets` extrinsics. -pub fn transfer_assets_delivery_fees( - test_args: TestArgs, -) -> u128 { - // Approximation of the actual message sent by the extrinsic. - // The assets are not reanchored and the topic is a dummy one. - // However, it should have the same encoded size, which is what matters for delivery fees. - let message = Xcm(vec![ - ReceiveTeleportedAsset(test_args.assets.clone()), // Same encoded size as `ReserveAssetDeposited` - ClearOrigin, - BuyExecution { fees: test_args.assets.get(test_args.fee_asset_item as usize).unwrap().clone(), weight_limit: test_args.weight_limit }, - DepositAsset { assets: Wild(AllCounted(test_args.assets.len() as u32)), beneficiary: test_args.beneficiary }, - SetTopic([0u8; 32]), // Dummy topic - ]); - let Parachain(para_id) = test_args.dest.interior().last().unwrap() else { unreachable!("Location is parachain") }; - let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); - let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; - delivery_fees_amount -} diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs b/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs index 7177726e0704..2eef506b259c 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs @@ -17,4 +17,5 @@ //! Module contains predefined test-case scenarios for `Runtime` with various assets. pub mod test_cases; +pub mod xcm_helpers; pub use parachains_runtimes_test_utils::*; diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 6efc23b6a81f..46b001ad4738 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -15,6 +15,7 @@ //! Module contains predefined test-case scenarios for `Runtime` with various assets. +use super::xcm_helpers; use codec::Encode; use frame_support::{ assert_noop, assert_ok, @@ -561,24 +562,17 @@ pub fn teleports_for_foreign_assets_works< .into() ); - // Build expected message sent by the `teleport_assets` extrinsic to calculate delivery fees - let universal_location = ::UniversalLocation::get(); - let assets_to_teleport: MultiAsset = (foreign_asset_id_multilocation, asset_to_teleport_away).into(); - let assets_to_teleport = assets_to_teleport - .reanchored(&dest, universal_location).expect("We know location is invertible; qed"); - let mut expected_message = >::get_teleport_assets_message( - assets_to_teleport.clone(), - assets_to_teleport.clone(), + // Make sure the target account has enough native asset to pay for delivery fees + let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< + ::PriceForSiblingDelivery + >( + (foreign_asset_id_multilocation, asset_to_teleport_away).into(), + 0, + Unlimited, dest_beneficiary, - None, + dest, ); - - // Make sure the target account has enough native asset to pay for delivery fees - let delivery_fees = < - ::PriceForSiblingDelivery as PriceForParachainDelivery - >::price_for_parachain_delivery(foreign_para_id.into(), &expected_message); - let Fungible(amount_to_mint) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible; qed") }; - >::mint_into(&target_account, amount_to_mint.into()).unwrap(); + >::mint_into(&target_account, delivery_fees.into()).unwrap(); assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs new file mode 100644 index 000000000000..9903ec5ffbab --- /dev/null +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -0,0 +1,42 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; +use xcm::latest::prelude::*; + +/// Returns the delivery fees amount for pallet xcm's `teleport_assets` and `reserve_transfer_assets` extrinsics. +pub fn transfer_assets_delivery_fees( + assets: MultiAssets, + fee_asset_item: u32, + weight_limit: WeightLimit, + beneficiary: MultiLocation, + destination: MultiLocation, +) -> u128 { + // Approximation of the actual message sent by the extrinsic. + // The assets are not reanchored and the topic is a dummy one. + // However, it should have the same encoded size, which is what matters for delivery fees. + let message = Xcm(vec![ + ReceiveTeleportedAsset(assets.clone()), // Same encoded size as `ReserveAssetDeposited` + ClearOrigin, + BuyExecution { fees: assets.get(fee_asset_item as usize).unwrap().clone(), weight_limit }, + DepositAsset { assets: Wild(AllCounted(assets.len() as u32)), beneficiary }, + SetTopic([0u8; 32]), // Dummy topic + ]); + let Parachain(para_id) = destination.interior().last().unwrap() else { unreachable!("Location is parachain") }; + let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); + let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; + delivery_fees_amount +} From a71219a296a1d0a00ee33f9e133cdd6a5d0cdb01 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 14:41:02 -0300 Subject: [PATCH 064/116] Fix feature propagation --- .../emulated/assets/asset-hub-kusama/Cargo.toml | 4 +++- .../parachains/integration-tests/emulated/common/Cargo.toml | 1 + polkadot/runtime/common/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml index 7c45d4ba1f31..be798a4e2335 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml @@ -22,8 +22,8 @@ pallet-asset-conversion = { path = "../../../../../../substrate/frame/asset-conv # Polkadot polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false} polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false} -polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } polkadot-runtime-common = { path = "../../../../../../polkadot/runtime/common" } +polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } kusama-runtime = { package = "staging-kusama-runtime", path = "../../../../../../polkadot/runtime/kusama" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} @@ -52,5 +52,7 @@ runtime-benchmarks = [ "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "kusama-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] diff --git a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml index 437cf53104ea..fc9d472006c4 100644 --- a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml @@ -87,6 +87,7 @@ runtime-benchmarks = [ "polkadot-primitives/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", "polkadot-service/runtime-benchmarks", "rococo-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 1e7d8d50634d..4e2f0c692fc6 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -125,7 +125,7 @@ runtime-benchmarks = [ "runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", - "xcm-executor", + "xcm-executor/runtime-benchmarks", ] try-runtime = [ "frame-election-provider-support/try-runtime", From c4fe1acfe05a7c8d2092abc9da0d4c9a194274d5 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 26 Sep 2023 17:43:57 +0000 Subject: [PATCH 065/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../assets/asset-hub-kusama/src/lib.rs | 2 +- .../src/tests/reserve_transfer.rs | 55 ++++++++++--------- .../assets/asset-hub-kusama/src/tests/swap.rs | 2 +- .../asset-hub-kusama/src/tests/teleport.rs | 18 +++--- .../assets/asset-hub-polkadot/src/lib.rs | 2 +- .../src/tests/reserve_transfer.rs | 2 +- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../emulated/common/src/xcm_helpers.rs | 5 +- .../assets/test-utils/src/test_cases.rs | 8 ++- .../assets/test-utils/src/xcm_helpers.rs | 3 +- .../collectives-polkadot/src/xcm_config.rs | 14 +++-- 11 files changed, 59 insertions(+), 54 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs index 7d438d7e044f..4f875c8e40ff 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub use asset_test_utils::xcm_helpers; pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, @@ -30,7 +31,6 @@ pub use integration_tests_common::{ KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusamaA, PenpalKusamaAPallet, PenpalKusamaAReceiver, PenpalKusamaASender, PenpalKusamaB, PenpalKusamaBPallet, }; -pub use asset_test_utils::xcm_helpers; pub use parachains_common::{AccountId, Balance}; pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs index 021062c0ffa5..331e227ad19d 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs @@ -14,13 +14,11 @@ // limitations under the License. use crate::*; -use kusama_runtime::xcm_config::{ - TreasuryAccount as KusamaTreasuryAccount, - PriceForChildParachainDelivery, -}; use asset_hub_kusama_runtime::{ - PriceForSiblingParachainDelivery, - xcm_config::TreasuryAccount as AssetHubKusamaTreasuryAccount, + xcm_config::TreasuryAccount as AssetHubKusamaTreasuryAccount, PriceForSiblingParachainDelivery, +}; +use kusama_runtime::xcm_config::{ + PriceForChildParachainDelivery, TreasuryAccount as KusamaTreasuryAccount, }; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -28,13 +26,14 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(630_092_000, 6_196))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + let delivery_fees_amount = + xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( Kusama, @@ -80,13 +79,14 @@ fn system_para_to_para_assertions(t: SystemParaToParaTest) { 6_196, ))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + let delivery_fees_amount = + xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( AssetHubKusama, @@ -123,13 +123,14 @@ fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) { 6196, ))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + let delivery_fees_amount = + xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( AssetHubKusama, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs index 707fb349ad0d..df7d2e44478c 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/swap.rs @@ -14,10 +14,10 @@ // limitations under the License. use crate::*; +use asset_hub_kusama_runtime::AssetDeposit; use frame_support::{instances::Instance2, BoundedVec}; use parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; use sp_runtime::{DispatchError, ModuleError}; -use asset_hub_kusama_runtime::AssetDeposit; #[test] fn swap_locally_on_chain_using_local_assets() { diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs index b1f4817acfa1..7bcae88915cc 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs @@ -17,8 +17,7 @@ use crate::*; use kusama_runtime::xcm_config::{ - TreasuryAccount as KusamaTreasuryAccount, - PriceForChildParachainDelivery, + PriceForChildParachainDelivery, TreasuryAccount as KusamaTreasuryAccount, }; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -26,13 +25,14 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); - let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + let delivery_fees_amount = + xcm_helpers::transfer_assets_delivery_fees::( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( Kusama, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs index 62dd1b332770..fe0d614025b0 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub use asset_test_utils::xcm_helpers; pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, @@ -30,7 +31,6 @@ pub use integration_tests_common::{ PenpalPolkadotA, PenpalPolkadotAPallet, PenpalPolkadotAReceiver, PenpalPolkadotB, PenpalPolkadotBPallet, Polkadot, PolkadotPallet, PolkadotReceiver, PolkadotSender, }; -pub use asset_test_utils::xcm_helpers; pub use parachains_common::{AccountId, Balance}; pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs index b270dd187d7d..9b1df387f97e 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs @@ -14,8 +14,8 @@ // limitations under the License. use crate::*; -use polkadot_runtime::xcm_config::PriceForChildParachainDelivery; use asset_hub_polkadot_runtime::PriceForSiblingParachainDelivery; +use polkadot_runtime::xcm_config::PriceForChildParachainDelivery; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs index 022903e0655a..a585996c8a4d 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub use asset_test_utils::xcm_helpers; pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, @@ -32,7 +33,6 @@ pub use integration_tests_common::{ PenpalWestendA, PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend, WestendPallet, WestendReceiver, WestendSender, }; -pub use asset_test_utils::xcm_helpers; pub use parachains_common::{AccountId, Balance}; pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, diff --git a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs index 527d8266b699..670eaa383c3d 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs @@ -15,10 +15,7 @@ // along with Cumulus. If not, see . use parachains_common::AccountId; -use xcm::{ - prelude::*, - DoubleEncoded, -}; +use xcm::{prelude::*, DoubleEncoded}; /// Helper method to build a XCM with a `Transact` instruction and paying for its execution pub fn xcm_transact_paid_execution( diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 46b001ad4738..fa8e75d3d88f 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -564,7 +564,7 @@ pub fn teleports_for_foreign_assets_works< // Make sure the target account has enough native asset to pay for delivery fees let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< - ::PriceForSiblingDelivery + ::PriceForSiblingDelivery, >( (foreign_asset_id_multilocation, asset_to_teleport_away).into(), 0, @@ -572,7 +572,11 @@ pub fn teleports_for_foreign_assets_works< dest_beneficiary, dest, ); - >::mint_into(&target_account, delivery_fees.into()).unwrap(); + >::mint_into( + &target_account, + delivery_fees.into(), + ) + .unwrap(); assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs index 9903ec5ffbab..004adcea3214 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -17,7 +17,8 @@ use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; use xcm::latest::prelude::*; -/// Returns the delivery fees amount for pallet xcm's `teleport_assets` and `reserve_transfer_assets` extrinsics. +/// Returns the delivery fees amount for pallet xcm's `teleport_assets` and +/// `reserve_transfer_assets` extrinsics. pub fn transfer_assets_delivery_fees( assets: MultiAssets, fee_asset_item: u32, diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 7ecced56ca65..d2d667fe85ae 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -29,18 +29,20 @@ use parachains_common::{ xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; -use sp_runtime::traits::AccountIdConversion; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_constants::{system_parachain::SystemParachains, xcm::body::FELLOWSHIP_ADMIN_INDEX}; +use polkadot_runtime_constants::{ + system_parachain::SystemParachains, xcm::body::FELLOWSHIP_ADMIN_INDEX, +}; +use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, IsConcrete, - LocatableAssetId, OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, + LocatableAssetId, OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; From f94fc1d018c74924a0ceab9f9fb63f35dc3e4fc1 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 15:02:34 -0300 Subject: [PATCH 066/116] Fix feature propagation for std --- cumulus/parachains/common/Cargo.toml | 1 + .../assets/test-utils/src/test_cases.rs | 30 +++++++------------ polkadot/runtime/common/Cargo.toml | 2 ++ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/cumulus/parachains/common/Cargo.toml b/cumulus/parachains/common/Cargo.toml index 09925a92f396..23f495dc5110 100644 --- a/cumulus/parachains/common/Cargo.toml +++ b/cumulus/parachains/common/Cargo.toml @@ -79,6 +79,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "parachain-info/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index fa8e75d3d88f..ff0299195c5b 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -225,26 +225,6 @@ pub fn teleports_for_native_asset_works< target_account_balance_before_teleport - existential_deposit ); - // Build expected message sent by the `teleport_assets` extrinsic to calculate delivery fees - let context = ::UniversalLocation::get(); - let assets_to_teleport: MultiAsset = (native_asset_id, native_asset_to_teleport_away.into()).into(); - let assets_to_teleport = assets_to_teleport - .reanchored(&dest, context).expect("We know location is invertible; qed"); - let weight_limit = Limited(Weight::from_parts(161_592_000, 0)); - let expected_message = Xcm::<()>(vec![ - ReceiveTeleportedAsset(assets_to_teleport.clone().into()), - ClearOrigin, - BuyExecution { fees: assets_to_teleport.clone().into(), weight_limit }, - DepositAsset { assets: Wild(AllCounted(1)), beneficiary: dest_beneficiary }, - SetTopic([0u8; 32]), - ]); - - // Make sure the target account has enough native asset to pay for delivery fees - let delivery_fees = < - ::PriceForSiblingDelivery as PriceForParachainDelivery - >::price_for_parachain_delivery(other_para_id.into(), &expected_message); - let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible; qed") }; - assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -255,6 +235,16 @@ pub fn teleports_for_native_asset_works< &alice, )); + let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< + ::PriceForSiblingDelivery + >( + (native_asset_id, native_asset_to_teleport_away.into()).into(), + 0, + Unlimited, + dest_beneficiary, + dest, + ); + // check balances assert_eq!( >::free_balance(&target_account), diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 4e2f0c692fc6..4fc78af817da 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -104,6 +104,8 @@ std = [ "sp-staking/std", "sp-std/std", "xcm/std", + "pallet-xcm-benchmarks/std", + "xcm-executor/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", From b555e59036aa0997d5af3a154d30db15a36891c6 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 15:04:57 -0300 Subject: [PATCH 067/116] Fixes --- .../parachains/runtimes/assets/test-utils/src/test_cases.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index ff0299195c5b..28c7332fa424 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -30,7 +30,6 @@ use parachains_runtimes_test_utils::{ assert_metadata, assert_total, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, ValidatorIdOf, XcmReceivedFrom, }; -use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; use sp_runtime::{ traits::{MaybeEquivalence, StaticLookup, Zero}, DispatchError, Saturating, @@ -248,7 +247,7 @@ pub fn teleports_for_native_asset_works< // check balances assert_eq!( >::free_balance(&target_account), - target_account_balance_before_teleport - native_asset_to_teleport_away - delivery_fees_amount.into() + target_account_balance_before_teleport - native_asset_to_teleport_away - delivery_fees.into() ); assert_eq!( >::free_balance(&CheckingAccount::get()), From 79d8020a1e4b07644cdc159fe3a75cbb374f42e9 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 15:08:50 -0300 Subject: [PATCH 068/116] Format features --- cumulus/parachains/common/Cargo.toml | 2 +- .../emulated/assets/asset-hub-kusama/Cargo.toml | 4 ++-- .../parachains/integration-tests/emulated/common/Cargo.toml | 2 +- polkadot/runtime/common/Cargo.toml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/common/Cargo.toml b/cumulus/parachains/common/Cargo.toml index 23f495dc5110..e41dea941a7b 100644 --- a/cumulus/parachains/common/Cargo.toml +++ b/cumulus/parachains/common/Cargo.toml @@ -66,6 +66,7 @@ std = [ "pallet-authorship/std", "pallet-balances/std", "pallet-collator-selection/std", + "parachain-info/std", "polkadot-core-primitives/std", "polkadot-primitives/std", "polkadot-runtime-constants/std", @@ -79,7 +80,6 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "parachain-info/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml index be798a4e2335..0cb1b469ce37 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml @@ -44,15 +44,15 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "integration-tests-common/runtime-benchmarks", + "kusama-runtime/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "kusama-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] diff --git a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml index fc9d472006c4..aab55a33e7f3 100644 --- a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml @@ -85,9 +85,9 @@ runtime-benchmarks = [ "penpal-runtime/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", "polkadot-service/runtime-benchmarks", "rococo-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 4fc78af817da..23cf1a67d951 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -88,6 +88,7 @@ std = [ "pallet-transaction-payment/std", "pallet-treasury/std", "pallet-vesting/std", + "pallet-xcm-benchmarks/std", "parity-scale-codec/std", "primitives/std", "runtime-parachains/std", @@ -103,9 +104,8 @@ std = [ "sp-session/std", "sp-staking/std", "sp-std/std", - "xcm/std", - "pallet-xcm-benchmarks/std", "xcm-executor/std", + "xcm/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", From 64afc86b251d096e8e532e36327218f202d643d5 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 26 Sep 2023 18:10:19 +0000 Subject: [PATCH 069/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../parachains/runtimes/assets/test-utils/src/test_cases.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 28c7332fa424..c2ec5401e795 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -235,7 +235,7 @@ pub fn teleports_for_native_asset_works< )); let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< - ::PriceForSiblingDelivery + ::PriceForSiblingDelivery, >( (native_asset_id, native_asset_to_teleport_away.into()).into(), 0, @@ -247,7 +247,9 @@ pub fn teleports_for_native_asset_works< // check balances assert_eq!( >::free_balance(&target_account), - target_account_balance_before_teleport - native_asset_to_teleport_away - delivery_fees.into() + target_account_balance_before_teleport - + native_asset_to_teleport_away - + delivery_fees.into() ); assert_eq!( >::free_balance(&CheckingAccount::get()), From 797ef3964fe4301bc2bbe2b3016fc2ff974f1b5c Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 15:36:23 -0300 Subject: [PATCH 070/116] Fix tests with runtime-benchmarks --- cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 1 + cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs | 1 + cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index d1dc0358042d..3f6ce1e248fa 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -1223,6 +1223,7 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::{KsmLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; + use cumulus_primitives_core::ParaId; parameter_types! { pub ExistentialDepositMultiAsset: Option = Some(( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index 60ec8afc5106..8d59e38805c3 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -1099,6 +1099,7 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::{DotLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; + use cumulus_primitives_core::ParaId; parameter_types! { pub ExistentialDepositMultiAsset: Option = Some(( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 3a424d65c753..7627379b2cb8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1237,6 +1237,7 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::{MaxAssetsIntoHolding, WestendLocation}; use pallet_xcm_benchmarks::asset_instance_from; + use cumulus_primitives_core::ParaId; parameter_types! { pub ExistentialDepositMultiAsset: Option = Some(( From 7e85258f52176996c22331fdbbb0c8d1d8609342 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 26 Sep 2023 16:50:50 -0300 Subject: [PATCH 071/116] Fix pallet-xcm tests --- polkadot/xcm/pallet-xcm/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/xcm/pallet-xcm/src/tests.rs b/polkadot/xcm/pallet-xcm/src/tests.rs index 55bf7462e4e0..d267eece2c04 100644 --- a/polkadot/xcm/pallet-xcm/src/tests.rs +++ b/polkadot/xcm/pallet-xcm/src/tests.rs @@ -576,7 +576,7 @@ fn reserve_transfer_assets_with_paid_router_works() { Xcm(vec![ ReserveAssetDeposited((Parent, SEND_AMOUNT).into()), ClearOrigin, - buy_limited_execution((Parent, SEND_AMOUNT), Weight::from_parts(4000, 4000)), + buy_execution((Parent, SEND_AMOUNT)), DepositAsset { assets: AllCounted(1).into(), beneficiary: dest }, ]), )] From 792f197147f84f6a98525dad0061865ee6d7bf5a Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 06:59:47 -0300 Subject: [PATCH 072/116] Fix polkadot-collectives and bridge-hub-rococo tests --- Cargo.lock | 2 ++ .../collectives-polkadot/Cargo.toml | 2 ++ .../collectives-polkadot/src/lib.rs | 2 ++ .../src/tests/fellowship.rs | 28 +++++++++++++------ .../collectives-polkadot/src/xcm_helpers.rs | 20 +++++++++++++ .../assets/test-utils/src/xcm_helpers.rs | 1 + .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 18 ++++++++++-- .../bridge-hub-polkadot/src/lib.rs | 18 ++++++++++-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 17 ++++++++++- .../collectives-polkadot/src/lib.rs | 1 + polkadot/xcm/xcm-builder/src/pay.rs | 13 +++++---- 11 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs diff --git a/Cargo.lock b/Cargo.lock index c6c8ac47e5b1..d20a9e40715f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2564,6 +2564,7 @@ dependencies = [ name = "collectives-polkadot-integration-tests" version = "0.1.0" dependencies = [ + "asset-hub-polkadot-runtime", "collectives-polkadot-runtime", "cumulus-pallet-parachain-system", "cumulus-pallet-xcmp-queue", @@ -2579,6 +2580,7 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime", + "polkadot-runtime-common", "polkadot-runtime-parachains", "sp-core", "sp-runtime", diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml index 99caccc81590..2700f0022a08 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml @@ -23,6 +23,7 @@ pallet-salary = { path = "../../../../../../substrate/frame/salary", default-fea polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false} polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false} polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } +polkadot-runtime-common = { path = "../../../../../../polkadot/runtime/common" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} @@ -32,6 +33,7 @@ parachains-common = { path = "../../../../common" } cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false} cumulus-pallet-parachain-system = { path = "../../../../../pallets/parachain-system" } collectives-polkadot-runtime = { path = "../../../../runtimes/collectives/collectives-polkadot" } +asset-hub-polkadot-runtime = { path = "../../../../runtimes/assets/asset-hub-polkadot" } # Local xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs index aa716c7c9485..3e99ca6787a8 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs @@ -34,6 +34,8 @@ pub use xcm_emulator::{ RelayChain as Relay, Test, TestArgs, TestContext, TestExt, TestExternalities, }; +pub mod xcm_helpers; + pub const ASSET_ID: u32 = 1; pub const ASSET_MIN_BALANCE: u128 = 1000; pub const ASSETS_PALLET_ID: u8 = 50; diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs index c08a660205f6..21f5116c8a4c 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs @@ -17,8 +17,13 @@ use crate::*; use collectives_polkadot_runtime::fellowship::FellowshipSalaryPaymaster; +use integration_tests_common::constants::{collectives, asset_hub_polkadot}; +use asset_hub_polkadot_runtime::{ + PriceForSiblingParachainDelivery as AssetHubPolkadotPriceForParachainDelivery, +}; use frame_support::traits::{ fungibles::{Create, Mutate}, + fungible, tokens::Pay, }; use sp_core::crypto::Ss58Codec; @@ -34,6 +39,7 @@ fn pay_salary() { let pay_amount = 9000; AssetHubPolkadot::execute_with(|| { + type AssetHubBalances = ::Balances; type AssetHubAssets = ::Assets; assert_ok!(>::create( @@ -42,6 +48,10 @@ fn pay_salary() { true, pay_amount / 2 )); + // Make sure we have enough assets for delivery + let querier = (Parent, Parachain(collectives::PARA_ID)).into(); + let delivery_fees = xcm_helpers::query_response_delivery_fees::(querier); + assert_ok!(>::mint_into(&pay_from, delivery_fees + asset_hub_polkadot::ED)); assert_ok!(>::mint_into(asset_id, &pay_from, pay_amount * 2)); }); @@ -59,17 +69,19 @@ fn pay_salary() { AssetHubPolkadot::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( AssetHubPolkadot, vec![ - RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => - { asset_id: id == &asset_id, - from: from == &pay_from, - to: to == &pay_to, - amount: amount == &pay_amount, - }, - RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, - ] + RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => + { + asset_id: id == &asset_id, + from: from == &pay_from, + to: to == &pay_to, + amount: amount == &pay_amount, + }, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, + ] ); }); } diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs new file mode 100644 index 000000000000..3b03b1bcafdb --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs @@ -0,0 +1,20 @@ +use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; +use xcm::latest::prelude::*; + +pub fn query_response_delivery_fees(querier: MultiLocation) -> u128 { + // Message to calculate delivery fees, it's encoded size is what's important. + // This message reports that there was no error, if an error is reported, the encoded size would be different. + let message = Xcm(vec![ + QueryResponse { + query_id: 0, // Dummy query id + response: Response::ExecutionResult(None), + max_weight: Weight::zero(), + querier: Some(querier), + }, + SetTopic([0u8; 32]), // Dummy topic + ]); + let Parachain(para_id) = querier.interior().last().unwrap() else { unreachable!("Location is parachain") }; + let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); + let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; + delivery_fees_amount +} diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs index 004adcea3214..0dc7b27bd48c 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -38,6 +38,7 @@ pub fn transfer_assets_delivery_fees( ]); let Parachain(para_id) = destination.interior().last().unwrap() else { unreachable!("Location is parachain") }; let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); + dbg!(&delivery_fees); let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; delivery_fees_amount } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 67d407f28646..001a57cdc28c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -74,7 +74,7 @@ use parachains_common::{ }; // XCM Imports -use xcm::latest::prelude::BodyId; +use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; /// The address format for describing accounts. @@ -304,6 +304,20 @@ pub type RootOrFellows = EitherOfDiverse< EnsureXcm>, >; +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::KsmRelayLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -313,7 +327,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = RootOrFellows; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 10f463c36316..2b53fa5203f2 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -74,7 +74,7 @@ use parachains_common::{ HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; // XCM Imports -use xcm::latest::prelude::BodyId; +use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; /// The address format for describing accounts. @@ -304,6 +304,20 @@ pub type RootOrFellows = EitherOfDiverse< EnsureXcm>, >; +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::DotRelayLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -313,7 +327,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = RootOrFellows; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 561766b18145..f1805f0d33c6 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -65,6 +65,7 @@ use bp_runtime::HeaderId; pub use sp_runtime::BuildStorage; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; +use xcm::latest::prelude::*; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -310,6 +311,20 @@ impl parachain_info::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {} +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::RelayLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -319,7 +334,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index d833c75d470c..f2b0230de945 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -409,6 +409,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EitherOfDiverse, Fellows>; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; + // TODO: This should have the price set, but then why is it failing?? type PriceForSiblingDelivery = (); } diff --git a/polkadot/xcm/xcm-builder/src/pay.rs b/polkadot/xcm/xcm-builder/src/pay.rs index 0f3a622f4ece..4c9b9a6088de 100644 --- a/polkadot/xcm/xcm-builder/src/pay.rs +++ b/polkadot/xcm/xcm-builder/src/pay.rs @@ -110,11 +110,14 @@ impl< let message = Xcm(vec![ DescendOrigin(Interior::get()), UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - SetAppendix(Xcm(vec![ReportError(QueryResponseInfo { - destination, - query_id, - max_weight: Weight::zero(), - })])), + SetAppendix(Xcm(vec![ + SetFeesMode { jit_withdraw: true }, + ReportError(QueryResponseInfo { + destination, + query_id, + max_weight: Weight::zero(), + }), + ])), TransferAsset { beneficiary, assets: vec![MultiAsset { id: asset_id, fun: Fungibility::Fungible(amount) }] From 0c5980fec48137e18fc2240545b2fb8f68ef2ff5 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 07:01:54 -0300 Subject: [PATCH 073/116] Fix license issue --- .../collectives-polkadot/src/xcm_helpers.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs index 3b03b1bcafdb..60ab4b0233c8 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs @@ -1,3 +1,21 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! XCM helpers for getting delivery fees for tests + use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; use xcm::latest::prelude::*; From 72718fd4686f67e37be618b18cecb9c311eff179 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 07:11:47 -0300 Subject: [PATCH 074/116] Remove dbg --- cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs index 0dc7b27bd48c..004adcea3214 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -38,7 +38,6 @@ pub fn transfer_assets_delivery_fees( ]); let Parachain(para_id) = destination.interior().last().unwrap() else { unreachable!("Location is parachain") }; let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); - dbg!(&delivery_fees); let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; delivery_fees_amount } From 3af762451258e700e8c2f21298d3c970aeb9b60f Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 08:16:14 -0300 Subject: [PATCH 075/116] Change xcm delivery fee helpers to work with UMP --- .../src/tests/reserve_transfer.rs | 20 +++++------ .../asset-hub-kusama/src/tests/teleport.rs | 8 ++--- .../src/tests/reserve_transfer.rs | 12 +++---- .../asset-hub-polkadot/src/tests/teleport.rs | 6 ++-- .../src/tests/reserve_transfer.rs | 6 ++-- .../collectives-polkadot/Cargo.toml | 1 - .../src/tests/fellowship.rs | 6 ++-- .../collectives-polkadot/src/xcm_helpers.rs | 6 ++-- .../runtimes/assets/test-utils/Cargo.toml | 2 -- .../assets/test-utils/src/test_cases.rs | 21 ++++++++++-- .../assets/test-utils/src/xcm_helpers.rs | 33 ++++++++++++------- 11 files changed, 71 insertions(+), 50 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs index 331e227ad19d..160415e11ffd 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs @@ -14,11 +14,11 @@ // limitations under the License. use crate::*; -use asset_hub_kusama_runtime::{ - xcm_config::TreasuryAccount as AssetHubKusamaTreasuryAccount, PriceForSiblingParachainDelivery, +use asset_hub_kusama_runtime::xcm_config::{ + TreasuryAccount as AssetHubKusamaTreasuryAccount, XcmConfig as AssetHubKusamaXcmConfig, }; use kusama_runtime::xcm_config::{ - PriceForChildParachainDelivery, TreasuryAccount as KusamaTreasuryAccount, + XcmConfig as KusamaXcmConfig, TreasuryAccount as KusamaTreasuryAccount, }; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -27,7 +27,7 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(630_092_000, 6_196))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( t.args.assets.clone(), 0, t.args.weight_limit, @@ -80,7 +80,7 @@ fn system_para_to_para_assertions(t: SystemParaToParaTest) { ))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( t.args.assets.clone(), 0, t.args.weight_limit, @@ -124,7 +124,7 @@ fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) { ))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( t.args.assets.clone(), 0, t.args.weight_limit, @@ -249,7 +249,7 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -318,7 +318,7 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -390,7 +390,7 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -432,7 +432,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs index 7bcae88915cc..ace58cbed663 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs @@ -17,7 +17,7 @@ use crate::*; use kusama_runtime::xcm_config::{ - PriceForChildParachainDelivery, TreasuryAccount as KusamaTreasuryAccount, + XcmConfig, TreasuryAccount as KusamaTreasuryAccount, }; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -26,7 +26,7 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( t.args.assets.clone(), 0, t.args.weight_limit, @@ -200,7 +200,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -313,7 +313,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs index 9b1df387f97e..7a664cafd9a5 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs @@ -14,8 +14,8 @@ // limitations under the License. use crate::*; -use asset_hub_polkadot_runtime::PriceForSiblingParachainDelivery; -use polkadot_runtime::xcm_config::PriceForChildParachainDelivery; +use asset_hub_polkadot_runtime::xcm_config::XcmConfig as AssetHubPolkadotXcmConfig; +use polkadot_runtime::xcm_config::XcmConfig as PolkadotXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -188,7 +188,7 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -257,7 +257,7 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -329,7 +329,7 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -371,7 +371,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs index 67a622031b6b..43702c9424c1 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs @@ -16,7 +16,7 @@ #![allow(dead_code)] // use crate::*; -use polkadot_runtime::xcm_config::PriceForChildParachainDelivery; +use polkadot_runtime::xcm_config::XcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -179,7 +179,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -292,7 +292,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs index edf3d3e7a629..66e5cc9b72a4 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -14,7 +14,7 @@ // limitations under the License. use crate::*; -use asset_hub_westend_runtime::PriceForSiblingParachainDelivery; +use asset_hub_westend_runtime::xcm_config::XcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -308,7 +308,7 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubWestend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, @@ -350,7 +350,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubWestend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml index 2700f0022a08..10801f409322 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml @@ -23,7 +23,6 @@ pallet-salary = { path = "../../../../../../substrate/frame/salary", default-fea polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false} polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false} polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } -polkadot-runtime-common = { path = "../../../../../../polkadot/runtime/common" } polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs index 21f5116c8a4c..0c51585c840d 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs @@ -18,9 +18,7 @@ use crate::*; use collectives_polkadot_runtime::fellowship::FellowshipSalaryPaymaster; use integration_tests_common::constants::{collectives, asset_hub_polkadot}; -use asset_hub_polkadot_runtime::{ - PriceForSiblingParachainDelivery as AssetHubPolkadotPriceForParachainDelivery, -}; +use asset_hub_polkadot_runtime::xcm_config::XcmConfig as AssetHubPolkadotXcmConfig; use frame_support::traits::{ fungibles::{Create, Mutate}, fungible, @@ -50,7 +48,7 @@ fn pay_salary() { )); // Make sure we have enough assets for delivery let querier = (Parent, Parachain(collectives::PARA_ID)).into(); - let delivery_fees = xcm_helpers::query_response_delivery_fees::(querier); + let delivery_fees = xcm_helpers::query_response_delivery_fees::(querier); assert_ok!(>::mint_into(&pay_from, delivery_fees + asset_hub_polkadot::ED)); assert_ok!(>::mint_into(asset_id, &pay_from, pay_amount * 2)); }); diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs index 60ab4b0233c8..0d41052f7044 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs @@ -16,10 +16,9 @@ //! XCM helpers for getting delivery fees for tests -use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; use xcm::latest::prelude::*; -pub fn query_response_delivery_fees(querier: MultiLocation) -> u128 { +pub fn query_response_delivery_fees(querier: MultiLocation) -> u128 { // Message to calculate delivery fees, it's encoded size is what's important. // This message reports that there was no error, if an error is reported, the encoded size would be different. let message = Xcm(vec![ @@ -31,8 +30,7 @@ pub fn query_response_delivery_fees(querier: Multi }, SetTopic([0u8; 32]), // Dummy topic ]); - let Parachain(para_id) = querier.interior().last().unwrap() else { unreachable!("Location is parachain") }; - let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); + let Ok((_, delivery_fees)) = validate_send::(querier, message) else { unreachable!("message can be sent; qed") }; let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; delivery_fees_amount } diff --git a/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml b/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml index db4e4a11e759..2ec0162f2aef 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml @@ -38,7 +38,6 @@ xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-f xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false } pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false } polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false } -polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } [dev-dependencies] hex-literal = "0.4.1" @@ -67,7 +66,6 @@ std = [ "parachains-common/std", "parachains-runtimes-test-utils/std", "polkadot-parachain-primitives/std", - "polkadot-runtime-common/std", "sp-consensus-aura/std", "sp-core/std", "sp-io/std", diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index c2ec5401e795..d1b30457cca6 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -177,6 +177,22 @@ pub fn teleports_for_native_asset_works< target_account_balance_before_teleport - existential_deposit ); + // Make sure account can pay delivery fees + let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< + XcmConfig::XcmSender, + >( + (native_asset_id, native_asset_to_teleport_away.into()).into(), + 0, + Unlimited, + dest_beneficiary, + dest, + ); + >::mint_into( + &target_account, + delivery_fees.into(), + ) + .unwrap(); + assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, @@ -186,6 +202,7 @@ pub fn teleports_for_native_asset_works< included_head.clone(), &alice, )); + // check balances assert_eq!( >::free_balance(&target_account), @@ -235,7 +252,7 @@ pub fn teleports_for_native_asset_works< )); let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< - ::PriceForSiblingDelivery, + XcmConfig::XcmSender, >( (native_asset_id, native_asset_to_teleport_away.into()).into(), 0, @@ -555,7 +572,7 @@ pub fn teleports_for_foreign_assets_works< // Make sure the target account has enough native asset to pay for delivery fees let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< - ::PriceForSiblingDelivery, + XcmConfig::XcmSender, >( (foreign_asset_id_multilocation, asset_to_teleport_away).into(), 0, diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs index 004adcea3214..ba736c63363e 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -14,30 +14,41 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; +//! Helpers for calculating XCM delivery fees. + use xcm::latest::prelude::*; /// Returns the delivery fees amount for pallet xcm's `teleport_assets` and /// `reserve_transfer_assets` extrinsics. -pub fn transfer_assets_delivery_fees( +/// It assumes delivery fees are only paid in one asset and that asset is known. +pub fn transfer_assets_parent_delivery_fees( assets: MultiAssets, fee_asset_item: u32, weight_limit: WeightLimit, beneficiary: MultiLocation, destination: MultiLocation, ) -> u128 { - // Approximation of the actual message sent by the extrinsic. - // The assets are not reanchored and the topic is a dummy one. - // However, it should have the same encoded size, which is what matters for delivery fees. - let message = Xcm(vec![ + let message = teleport_assets_dummy_message(assets, fee_asset_item, weight_limit, beneficiary); + let Ok((_, delivery_fees)) = validate_send::(destination, message) else { unreachable!("message can be sent; qed") }; + let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("asset is fungible; qed") }; + delivery_fees_amount +} + +/// Approximates the actual message sent by the teleport extrinsic. +/// The assets are not reanchored and the topic is a dummy one. +/// However, it should have the same encoded size, which is what matters for delivery fees. +/// Also has same encoded size as the one created by the reserve transfer assets extrinsic. +fn teleport_assets_dummy_message( + assets: MultiAssets, + fee_asset_item: u32, + weight_limit: WeightLimit, + beneficiary: MultiLocation, +) -> Xcm<()> { + Xcm(vec![ ReceiveTeleportedAsset(assets.clone()), // Same encoded size as `ReserveAssetDeposited` ClearOrigin, BuyExecution { fees: assets.get(fee_asset_item as usize).unwrap().clone(), weight_limit }, DepositAsset { assets: Wild(AllCounted(assets.len() as u32)), beneficiary }, SetTopic([0u8; 32]), // Dummy topic - ]); - let Parachain(para_id) = destination.interior().last().unwrap() else { unreachable!("Location is parachain") }; - let delivery_fees = P::price_for_parachain_delivery((*para_id).into(), &message); - let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; - delivery_fees_amount + ]) } From 33746fcd753ea63617184c3015c93ffa81cdc070 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 08:19:27 -0300 Subject: [PATCH 076/116] Remove remnant from UMP branch --- .../runtimes/assets/test-utils/src/test_cases.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index d1b30457cca6..7dd437704db4 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -177,22 +177,6 @@ pub fn teleports_for_native_asset_works< target_account_balance_before_teleport - existential_deposit ); - // Make sure account can pay delivery fees - let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< - XcmConfig::XcmSender, - >( - (native_asset_id, native_asset_to_teleport_away.into()).into(), - 0, - Unlimited, - dest_beneficiary, - dest, - ); - >::mint_into( - &target_account, - delivery_fees.into(), - ) - .unwrap(); - assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, From 231f548a007ded2f13f60da8b20665bbb947cea6 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 08:22:41 -0300 Subject: [PATCH 077/116] Remove remnant from UMP branch --- Cargo.lock | 2 -- .../parachains/runtimes/assets/test-utils/src/xcm_helpers.rs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7cc881a11be8..76793c40fd90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1009,7 +1009,6 @@ dependencies = [ "parachains-runtimes-test-utils", "parity-scale-codec", "polkadot-parachain-primitives", - "polkadot-runtime-common", "sp-consensus-aura", "sp-core", "sp-io", @@ -2586,7 +2585,6 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime", - "polkadot-runtime-common", "polkadot-runtime-parachains", "sp-core", "sp-runtime", diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs index ba736c63363e..0e661b9c6eb9 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -21,7 +21,7 @@ use xcm::latest::prelude::*; /// Returns the delivery fees amount for pallet xcm's `teleport_assets` and /// `reserve_transfer_assets` extrinsics. /// It assumes delivery fees are only paid in one asset and that asset is known. -pub fn transfer_assets_parent_delivery_fees( +pub fn transfer_assets_delivery_fees( assets: MultiAssets, fee_asset_item: u32, weight_limit: WeightLimit, From 36fd6127840c2ad93e0030ffb5151741695d32e7 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 08:37:17 -0300 Subject: [PATCH 078/116] Fix collectives tests --- Cargo.lock | 1 + .../emulated/collectives/collectives-polkadot/Cargo.toml | 1 + .../collectives-polkadot/src/tests/ambassador.rs | 8 +++++++- .../collectives-polkadot/src/tests/fellowship.rs | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76793c40fd90..c997c1fd6233 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2589,6 +2589,7 @@ dependencies = [ "sp-core", "sp-runtime", "staging-xcm", + "staging-xcm-executor", "xcm-emulator", ] diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml index 10801f409322..48091f0d8529 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/Cargo.toml @@ -26,6 +26,7 @@ polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parac polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false } # Cumulus parachains-common = { path = "../../../../common" } diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs index d9fd78fbcbff..df6169e42305 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs @@ -17,6 +17,8 @@ use crate::*; use collectives_polkadot_runtime::ambassador::AmbassadorSalaryPaymaster; +use integration_tests_common::constants::collectives; +use asset_hub_polkadot_runtime::xcm_config::XcmConfig as AssetHubPolkadotXcmConfig; use frame_support::traits::{fungible::Mutate, tokens::Pay}; use sp_core::crypto::Ss58Codec; use xcm_emulator::TestExt; @@ -32,7 +34,11 @@ fn pay_salary() { AssetHubPolkadot::execute_with(|| { type AssetHubBalances = ::Balances; - assert_ok!(>::mint_into(&pay_from, pay_amount * 2)); + // Make sure we have enough assets for delivery + let querier = (Parent, Parachain(collectives::PARA_ID)).into(); + let delivery_fees = xcm_helpers::query_response_delivery_fees::<::XcmSender>(querier); + + assert_ok!(>::mint_into(&pay_from, pay_amount * 2 + delivery_fees)); }); Collectives::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs index 0c51585c840d..0e744f0b30e0 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs @@ -48,7 +48,7 @@ fn pay_salary() { )); // Make sure we have enough assets for delivery let querier = (Parent, Parachain(collectives::PARA_ID)).into(); - let delivery_fees = xcm_helpers::query_response_delivery_fees::(querier); + let delivery_fees = xcm_helpers::query_response_delivery_fees::<::XcmSender>(querier); assert_ok!(>::mint_into(&pay_from, delivery_fees + asset_hub_polkadot::ED)); assert_ok!(>::mint_into(asset_id, &pay_from, pay_amount * 2)); }); From 8d525f744967e5833238077199aebb517b722a40 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 08:43:28 -0300 Subject: [PATCH 079/116] Wrong constants module being imported --- cumulus/parachains/common/src/kusama.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/common/src/kusama.rs b/cumulus/parachains/common/src/kusama.rs index f0d2ef44eb2e..308f7d081ced 100644 --- a/cumulus/parachains/common/src/kusama.rs +++ b/cumulus/parachains/common/src/kusama.rs @@ -27,8 +27,8 @@ pub mod consensus { /// Constants relating to KSM. pub mod currency { + use kusama_runtime_constants as constants; use polkadot_core_primitives::Balance; - use rococo_runtime_constants as constants; /// The existential deposit. Set to 1/10 of its parent Relay Chain. pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10; From fb4ff56ab15c39b43faf377b295601bd863b2748 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 08:47:36 -0300 Subject: [PATCH 080/116] Add SetFeesMode to expected message in PayOverXcm tests --- .../collectives-polkadot/src/lib.rs | 2 +- polkadot/xcm/xcm-builder/src/tests/pay/pay.rs | 26 ++++++++++++------- .../xcm/xcm-builder/src/tests/pay/salary.rs | 13 ++++++---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 49db55b17460..cc4428061c5c 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -410,7 +410,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EitherOfDiverse, Fellows>; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - // TODO: This should have the price set, but then why is it failing?? + // TODO: This should have the price set type PriceForSiblingDelivery = (); } diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs b/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs index 491a2bcef7a0..178b93842736 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/pay.rs @@ -71,11 +71,14 @@ fn pay_over_xcm_works() { let expected_message = Xcm(vec![ DescendOrigin(AccountId32 { id: SenderAccount::get().into(), network: None }.into()), UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - SetAppendix(Xcm(vec![ReportError(QueryResponseInfo { - destination: (Parent, Parachain(42)).into(), - query_id: 1, - max_weight: Weight::zero(), - })])), + SetAppendix(Xcm(vec![ + SetFeesMode { jit_withdraw: true }, + ReportError(QueryResponseInfo { + destination: (Parent, Parachain(42)).into(), + query_id: 1, + max_weight: Weight::zero(), + }), + ])), TransferAsset { assets: (Here, amount).into(), beneficiary: AccountId32 { id: recipient.clone().into(), network: None }.into(), @@ -130,11 +133,14 @@ fn pay_over_xcm_governance_body() { let expected_message = Xcm(vec![ DescendOrigin(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into()), UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - SetAppendix(Xcm(vec![ReportError(QueryResponseInfo { - destination: (Parent, Parachain(42)).into(), - query_id: 1, - max_weight: Weight::zero(), - })])), + SetAppendix(Xcm(vec![ + SetFeesMode { jit_withdraw: true }, + ReportError(QueryResponseInfo { + destination: (Parent, Parachain(42)).into(), + query_id: 1, + max_weight: Weight::zero(), + }), + ])), TransferAsset { assets: (Parent, amount).into(), beneficiary: AccountId32 { id: recipient.clone().into(), network: None }.into(), diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs index 1d40345f302a..e490fe326b37 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/salary.rs @@ -148,11 +148,14 @@ fn salary_pay_over_xcm_works() { let expected_message: Xcm = Xcm::(vec![ DescendOrigin(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into()), UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - SetAppendix(Xcm(vec![ReportError(QueryResponseInfo { - destination: (Parent, Parachain(42)).into(), - query_id: 1, - max_weight: Weight::zero(), - })])), + SetAppendix(Xcm(vec![ + SetFeesMode { jit_withdraw: true }, + ReportError(QueryResponseInfo { + destination: (Parent, Parachain(42)).into(), + query_id: 1, + max_weight: Weight::zero(), + }), + ])), TransferAsset { assets: (AssetHubAssetId::get(), FixedSalaryAmount::get()).into(), beneficiary: AccountId32 { id: recipient.clone().into(), network: None }.into(), From 65c0fc6d58fa553139a6e2285c750362f32d806e Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 08:55:22 -0300 Subject: [PATCH 081/116] Fix ambiguous trait calls --- .../emulated/assets/asset-hub-kusama/Cargo.toml | 2 ++ .../asset-hub-kusama/src/tests/reserve_transfer.rs | 14 +++++++------- .../assets/asset-hub-kusama/src/tests/teleport.rs | 6 +++--- .../emulated/assets/asset-hub-polkadot/Cargo.toml | 2 ++ .../src/tests/reserve_transfer.rs | 8 ++++---- .../asset-hub-polkadot/src/tests/teleport.rs | 4 ++-- .../emulated/assets/asset-hub-westend/Cargo.toml | 2 ++ .../src/tests/reserve_transfer.rs | 4 ++-- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml index 0cb1b469ce37..f26a61629c78 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml @@ -28,6 +28,7 @@ polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } kusama-runtime = { package = "staging-kusama-runtime", path = "../../../../../../polkadot/runtime/kusama" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false } # Cumulus parachains-common = { path = "../../../../common" } @@ -55,4 +56,5 @@ runtime-benchmarks = [ "polkadot-runtime-parachains/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs index 160415e11ffd..0d9aac6f67c6 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs @@ -27,7 +27,7 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(630_092_000, 6_196))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( t.args.assets.clone(), 0, t.args.weight_limit, @@ -80,7 +80,7 @@ fn system_para_to_para_assertions(t: SystemParaToParaTest) { ))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( t.args.assets.clone(), 0, t.args.weight_limit, @@ -124,7 +124,7 @@ fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) { ))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( t.args.assets.clone(), 0, t.args.weight_limit, @@ -249,7 +249,7 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -318,7 +318,7 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -390,7 +390,7 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -432,7 +432,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs index ace58cbed663..1c3c4e862a9a 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs @@ -26,7 +26,7 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( t.args.assets.clone(), 0, t.args.weight_limit, @@ -200,7 +200,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -313,7 +313,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml index ee2839928f25..e61112f93e12 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/Cargo.toml @@ -25,6 +25,7 @@ polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parac polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false } # Cumulus parachains-common = { path = "../../../../common" } @@ -50,4 +51,5 @@ runtime-benchmarks = [ "polkadot-runtime-parachains/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs index 7a664cafd9a5..8b3852300433 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs @@ -188,7 +188,7 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -257,7 +257,7 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -329,7 +329,7 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -371,7 +371,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs index 43702c9424c1..52e3e67c5505 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/teleport.rs @@ -179,7 +179,7 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -292,7 +292,7 @@ fn teleport_native_assets_from_relay_to_system_para_works() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml index 1bba515684f3..d80484e15003 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml @@ -26,6 +26,7 @@ polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parac polkadot-runtime = { path = "../../../../../../polkadot/runtime/polkadot" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false } # Cumulus parachains-common = { path = "../../../../common" } @@ -51,4 +52,5 @@ runtime-benchmarks = [ "polkadot-runtime-parachains/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 66e5cc9b72a4..03d16d5e321a 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -308,7 +308,7 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubWestend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, @@ -350,7 +350,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubWestend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::( + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( test.args.assets.clone(), 0, test.args.weight_limit, From 268fa714eaea1d557b918c4e0614c3a7c881bf57 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 09:05:34 -0300 Subject: [PATCH 082/116] Updated lock --- Cargo.lock | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c997c1fd6233..9c500d13068d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,6 +716,7 @@ dependencies = [ "sp-runtime", "staging-kusama-runtime", "staging-xcm", + "staging-xcm-executor", "xcm-emulator", ] @@ -814,6 +815,7 @@ dependencies = [ "polkadot-runtime-parachains", "sp-runtime", "staging-xcm", + "staging-xcm-executor", "xcm-emulator", ] @@ -909,6 +911,7 @@ dependencies = [ "polkadot-runtime-parachains", "sp-runtime", "staging-xcm", + "staging-xcm-executor", "xcm-emulator", ] From fce81f151e3f0a4c87b4966f451cd732e9d6d6de Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 27 Sep 2023 13:34:50 +0000 Subject: [PATCH 083/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../src/tests/reserve_transfer.rs | 72 ++++++------------- .../asset-hub-kusama/src/tests/teleport.rs | 21 +++--- .../src/tests/reserve_transfer.rs | 40 ++++------- .../src/tests/ambassador.rs | 13 ++-- .../src/tests/fellowship.rs | 15 ++-- .../collectives-polkadot/src/xcm_helpers.rs | 23 +++--- .../assets/test-utils/src/test_cases.rs | 34 +++++---- 7 files changed, 91 insertions(+), 127 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs index 0d9aac6f67c6..25faa421e5c1 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/reserve_transfer.rs @@ -18,7 +18,7 @@ use asset_hub_kusama_runtime::xcm_config::{ TreasuryAccount as AssetHubKusamaTreasuryAccount, XcmConfig as AssetHubKusamaXcmConfig, }; use kusama_runtime::xcm_config::{ - XcmConfig as KusamaXcmConfig, TreasuryAccount as KusamaTreasuryAccount, + TreasuryAccount as KusamaTreasuryAccount, XcmConfig as KusamaXcmConfig, }; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -27,13 +27,9 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) { Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(630_092_000, 6_196))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(t.args.assets.clone(), 0, t.args.weight_limit, t.args.beneficiary, t.args.dest); assert_expected_events!( Kusama, @@ -80,13 +76,9 @@ fn system_para_to_para_assertions(t: SystemParaToParaTest) { ))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(t.args.assets.clone(), 0, t.args.weight_limit, t.args.beneficiary, t.args.dest); assert_expected_events!( AssetHubKusama, @@ -124,13 +116,9 @@ fn system_para_to_para_assets_assertions(t: SystemParaToParaTest) { ))); let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(t.args.assets.clone(), 0, t.args.weight_limit, t.args.beneficiary, t.args.dest); assert_expected_events!( AssetHubKusama, @@ -249,13 +237,9 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -318,13 +302,9 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Kusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -390,13 +370,9 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -432,13 +408,9 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubKusama::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs index 1c3c4e862a9a..5de1b0b5f2b1 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/teleport.rs @@ -16,23 +16,22 @@ #![allow(dead_code)] // use crate::*; -use kusama_runtime::xcm_config::{ - XcmConfig, TreasuryAccount as KusamaTreasuryAccount, -}; +use kusama_runtime::xcm_config::{TreasuryAccount as KusamaTreasuryAccount, XcmConfig}; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; Kusama::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); - let delivery_fees_amount = - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - t.args.assets.clone(), - 0, - t.args.weight_limit, - t.args.beneficiary, - t.args.dest, - ); + let delivery_fees_amount = xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >( + t.args.assets.clone(), + 0, + t.args.weight_limit, + t.args.beneficiary, + t.args.dest, + ); assert_expected_events!( Kusama, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs index 8b3852300433..9e5c9983cfe4 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/reserve_transfer.rs @@ -188,13 +188,9 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -257,13 +253,9 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let receiver_balance_after = test.receiver.balance; let delivery_fees = Polkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -329,13 +321,9 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -371,13 +359,9 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubPolkadot::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs index df6169e42305..41b613976c64 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs @@ -16,10 +16,10 @@ //! Integration tests concerning the Ambassador Program. use crate::*; -use collectives_polkadot_runtime::ambassador::AmbassadorSalaryPaymaster; -use integration_tests_common::constants::collectives; use asset_hub_polkadot_runtime::xcm_config::XcmConfig as AssetHubPolkadotXcmConfig; +use collectives_polkadot_runtime::ambassador::AmbassadorSalaryPaymaster; use frame_support::traits::{fungible::Mutate, tokens::Pay}; +use integration_tests_common::constants::collectives; use sp_core::crypto::Ss58Codec; use xcm_emulator::TestExt; @@ -36,9 +36,14 @@ fn pay_salary() { // Make sure we have enough assets for delivery let querier = (Parent, Parachain(collectives::PARA_ID)).into(); - let delivery_fees = xcm_helpers::query_response_delivery_fees::<::XcmSender>(querier); + let delivery_fees = xcm_helpers::query_response_delivery_fees::< + ::XcmSender, + >(querier); - assert_ok!(>::mint_into(&pay_from, pay_amount * 2 + delivery_fees)); + assert_ok!(>::mint_into( + &pay_from, + pay_amount * 2 + delivery_fees + )); }); Collectives::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs index 0e744f0b30e0..26e5614e51f0 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs @@ -16,14 +16,14 @@ //! Integration tests concerning the Fellowship. use crate::*; -use collectives_polkadot_runtime::fellowship::FellowshipSalaryPaymaster; -use integration_tests_common::constants::{collectives, asset_hub_polkadot}; use asset_hub_polkadot_runtime::xcm_config::XcmConfig as AssetHubPolkadotXcmConfig; +use collectives_polkadot_runtime::fellowship::FellowshipSalaryPaymaster; use frame_support::traits::{ - fungibles::{Create, Mutate}, fungible, + fungibles::{Create, Mutate}, tokens::Pay, }; +use integration_tests_common::constants::{asset_hub_polkadot, collectives}; use sp_core::crypto::Ss58Codec; use xcm_emulator::TestExt; @@ -48,8 +48,13 @@ fn pay_salary() { )); // Make sure we have enough assets for delivery let querier = (Parent, Parachain(collectives::PARA_ID)).into(); - let delivery_fees = xcm_helpers::query_response_delivery_fees::<::XcmSender>(querier); - assert_ok!(>::mint_into(&pay_from, delivery_fees + asset_hub_polkadot::ED)); + let delivery_fees = xcm_helpers::query_response_delivery_fees::< + ::XcmSender, + >(querier); + assert_ok!(>::mint_into( + &pay_from, + delivery_fees + asset_hub_polkadot::ED + )); assert_ok!(>::mint_into(asset_id, &pay_from, pay_amount * 2)); }); diff --git a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs index 0d41052f7044..7980dae80795 100644 --- a/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs +++ b/cumulus/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/xcm_helpers.rs @@ -20,17 +20,18 @@ use xcm::latest::prelude::*; pub fn query_response_delivery_fees(querier: MultiLocation) -> u128 { // Message to calculate delivery fees, it's encoded size is what's important. - // This message reports that there was no error, if an error is reported, the encoded size would be different. - let message = Xcm(vec![ - QueryResponse { - query_id: 0, // Dummy query id - response: Response::ExecutionResult(None), - max_weight: Weight::zero(), - querier: Some(querier), - }, - SetTopic([0u8; 32]), // Dummy topic - ]); + // This message reports that there was no error, if an error is reported, the encoded size would + // be different. + let message = Xcm(vec![ + QueryResponse { + query_id: 0, // Dummy query id + response: Response::ExecutionResult(None), + max_weight: Weight::zero(), + querier: Some(querier), + }, + SetTopic([0u8; 32]), // Dummy topic + ]); let Ok((_, delivery_fees)) = validate_send::(querier, message) else { unreachable!("message can be sent; qed") }; let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("Asset is fungible") }; - delivery_fees_amount + delivery_fees_amount } diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 7dd437704db4..51689c828663 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -235,15 +235,14 @@ pub fn teleports_for_native_asset_works< &alice, )); - let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< - XcmConfig::XcmSender, - >( - (native_asset_id, native_asset_to_teleport_away.into()).into(), - 0, - Unlimited, - dest_beneficiary, - dest, - ); + let delivery_fees = + xcm_helpers::transfer_assets_delivery_fees::( + (native_asset_id, native_asset_to_teleport_away.into()).into(), + 0, + Unlimited, + dest_beneficiary, + dest, + ); // check balances assert_eq!( @@ -555,15 +554,14 @@ pub fn teleports_for_foreign_assets_works< ); // Make sure the target account has enough native asset to pay for delivery fees - let delivery_fees = xcm_helpers::transfer_assets_delivery_fees::< - XcmConfig::XcmSender, - >( - (foreign_asset_id_multilocation, asset_to_teleport_away).into(), - 0, - Unlimited, - dest_beneficiary, - dest, - ); + let delivery_fees = + xcm_helpers::transfer_assets_delivery_fees::( + (foreign_asset_id_multilocation, asset_to_teleport_away).into(), + 0, + Unlimited, + dest_beneficiary, + dest, + ); >::mint_into( &target_account, delivery_fees.into(), From fc97690943562a5d3e8d291532e0184b9c798424 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 27 Sep 2023 12:45:07 -0300 Subject: [PATCH 084/116] Remove conflict --- polkadot/runtime/westend/src/xcm_config.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index 2a7c620f7065..a85cf43c6ff9 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -200,11 +200,6 @@ parameter_types! { pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); } -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parachain(1000).into()); -} - /// Type to convert the `GeneralAdmin` origin to a Plurality `MultiLocation` value. pub type GeneralAdminToPlurality = OriginToPluralityVoice; From 598516ef69e24cc3e7fa42c7f1dfea6b61bf29f2 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 29 Sep 2023 14:19:26 -0300 Subject: [PATCH 085/116] Add missing import --- .../runtimes/collectives/collectives-polkadot/src/xcm_config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 020b370ac146..c63b39332b77 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -33,6 +33,7 @@ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::{ system_parachain::SystemParachains, xcm::body::FELLOWSHIP_ADMIN_INDEX, }; +use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, From b9697b68284462494cf9197685c6c8eed362b54f Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 29 Sep 2023 14:46:45 -0300 Subject: [PATCH 086/116] Remove polkadot and kusama constants --- Cargo.lock | 5 +++++ .../runtimes/assets/asset-hub-kusama/Cargo.toml | 2 ++ .../runtimes/assets/asset-hub-kusama/src/lib.rs | 9 +-------- .../runtimes/assets/asset-hub-kusama/src/xcm_config.rs | 2 +- .../runtimes/assets/asset-hub-polkadot/Cargo.toml | 2 ++ .../runtimes/assets/asset-hub-polkadot/src/lib.rs | 2 +- .../runtimes/assets/asset-hub-polkadot/src/xcm_config.rs | 2 +- .../runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 ++ .../bridge-hubs/bridge-hub-kusama/src/xcm_config.rs | 2 +- .../runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml | 2 ++ .../bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs | 2 +- .../runtimes/collectives/collectives-polkadot/Cargo.toml | 2 ++ .../collectives/collectives-polkadot/src/xcm_config.rs | 2 +- 13 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6f0f6413827..e3a378f7c87c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -743,6 +743,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-common", "primitive-types", + "rococo-runtime-constants", "scale-info", "smallvec", "sp-api", @@ -832,6 +833,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "westend-runtime-constants", ] [[package]] @@ -1806,6 +1808,7 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime-common", + "rococo-runtime-constants", "scale-info", "serde", "smallvec", @@ -1890,6 +1893,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "westend-runtime-constants", ] [[package]] @@ -2578,6 +2582,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "westend-runtime-constants", ] [[package]] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml index eb0f249aaae7..1101d8a94ab0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml @@ -64,6 +64,7 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} +rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -222,6 +223,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "rococo-runtime-constants/std", ] experimental = [ "pallet-aura/experimental" ] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 0cbd4c51aee5..6777f4ea4134 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -1231,19 +1231,12 @@ impl_runtime_apis! { xcm_config::KsmLocation::get(), ExistentialDeposit::get() ).into()); - pub ToParachain: ParaId = kusama_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); } impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper< - XcmConfig, - ExistentialDepositMultiAsset, - PriceForSiblingParachainDelivery, - ToParachain, - (), - >; + type DeliveryHelper = (); // No requirement for UMP fn valid_destination() -> Result { Ok(KsmLocation::get()) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 480407effd0f..299bfdfc6b1e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -30,7 +30,7 @@ use frame_support::{ traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, }; use frame_system::EnsureRoot; -use kusama_runtime_constants::system_parachain::SystemParachains; +use rococo_runtime_constants::system_parachain::SystemParachains; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml index df38e4d9d64a..4f09343dadcd 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml @@ -59,6 +59,7 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} +westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -203,6 +204,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "westend-runtime-constants/std", ] experimental = [ "pallet-aura/experimental" ] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index d0ad8562817d..279b53e9bf5c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -1107,7 +1107,7 @@ impl_runtime_apis! { xcm_config::DotLocation::get(), ExistentialDeposit::get() ).into()); - pub ToParachain: ParaId = polkadot_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); + pub ToParachain: ParaId = westend_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); } impl pallet_xcm_benchmarks::Config for Runtime { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index 9e36f84206f5..192f04beaf1d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -33,7 +33,7 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_constants::system_parachain::SystemParachains; +use westend_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml index bfb0b9e71270..1732ada86da5 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -57,6 +57,7 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} +rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -131,6 +132,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "rococo-runtime-constants/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index b2fa6e2d9c91..8a555f4cc7c6 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -23,7 +23,7 @@ use frame_support::{ traits::{ConstU32, Contains, Everything, Nothing}, }; use frame_system::EnsureRoot; -use kusama_runtime_constants::system_parachain::SystemParachains; +use rococo_runtime_constants::system_parachain::SystemParachains; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml index eb0c18f5b460..627baa51bf92 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -57,6 +57,7 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} +westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -131,6 +132,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "westend-runtime-constants/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 2493ad5a7bf2..3af2c7b44562 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -30,7 +30,7 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_constants::system_parachain::SystemParachains; +use westend_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index e66cef31e56f..133b030a2585 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -61,6 +61,7 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} +westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -214,6 +215,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "westend-runtime-constants/std", ] experimental = [ "pallet-aura/experimental" ] diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index c63b39332b77..aa6e17e52ba2 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -30,7 +30,7 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_constants::{ +use westend_runtime_constants::{ system_parachain::SystemParachains, xcm::body::FELLOWSHIP_ADMIN_INDEX, }; use sp_runtime::traits::AccountIdConversion; From a38ee4c261e8498731b2c583040595da7c8615cd Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 29 Sep 2023 14:53:04 -0300 Subject: [PATCH 087/116] Remove hardcoded constant --- .../runtimes/collectives/collectives-polkadot/src/xcm_config.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index aa6e17e52ba2..9b79aa20f368 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -46,8 +46,6 @@ use xcm_builder::{ }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; -const FELLOWSHIP_ADMIN_INDEX: u32 = 1; - parameter_types! { pub const DotLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: Option = Some(NetworkId::Polkadot); From cd11b329ff21e588a0e9809627c2dba9486af0fa Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 29 Sep 2023 15:59:17 -0300 Subject: [PATCH 088/116] Fix CI --- cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml | 2 +- cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 1 - .../parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml | 2 +- .../runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 +- .../runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml | 2 +- .../runtimes/collectives/collectives-polkadot/Cargo.toml | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml index 1101d8a94ab0..219beb4e0f02 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml @@ -204,6 +204,7 @@ std = [ "polkadot-core-primitives/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", + "rococo-runtime-constants/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", @@ -223,7 +224,6 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "rococo-runtime-constants/std", ] experimental = [ "pallet-aura/experimental" ] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 6777f4ea4134..5bd5a4973cc7 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -1224,7 +1224,6 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::{KsmLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; - use cumulus_primitives_core::ParaId; parameter_types! { pub ExistentialDepositMultiAsset: Option = Some(( diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml index 4f09343dadcd..e69aa55be589 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml @@ -201,10 +201,10 @@ std = [ "sp-version/std", "sp-weights/std", "substrate-wasm-builder", + "westend-runtime-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", - "westend-runtime-constants/std", ] experimental = [ "pallet-aura/experimental" ] diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml index 1732ada86da5..791eeac250cc 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -112,6 +112,7 @@ std = [ "polkadot-core-primitives/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", + "rococo-runtime-constants/std", "scale-info/std", "serde", "sp-api/std", @@ -132,7 +133,6 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "rococo-runtime-constants/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 627baa51bf92..e2f95d512c5a 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -129,10 +129,10 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "westend-runtime-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", - "westend-runtime-constants/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index 133b030a2585..85a802cecc6b 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -212,10 +212,10 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "westend-runtime-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", - "westend-runtime-constants/std", ] experimental = [ "pallet-aura/experimental" ] From 29f800371b4946d8986a59688ebc556ed1913fdf Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 2 Oct 2023 06:50:51 -0300 Subject: [PATCH 089/116] Address feedback --- cumulus/pallets/xcmp-queue/src/lib.rs | 28 ++++++++++---------- polkadot/runtime/parachains/src/dmp.rs | 20 +++++++------- polkadot/runtime/parachains/src/dmp/tests.rs | 2 +- polkadot/runtime/parachains/src/lib.rs | 2 +- polkadot/runtime/rococo/src/xcm_config.rs | 6 ++--- polkadot/runtime/westend/src/xcm_config.rs | 6 ++--- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index 7eb565574607..b6a6eaa3d1c1 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -669,7 +669,7 @@ impl Pallet { messages_processed: &mut u8, max_weight: Weight, max_individual_weight: Weight, - should_decrement_fee_factor: bool, + should_decrease_fee_factor: bool, ) -> (Weight, bool) { let data = >::get(sender, sent_at); let mut last_remaining_fragments; @@ -735,8 +735,8 @@ impl Pallet { remaining_fragments = &b""[..]; } - if should_decrement_fee_factor { - Self::decrement_fee_factor(sender); + if should_decrease_fee_factor { + Self::decrease_fee_factor(sender); } } }, @@ -892,7 +892,7 @@ impl Pallet { } else { // Process up to one block's worth for now. let weight_remaining = weight_available.saturating_sub(weight_used); - let should_decrement_fee_factor = + let should_decrease_fee_factor = (status[index].message_metadata.len() as u32) <= suspend_threshold; let (weight_processed, is_empty) = Self::process_xcmp_message( sender, @@ -900,7 +900,7 @@ impl Pallet { &mut messages_processed, weight_remaining, xcmp_max_individual_weight, - should_decrement_fee_factor, + should_decrease_fee_factor, ); if is_empty { status[index].message_metadata.remove(0); @@ -971,22 +971,22 @@ impl Pallet { }); } - /// Raise the delivery fee factor by a multiplicative factor and stores the resulting value. + /// Increases the delivery fee factor by a multiplicative factor and stores the resulting value. /// - /// Returns the new delivery fee factor after the increment. - pub(crate) fn increment_fee_factor(para: ParaId, message_size_factor: FixedU128) -> FixedU128 { + /// Returns the new delivery fee factor after the increase. + pub(crate) fn increase_fee_factor(para: ParaId, message_size_factor: FixedU128) -> FixedU128 { >::mutate(para, |f| { - *f = f.saturating_mul(EXPONENTIAL_FEE_BASE + message_size_factor); + *f = f.saturating_mul(EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); *f }) } - /// Reduce the delivery fee factor by a multiplicative factor and stores the resulting value. + /// Decreases the delivery fee factor by a multiplicative factor and stores the resulting value. /// /// Does not reduce the fee factor below the initial value, which is currently set as 1. /// - /// Returns the new delivery fee factor after the decrement. - pub(crate) fn decrement_fee_factor(para: ParaId) -> FixedU128 { + /// Returns the new delivery fee factor after the decrease. + pub(crate) fn decrease_fee_factor(para: ParaId) -> FixedU128 { >::mutate(para, |f| { *f = InitialFactor::get().max(*f / EXPONENTIAL_FEE_BASE); *f @@ -1050,9 +1050,9 @@ impl XcmpMessageHandler for Pallet { // Update the delivery fee factor, if applicable. if count > suspend_threshold { let message_size_factor = - FixedU128::from_u32(data_ref.len().saturating_div(1024) as u32) + FixedU128::from((data_ref.len() / 1024) as u128) .saturating_mul(MESSAGE_SIZE_FEE_BASE); - Self::increment_fee_factor(sender, message_size_factor); + Self::increase_fee_factor(sender, message_size_factor); } }, Err(_) => status.push(InboundChannelDetails { diff --git a/polkadot/runtime/parachains/src/dmp.rs b/polkadot/runtime/parachains/src/dmp.rs index 69836a96d617..25acbc737639 100644 --- a/polkadot/runtime/parachains/src/dmp.rs +++ b/polkadot/runtime/parachains/src/dmp.rs @@ -244,9 +244,9 @@ impl Pallet { Self::dmq_max_length(config.max_downward_message_size).saturating_div(THRESHOLD_FACTOR); if q_len > (threshold as usize) { let message_size_factor = - FixedU128::from_u32(serialized_len.saturating_div(1024) as u32) + FixedU128::from((serialized_len / 1024) as u128) .saturating_mul(MESSAGE_SIZE_FEE_BASE); - Self::increment_fee_factor(para, message_size_factor); + Self::increase_fee_factor(para, message_size_factor); } Ok(()) @@ -304,7 +304,7 @@ impl Pallet { let threshold = Self::dmq_max_length(config.max_downward_message_size).saturating_div(THRESHOLD_FACTOR); if q_len <= (threshold as usize) { - Self::decrement_fee_factor(para); + Self::decrease_fee_factor(para); } T::DbWeight::get().reads_writes(1, 1) } @@ -338,22 +338,22 @@ impl Pallet { DownwardMessageQueues::::get(&recipient) } - /// Raise the delivery fee factor by a multiplicative factor and stores the resulting value. + /// Increases the delivery fee factor by a multiplicative factor and stores the resulting value. /// - /// Returns the new delivery fee factor after the increment. - pub(crate) fn increment_fee_factor(para: ParaId, message_size_factor: FixedU128) -> FixedU128 { + /// Returns the new delivery fee factor after the increase. + pub(crate) fn increase_fee_factor(para: ParaId, message_size_factor: FixedU128) -> FixedU128 { >::mutate(para, |f| { - *f = f.saturating_mul(EXPONENTIAL_FEE_BASE + message_size_factor); + *f = f.saturating_mul(EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); *f }) } - /// Reduce the delivery fee factor by a multiplicative factor and stores the resulting value. + /// Decreases the delivery fee factor by a multiplicative factor and stores the resulting value. /// /// Does not reduce the fee factor below the initial value, which is currently set as 1. /// - /// Returns the new delivery fee factor after the decrement. - pub(crate) fn decrement_fee_factor(para: ParaId) -> FixedU128 { + /// Returns the new delivery fee factor after the decrease. + pub(crate) fn decrease_fee_factor(para: ParaId) -> FixedU128 { >::mutate(para, |f| { *f = InitialFactor::get().max(*f / EXPONENTIAL_FEE_BASE); *f diff --git a/polkadot/runtime/parachains/src/dmp/tests.rs b/polkadot/runtime/parachains/src/dmp/tests.rs index a65984840da5..f9197b156a1e 100644 --- a/polkadot/runtime/parachains/src/dmp/tests.rs +++ b/polkadot/runtime/parachains/src/dmp/tests.rs @@ -233,7 +233,7 @@ fn verify_dmq_mqc_head_is_externally_accessible() { } #[test] -fn verify_fee_increment_and_decrement() { +fn verify_fee_increase_and_decrease() { let a = ParaId::from(123); let mut genesis = default_genesis_config(); genesis.configuration.config.max_downward_message_size = 16777216; diff --git a/polkadot/runtime/parachains/src/lib.rs b/polkadot/runtime/parachains/src/lib.rs index 718e6535b5cc..0a3a83cb1c95 100644 --- a/polkadot/runtime/parachains/src/lib.rs +++ b/polkadot/runtime/parachains/src/lib.rs @@ -59,7 +59,7 @@ use sp_runtime::{DispatchResult, FixedU128}; /// Trait for tracking message delivery fees on a transport protocol. pub trait FeeTracker { - /// The evolving exponential fee factor which will be used to calculate the delivery fees. + /// Returns the evolving exponential fee factor which will be used to calculate the delivery fees. fn get_fee_factor(para: ParaId) -> FixedU128; } diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 25e8066f1caf..5305b0942a8d 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -106,10 +106,10 @@ pub type PriceForChildParachainDelivery = /// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our /// individual routers. -pub type XcmRouter = WithUniqueTopic<( +pub type XcmRouter = WithUniqueTopic< // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter, -)>; + ChildParachainRouter +>; parameter_types! { pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) }); diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index a85cf43c6ff9..96064f1de7f3 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -100,10 +100,10 @@ pub type PriceForChildParachainDelivery = /// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our /// individual routers. -pub type XcmRouter = WithUniqueTopic<( +pub type XcmRouter = WithUniqueTopic< // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter, -)>; + ChildParachainRouter +>; parameter_types! { pub const AssetHub: MultiLocation = Parachain(ASSET_HUB_ID).into_location(); From ec36b49a3a7ea22bd956d8ef8df75ec828c03ec5 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 2 Oct 2023 11:29:12 +0000 Subject: [PATCH 090/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../runtimes/assets/asset-hub-kusama/src/xcm_config.rs | 2 +- .../runtimes/assets/asset-hub-polkadot/src/xcm_config.rs | 2 +- .../runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs | 2 +- .../bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs | 2 +- .../collectives/collectives-polkadot/src/xcm_config.rs | 2 +- polkadot/runtime/parachains/src/dmp.rs | 5 ++--- polkadot/runtime/parachains/src/lib.rs | 3 ++- polkadot/runtime/rococo/src/xcm_config.rs | 2 +- polkadot/runtime/westend/src/xcm_config.rs | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 299bfdfc6b1e..f3cf3fa401fe 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -30,7 +30,6 @@ use frame_support::{ traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, }; use frame_system::EnsureRoot; -use rococo_runtime_constants::system_parachain::SystemParachains; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, @@ -38,6 +37,7 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; +use rococo_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index 192f04beaf1d..444463ae26f1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -33,8 +33,8 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; -use westend_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use westend_runtime_constants::system_parachain::SystemParachains; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 8a555f4cc7c6..d4cb694535aa 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -23,7 +23,6 @@ use frame_support::{ traits::{ConstU32, Contains, Everything, Nothing}, }; use frame_system::EnsureRoot; -use rococo_runtime_constants::system_parachain::SystemParachains; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, @@ -31,6 +30,7 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; +use rococo_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 3af2c7b44562..99ac6d518730 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -30,8 +30,8 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; -use westend_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::AccountIdConversion; +use westend_runtime_constants::system_parachain::SystemParachains; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 9b79aa20f368..cab51302ea8f 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -30,10 +30,10 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; +use sp_runtime::traits::AccountIdConversion; use westend_runtime_constants::{ system_parachain::SystemParachains, xcm::body::FELLOWSHIP_ADMIN_INDEX, }; -use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/polkadot/runtime/parachains/src/dmp.rs b/polkadot/runtime/parachains/src/dmp.rs index 25acbc737639..bfc3be456e6c 100644 --- a/polkadot/runtime/parachains/src/dmp.rs +++ b/polkadot/runtime/parachains/src/dmp.rs @@ -243,9 +243,8 @@ impl Pallet { let threshold = Self::dmq_max_length(config.max_downward_message_size).saturating_div(THRESHOLD_FACTOR); if q_len > (threshold as usize) { - let message_size_factor = - FixedU128::from((serialized_len / 1024) as u128) - .saturating_mul(MESSAGE_SIZE_FEE_BASE); + let message_size_factor = FixedU128::from((serialized_len / 1024) as u128) + .saturating_mul(MESSAGE_SIZE_FEE_BASE); Self::increase_fee_factor(para, message_size_factor); } diff --git a/polkadot/runtime/parachains/src/lib.rs b/polkadot/runtime/parachains/src/lib.rs index 0a3a83cb1c95..7477a06d16a3 100644 --- a/polkadot/runtime/parachains/src/lib.rs +++ b/polkadot/runtime/parachains/src/lib.rs @@ -59,7 +59,8 @@ use sp_runtime::{DispatchResult, FixedU128}; /// Trait for tracking message delivery fees on a transport protocol. pub trait FeeTracker { - /// Returns the evolving exponential fee factor which will be used to calculate the delivery fees. + /// Returns the evolving exponential fee factor which will be used to calculate the delivery + /// fees. fn get_fee_factor(para: ParaId) -> FixedU128; } diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 5305b0942a8d..408f9e1260b7 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -108,7 +108,7 @@ pub type PriceForChildParachainDelivery = /// individual routers. pub type XcmRouter = WithUniqueTopic< // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter + ChildParachainRouter, >; parameter_types! { diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index 96064f1de7f3..4a1f54e3db65 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -102,7 +102,7 @@ pub type PriceForChildParachainDelivery = /// individual routers. pub type XcmRouter = WithUniqueTopic< // Only one router so far - use DMP to communicate with child parachains. - ChildParachainRouter + ChildParachainRouter, >; parameter_types! { From 6355068f426dc69353ddf78622c8500a3849f83e Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 4 Oct 2023 13:38:49 -0300 Subject: [PATCH 091/116] Default FeeManager shouldn't waive fees --- polkadot/xcm/xcm-executor/src/traits/fee_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs b/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs index 495f021e7252..2b2f21927f2e 100644 --- a/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs +++ b/polkadot/xcm/xcm-executor/src/traits/fee_manager.rs @@ -53,7 +53,7 @@ pub enum FeeReason { impl FeeManager for () { fn is_waived(_: Option<&MultiLocation>, _: FeeReason) -> bool { - true + false } fn handle_fee(_: MultiAssets, _: Option<&XcmContext>) {} } From 9fd00c2d0be5cfbe4e20526c2f735b107010593e Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 4 Oct 2023 13:55:08 -0300 Subject: [PATCH 092/116] Remove changes to polkadot and kusama system parachains --- .../assets/asset-hub-kusama/Cargo.toml | 2 -- .../assets/asset-hub-kusama/src/lib.rs | 23 +------------- .../assets/asset-hub-kusama/src/xcm_config.rs | 16 +++------- .../assets/asset-hub-polkadot/Cargo.toml | 2 -- .../assets/asset-hub-polkadot/src/lib.rs | 30 ++----------------- .../asset-hub-polkadot/src/xcm_config.rs | 16 +++------- .../asset-hub-westend/src/xcm_config.rs | 8 ++++- .../bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 -- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 16 +--------- .../bridge-hub-kusama/src/xcm_config.rs | 14 ++------- .../bridge-hub-polkadot/Cargo.toml | 2 -- .../bridge-hub-polkadot/src/lib.rs | 16 +--------- .../bridge-hub-polkadot/src/xcm_config.rs | 14 ++------- .../collectives-polkadot/Cargo.toml | 2 -- .../collectives-polkadot/src/lib.rs | 1 - .../collectives-polkadot/src/xcm_config.rs | 19 ++++-------- 16 files changed, 29 insertions(+), 154 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml index 219beb4e0f02..eb0f249aaae7 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml @@ -64,7 +64,6 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} -rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -204,7 +203,6 @@ std = [ "polkadot-core-primitives/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", - "rococo-runtime-constants/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 5bd5a4973cc7..cd49d516a53a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -633,20 +633,6 @@ parameter_types! { pub const FellowsBodyId: BodyId = BodyId::Technical; } -parameter_types! { - /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = Concrete(xcm_config::KsmLocation::get()); - /// The base fee for the message delivery fees. - pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); -} - -pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< - FeeAssetId, - BaseDeliveryFee, - TransactionByteFee, - XcmpQueue, ->; - impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -659,7 +645,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { >; type ControllerOriginConverter = xcm_config::XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -1225,13 +1211,6 @@ impl_runtime_apis! { use xcm_config::{KsmLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; - parameter_types! { - pub ExistentialDepositMultiAsset: Option = Some(( - xcm_config::KsmLocation::get(), - ExistentialDeposit::get() - ).into()); - } - impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index f3cf3fa401fe..0a7176847017 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -33,12 +33,10 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, + xcm_config::AssetFeeAsExistentialDepositMultiplier, }; use polkadot_parachain_primitives::primitives::Sibling; -use rococo_runtime_constants::system_parachain::SystemParachains; -use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use sp_runtime::traits::ConvertInto; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -48,7 +46,7 @@ use xcm_builder::{ NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -71,7 +69,6 @@ parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); pub const FellowshipLocation: MultiLocation = MultiLocation::parent(); - pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -522,12 +519,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount< - Self, - RelayOrOtherSystemParachains, - AccountId, - TreasuryAccount, - >; + type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml index e69aa55be589..df38e4d9d64a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml @@ -59,7 +59,6 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} -westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -201,7 +200,6 @@ std = [ "sp-version/std", "sp-weights/std", "substrate-wasm-builder", - "westend-runtime-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index 279b53e9bf5c..0869748c9361 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -567,19 +567,8 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types! { // Fellows pluralistic body. pub const FellowsBodyId: BodyId = BodyId::Technical; - /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = Concrete(xcm_config::DotLocation::get()); - /// The base fee for the message delivery fees. - pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } -pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< - FeeAssetId, - BaseDeliveryFee, - TransactionByteFee, - XcmpQueue, ->; - impl cumulus_pallet_xcmp_queue::Config for Runtime { type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; type RuntimeEvent = RuntimeEvent; @@ -592,7 +581,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { EnsureXcm>, >; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; - type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -1100,26 +1089,11 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::{DotLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; - use cumulus_primitives_core::ParaId; - - parameter_types! { - pub ExistentialDepositMultiAsset: Option = Some(( - xcm_config::DotLocation::get(), - ExistentialDeposit::get() - ).into()); - pub ToParachain: ParaId = westend_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); - } impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper< - XcmConfig, - ExistentialDepositMultiAsset, - PriceForSiblingParachainDelivery, - ToParachain, - (), - >; + type DeliveryHelper = (); fn valid_destination() -> Result { Ok(DotLocation::get()) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index 444463ae26f1..e6d6162a2a3f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -29,12 +29,10 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, + xcm_config::AssetFeeAsExistentialDepositMultiplier, }; use polkadot_parachain_primitives::primitives::Sibling; -use sp_runtime::traits::{AccountIdConversion, ConvertInto}; -use westend_runtime_constants::system_parachain::SystemParachains; +use sp_runtime::traits::ConvertInto; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -44,7 +42,7 @@ use xcm_builder::{ NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, + WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -60,7 +58,6 @@ parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(1001)); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); - pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -446,12 +443,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount< - Self, - RelayOrOtherSystemParachains, - AccountId, - TreasuryAccount, - >; + type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 45c3db663a0e..dcf1c2d7ff12 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -38,7 +38,7 @@ use parachains_common::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; -use westend_runtime_constants::system_parachain::SystemParachains; +use westend_runtime_constants::system_parachains::{ASSET_HUB_ID, COLLECTIVES_ID, BRIDGE_HUB_ID}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -479,6 +479,12 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; +match_types! { + pub type SystemParachains: impl Contains = { + MultiLocation { parents: 1, interior: X1(Parachain(ASSET_HUB_ID | COLLECTIVES_ID | BRIDGE_HUB_ID ))} + }; +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml index 791eeac250cc..bfb0b9e71270 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -57,7 +57,6 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} -rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -112,7 +111,6 @@ std = [ "polkadot-core-primitives/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", - "rococo-runtime-constants/std", "scale-info/std", "serde", "sp-api/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 7947194f780a..5154ba676ef9 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -305,20 +305,6 @@ pub type RootOrFellows = EitherOfDiverse< EnsureXcm>, >; -parameter_types! { - /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = Concrete(xcm_config::KsmRelayLocation::get()); - /// The base fee for the message delivery fees. - pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); -} - -pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< - FeeAssetId, - BaseDeliveryFee, - TransactionByteFee, - XcmpQueue, ->; - impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -328,7 +314,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = RootOrFellows; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index d4cb694535aa..fba36e363a97 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -26,12 +26,9 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, + xcm_config::ConcreteNativeAssetFrom, }; use polkadot_parachain_primitives::primitives::Sibling; -use rococo_runtime_constants::system_parachain::SystemParachains; -use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -40,7 +37,6 @@ use xcm_builder::{ ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, - XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -54,7 +50,6 @@ parameter_types! { pub const MaxAssetsIntoHolding: u32 = 64; pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); pub const FellowshipLocation: MultiLocation = MultiLocation::parent(); - pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -213,12 +208,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount< - Self, - RelayOrOtherSystemParachains, - AccountId, - TreasuryAccount, - >; + type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml index e2f95d512c5a..eb0c18f5b460 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -57,7 +57,6 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} -westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -129,7 +128,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "westend-runtime-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 06328ed55fc2..dbf99c037603 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -305,20 +305,6 @@ pub type RootOrFellows = EitherOfDiverse< EnsureXcm>, >; -parameter_types! { - /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = Concrete(xcm_config::DotRelayLocation::get()); - /// The base fee for the message delivery fees. - pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); -} - -pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< - FeeAssetId, - BaseDeliveryFee, - TransactionByteFee, - XcmpQueue, ->; - impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -328,7 +314,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = RootOrFellows; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 99ac6d518730..6cb3c25ce412 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -26,12 +26,9 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, + xcm_config::ConcreteNativeAssetFrom, }; use polkadot_parachain_primitives::primitives::Sibling; -use sp_runtime::traits::AccountIdConversion; -use westend_runtime_constants::system_parachain::SystemParachains; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -40,7 +37,6 @@ use xcm_builder::{ ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, - XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -54,7 +50,6 @@ parameter_types! { pub const MaxAssetsIntoHolding: u32 = 64; pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(1001)); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); - pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -217,12 +212,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount< - Self, - RelayOrOtherSystemParachains, - AccountId, - TreasuryAccount, - >; + type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index 85a802cecc6b..e66cef31e56f 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -61,7 +61,6 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} -westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -212,7 +211,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "westend-runtime-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index cc4428061c5c..ff16f93d8f54 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -410,7 +410,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EitherOfDiverse, Fellows>; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - // TODO: This should have the price set type PriceForSiblingDelivery = (); } diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index cab51302ea8f..d8a12ee42dd2 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -26,14 +26,9 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, + xcm_config::ConcreteNativeAssetFrom, }; use polkadot_parachain_primitives::primitives::Sibling; -use sp_runtime::traits::AccountIdConversion; -use westend_runtime_constants::{ - system_parachain::SystemParachains, xcm::body::FELLOWSHIP_ADMIN_INDEX, -}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -42,10 +37,12 @@ use xcm_builder::{ LocatableAssetId, OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; +const FELLOWSHIP_ADMIN_INDEX: u32 = 1; + parameter_types! { pub const DotLocation: MultiLocation = MultiLocation::parent(); pub const RelayNetwork: Option = Some(NetworkId::Polkadot); @@ -54,7 +51,6 @@ parameter_types! { X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); - pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into(); pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); @@ -271,12 +267,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount< - Self, - RelayOrOtherSystemParachains, - AccountId, - TreasuryAccount, - >; + type FeeManager = (); type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; From e30bae66bff166ef9ea6f4b19c206caa8f147615 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 4 Oct 2023 17:28:09 -0300 Subject: [PATCH 093/116] Update lockfile --- Cargo.lock | 5 ----- .../assets/asset-hub-westend/src/xcm_config.rs | 11 +++++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3a378f7c87c..c6f0f6413827 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -743,7 +743,6 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-common", "primitive-types", - "rococo-runtime-constants", "scale-info", "smallvec", "sp-api", @@ -833,7 +832,6 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "westend-runtime-constants", ] [[package]] @@ -1808,7 +1806,6 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime-common", - "rococo-runtime-constants", "scale-info", "serde", "smallvec", @@ -1893,7 +1890,6 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "westend-runtime-constants", ] [[package]] @@ -2582,7 +2578,6 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "westend-runtime-constants", ] [[package]] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index dcf1c2d7ff12..a289ec145711 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -38,7 +38,7 @@ use parachains_common::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; -use westend_runtime_constants::system_parachains::{ASSET_HUB_ID, COLLECTIVES_ID, BRIDGE_HUB_ID}; +use westend_runtime_constants::system_parachain; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -481,7 +481,14 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia match_types! { pub type SystemParachains: impl Contains = { - MultiLocation { parents: 1, interior: X1(Parachain(ASSET_HUB_ID | COLLECTIVES_ID | BRIDGE_HUB_ID ))} + MultiLocation { + parents: 1, + interior: X1(Parachain( + system_parachain::ASSET_HUB_ID | + system_parachain::COLLECTIVES_ID | + system_parachain::BRIDGE_HUB_ID + )), + } }; } From d95d13c7b0ec03046f82d82755b9b7ad63b8d2ff Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 5 Oct 2023 04:52:46 -0300 Subject: [PATCH 094/116] Fix emulated tests --- Cargo.lock | 1 + .../assets/asset-hub-westend/Cargo.toml | 2 ++ .../src/tests/reserve_transfer.rs | 25 +++++++++++++++++-- .../asset-hub-westend/src/tests/teleport.rs | 25 +++++++++++++++++-- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6f0f6413827..781b4f1ad5f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -856,6 +856,7 @@ dependencies = [ "sp-runtime", "staging-xcm", "staging-xcm-executor", + "westend-runtime", "xcm-emulator", ] diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml index 7af3afa00d01..f3c05c93de4d 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml @@ -26,6 +26,7 @@ polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parac xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false } +westend-runtime = { path = "../../../../../../polkadot/runtime/westend", default-features = false } # Cumulus parachains-common = { path = "../../../../common" } @@ -51,4 +52,5 @@ runtime-benchmarks = [ "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-executor/runtime-benchmarks", + "westend-runtime/runtime-benchmarks", ] diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 03d16d5e321a..c07d3edd5b0c 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -14,6 +14,7 @@ // limitations under the License. use crate::*; +use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; use asset_hub_westend_runtime::xcm_config::XcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -183,10 +184,20 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { test.set_dispatchable::(relay_limited_reserve_transfer_assets); test.assert(); + let delivery_fees = Westend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } @@ -242,10 +253,20 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { test.set_dispatchable::(relay_reserve_transfer_assets); test.assert(); + let delivery_fees = Westend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs index 8de73a7420c6..f5fa0559a1fd 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs @@ -16,6 +16,7 @@ #![allow(dead_code)] // use crate::*; +use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -174,11 +175,21 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { test.set_dispatchable::(relay_limited_teleport_assets); test.assert(); + let delivery_fees = Westend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -277,11 +288,21 @@ fn teleport_native_assets_from_relay_to_system_para_works() { test.set_dispatchable::(relay_teleport_assets); test.assert(); + let delivery_fees = Westend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } From 842c78bc3462f996e294701029a36b1a1e768ef4 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 6 Oct 2023 05:22:17 -0300 Subject: [PATCH 095/116] Tackle no delivery fees scenario in runtime tests --- .../runtimes/assets/test-utils/src/xcm_helpers.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs index 0e661b9c6eb9..f036f9283dc3 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -20,7 +20,8 @@ use xcm::latest::prelude::*; /// Returns the delivery fees amount for pallet xcm's `teleport_assets` and /// `reserve_transfer_assets` extrinsics. -/// It assumes delivery fees are only paid in one asset and that asset is known. +/// Because it returns only a `u128`, it assumes delivery fees are only paid +/// in one asset and that asset is known. pub fn transfer_assets_delivery_fees( assets: MultiAssets, fee_asset_item: u32, @@ -30,8 +31,12 @@ pub fn transfer_assets_delivery_fees( ) -> u128 { let message = teleport_assets_dummy_message(assets, fee_asset_item, weight_limit, beneficiary); let Ok((_, delivery_fees)) = validate_send::(destination, message) else { unreachable!("message can be sent; qed") }; - let Fungible(delivery_fees_amount) = delivery_fees.inner()[0].fun else { unreachable!("asset is fungible; qed") }; - delivery_fees_amount + if let Some(delivery_fee) = delivery_fees.inner().first() { + let Fungible(delivery_fee_amount) = delivery_fee.fun else { unreachable!("asset is fungible; qed"); }; + delivery_fee_amount + } else { + 0 + } } /// Approximates the actual message sent by the teleport extrinsic. From b0624377c2bea689bcca79585b36dfdb6b0b15f6 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 11 Oct 2023 11:05:13 +0200 Subject: [PATCH 096/116] Format features --- .../emulated/assets/asset-hub-westend/Cargo.toml | 2 +- polkadot/runtime/common/Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml index 120684571463..f4f75dd31c54 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml @@ -61,7 +61,7 @@ runtime-benchmarks = [ "polkadot-runtime-common/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", "westend-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 3abcfec4b6a0..99f8345dd4e9 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -107,8 +107,8 @@ std = [ "sp-session/std", "sp-staking/std", "sp-std/std", - "xcm-executor/std", "xcm-builder/std", + "xcm-executor/std", "xcm/std", ] runtime-benchmarks = [ @@ -132,8 +132,8 @@ runtime-benchmarks = [ "runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] try-runtime = [ "frame-election-provider-support/try-runtime", From 73ad0fc1ad8b3f411a0187f75420a2736a523809 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 12 Oct 2023 15:22:56 +0200 Subject: [PATCH 097/116] Add UMP pricing (#1556) # Description Adds pricing for UMP, much like it was added for DMP in https://github.com/paritytech/polkadot/pull/6843 and HRMP in https://github.com/paritytech/polkadot-sdk/pull/1234. --------- Co-authored-by: command-bot <> Co-authored-by: Keith Yeung Co-authored-by: Liam Aharon --- Cargo.lock | 6 + cumulus/pallets/parachain-system/Cargo.toml | 4 + cumulus/pallets/parachain-system/src/lib.rs | 90 ++++++++++- cumulus/pallets/xcmp-queue/src/lib.rs | 48 +++--- cumulus/pallets/xcmp-queue/src/mock.rs | 3 +- cumulus/parachain-template/runtime/src/lib.rs | 4 +- .../assets/asset-hub-westend/Cargo.toml | 1 + .../src/tests/reserve_transfer.rs | 22 +-- .../asset-hub-westend/src/tests/teleport.rs | 53 ++++--- .../assets/asset-hub-kusama/src/lib.rs | 18 ++- .../assets/asset-hub-kusama/src/xcm_config.rs | 22 ++- .../assets/asset-hub-polkadot/src/lib.rs | 18 ++- .../asset-hub-polkadot/src/xcm_config.rs | 20 ++- .../assets/asset-hub-westend/Cargo.toml | 4 + .../assets/asset-hub-westend/src/lib.rs | 9 +- .../asset-hub-westend/src/xcm_config.rs | 38 +++-- .../assets/test-utils/src/test_cases.rs | 15 ++ .../assets/test-utils/src/xcm_helpers.rs | 63 +++++++- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 18 ++- .../bridge-hub-kusama/src/xcm_config.rs | 21 ++- .../bridge-hub-polkadot/src/lib.rs | 18 ++- .../bridge-hub-polkadot/src/xcm_config.rs | 21 ++- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 14 +- .../bridge-hub-rococo/src/xcm_config.rs | 14 +- .../collectives-polkadot/src/lib.rs | 20 ++- .../collectives-polkadot/src/xcm_config.rs | 16 +- .../contracts/contracts-rococo/src/lib.rs | 6 +- .../contracts-rococo/src/xcm_config.rs | 25 ++- .../runtimes/testing/penpal/src/lib.rs | 4 +- .../testing/rococo-parachain/Cargo.toml | 3 + .../testing/rococo-parachain/src/lib.rs | 4 +- cumulus/primitives/utility/Cargo.toml | 11 +- cumulus/primitives/utility/src/lib.rs | 79 +++++++--- polkadot/runtime/common/src/xcm_sender.rs | 75 ++++++--- polkadot/runtime/parachains/src/dmp.rs | 30 ++-- polkadot/runtime/parachains/src/lib.rs | 14 +- polkadot/runtime/rococo/src/lib.rs | 1 + polkadot/runtime/westend/src/lib.rs | 1 + .../xcm/pallet_xcm_benchmarks_fungible.rs | 34 ++--- .../src/fungible/benchmarking.rs | 26 +++- .../src/generic/benchmarking.rs | 142 ++++++++++++++++-- .../pallet-xcm-benchmarks/src/generic/mock.rs | 26 +++- .../pallet-xcm-benchmarks/src/generic/mod.rs | 5 + polkadot/xcm/src/v3/mod.rs | 4 +- .../procedural/src/pallet/expand/warnings.rs | 4 +- 45 files changed, 824 insertions(+), 250 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d858daa5e092..3343a5fbe3b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -869,6 +869,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "westend-runtime", + "westend-runtime-constants", "xcm-emulator", ] @@ -942,6 +943,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "westend-runtime", "westend-runtime-constants", ] @@ -3543,6 +3545,7 @@ dependencies = [ "log", "parity-scale-codec", "polkadot-parachain-primitives", + "polkadot-runtime-parachains", "sc-client-api", "scale-info", "sp-core", @@ -3723,8 +3726,10 @@ dependencies = [ "cumulus-primitives-core", "frame-support", "log", + "pallet-xcm-benchmarks", "parity-scale-codec", "polkadot-runtime-common", + "polkadot-runtime-parachains", "sp-io", "sp-runtime", "sp-std", @@ -13995,6 +14000,7 @@ dependencies = [ "parachains-common", "parity-scale-codec", "polkadot-parachain-primitives", + "polkadot-runtime-common", "scale-info", "sp-api", "sp-block-builder", diff --git a/cumulus/pallets/parachain-system/Cargo.toml b/cumulus/pallets/parachain-system/Cargo.toml index 5470dce47480..64e238ecab69 100644 --- a/cumulus/pallets/parachain-system/Cargo.toml +++ b/cumulus/pallets/parachain-system/Cargo.toml @@ -29,6 +29,7 @@ sp-version = { path = "../../../substrate/primitives/version", default-features # Polkadot polkadot-parachain-primitives = { path = "../../../polkadot/parachain", default-features = false, features = [ "wasm-api" ]} +polkadot-runtime-parachains = { path = "../../../polkadot/runtime/parachains", default-features = false } xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false} # Cumulus @@ -63,6 +64,7 @@ std = [ "frame-system/std", "log/std", "polkadot-parachain-primitives/std", + "polkadot-runtime-parachains/std", "scale-info/std", "sp-core/std", "sp-externalities/std", @@ -80,12 +82,14 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", + "polkadot-runtime-parachains/try-runtime", "sp-runtime/try-runtime", ] diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index eaf15768e290..3b1d0525d15f 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -45,6 +45,7 @@ use frame_support::{ }; use frame_system::{ensure_none, ensure_root, pallet_prelude::HeaderFor}; use polkadot_parachain_primitives::primitives::RelayChainBlockNumber; +use polkadot_runtime_parachains::FeeTracker; use scale_info::TypeInfo; use sp_runtime::{ traits::{Block as BlockT, BlockNumberProvider, Hash}, @@ -52,7 +53,7 @@ use sp_runtime::{ InvalidTransaction, TransactionLongevity, TransactionSource, TransactionValidity, ValidTransaction, }, - DispatchError, RuntimeDebug, + DispatchError, FixedU128, RuntimeDebug, Saturating, }; use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*}; use xcm::latest::XcmHash; @@ -177,6 +178,20 @@ where check_version: bool, } +pub mod ump_constants { + use super::FixedU128; + + /// `host_config.max_upward_queue_size / THRESHOLD_FACTOR` is the threshold after which delivery + /// starts getting exponentially more expensive. + /// `2` means the price starts to increase when queue is half full. + pub const THRESHOLD_FACTOR: u32 = 2; + /// The base number the delivery fee factor gets multiplied by every time it is increased. + /// Also the number it gets divided by when decreased. + pub const EXPONENTIAL_FEE_BASE: FixedU128 = FixedU128::from_rational(105, 100); // 1.05 + /// The base number message size in KB is multiplied by before increasing the fee factor. + pub const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0.001 +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -240,6 +255,9 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { + /// Handles actually sending upward messages by moving them from `PendingUpwardMessages` to + /// `UpwardMessages`. Decreases the delivery fee factor if after sending messages, the queue + /// total size is less than the threshold (see [`ump_constants::THRESHOLD_FACTOR`]). fn on_finalize(_: BlockNumberFor) { >::kill(); >::kill(); @@ -326,6 +344,17 @@ pub mod pallet { UpwardMessages::::put(&up[..num as usize]); *up = up.split_off(num as usize); + // If the total size of the pending messages is less than the threshold, + // we decrease the fee factor, since the queue is less congested. + // This makes delivery of new messages cheaper. + let threshold = host_config + .max_upward_queue_size + .saturating_div(ump_constants::THRESHOLD_FACTOR); + let remaining_total_size: usize = up.iter().map(UpwardMessage::len).sum(); + if remaining_total_size <= threshold as usize { + Self::decrease_fee_factor(()); + } + (num, total_size) }); @@ -721,7 +750,7 @@ pub mod pallet { StorageValue<_, Vec>, ValueQuery>; /// Storage field that keeps track of bandwidth used by the unincluded segment along with the - /// latest the latest HRMP watermark. Used for limiting the acceptance of new blocks with + /// latest HRMP watermark. Used for limiting the acceptance of new blocks with /// respect to relay chain constraints. #[pallet::storage] pub(super) type AggregatedUnincludedSegment = @@ -860,6 +889,17 @@ pub mod pallet { pub(super) type PendingUpwardMessages = StorageValue<_, Vec, ValueQuery>; + /// Initialization value for the delivery fee factor for UMP. + #[pallet::type_value] + pub fn UpwardInitialDeliveryFeeFactor() -> FixedU128 { + FixedU128::from_u32(1) + } + + /// The factor to multiply the base delivery fee by for UMP. + #[pallet::storage] + pub(super) type UpwardDeliveryFeeFactor = + StorageValue<_, FixedU128, ValueQuery, UpwardInitialDeliveryFeeFactor>; + /// The number of HRMP messages we observed in `on_initialize` and thus used that number for /// announcing the weight of `on_initialize` and `on_finalize`. #[pallet::storage] @@ -976,6 +1016,31 @@ impl Pallet { } } +impl FeeTracker for Pallet { + type Id = (); + + fn get_fee_factor(_: Self::Id) -> FixedU128 { + UpwardDeliveryFeeFactor::::get() + } + + fn increase_fee_factor(_: Self::Id, message_size_factor: FixedU128) -> FixedU128 { + >::mutate(|f| { + *f = f.saturating_mul( + ump_constants::EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor), + ); + *f + }) + } + + fn decrease_fee_factor(_: Self::Id) -> FixedU128 { + >::mutate(|f| { + *f = + UpwardInitialDeliveryFeeFactor::get().max(*f / ump_constants::EXPONENTIAL_FEE_BASE); + *f + }) + } +} + impl GetChannelInfo for Pallet { fn get_channel_status(id: ParaId) -> ChannelStatus { // Note, that we are using `relevant_messaging_state` which may be from the previous @@ -1468,7 +1533,13 @@ impl frame_system::SetCode for ParachainSetCode { } impl Pallet { + /// Puts a message in the `PendingUpwardMessages` storage item. + /// The message will be later sent in `on_finalize`. + /// Checks host configuration to see if message is too big. + /// Increases the delivery fee factor if the queue is sufficiently (see + /// [`ump_constants::THRESHOLD_FACTOR`]) congested. pub fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> { + let message_len = message.len(); // Check if the message fits into the relay-chain constraints. // // Note, that we are using `host_configuration` here which may be from the previous @@ -1482,9 +1553,21 @@ impl Pallet { // // However, changing this setting is expected to be rare. if let Some(cfg) = Self::host_configuration() { - if message.len() > cfg.max_upward_message_size as usize { + if message_len > cfg.max_upward_message_size as usize { return Err(MessageSendError::TooBig) } + let threshold = + cfg.max_upward_queue_size.saturating_div(ump_constants::THRESHOLD_FACTOR); + // We check the threshold against total size and not number of messages since messages + // could be big or small. + let pending_messages = PendingUpwardMessages::::get(); + let total_size: usize = pending_messages.iter().map(UpwardMessage::len).sum(); + if total_size > threshold as usize { + // We increase the fee factor by a factor based on the new message's size in KB + let message_size_factor = FixedU128::from((message_len / 1024) as u128) + .saturating_mul(ump_constants::MESSAGE_SIZE_FEE_BASE); + Self::increase_fee_factor((), message_size_factor); + } } else { // This storage field should carry over from the previous block. So if it's None // then it must be that this is an edge-case where a message is attempted to be @@ -1496,6 +1579,7 @@ impl Pallet { // // Thus fall through here. }; + >::append(message.clone()); // The relay ump does not use using_encoded diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index 812cecfc57c7..66204b021d78 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -47,7 +47,7 @@ use frame_support::{ traits::{EnsureOrigin, Get}, weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight}, }; -use polkadot_runtime_common::xcm_sender::PriceForParachainDelivery; +use polkadot_runtime_common::xcm_sender::PriceForMessageDelivery; use polkadot_runtime_parachains::FeeTracker; use rand_chacha::{ rand_core::{RngCore, SeedableRng}, @@ -110,7 +110,7 @@ pub mod pallet { type ControllerOriginConverter: ConvertOrigin; /// The price for delivering an XCM to a sibling parachain destination. - type PriceForSiblingDelivery: PriceForParachainDelivery; + type PriceForSiblingDelivery: PriceForMessageDelivery; /// The weight information of this pallet. type WeightInfo: WeightInfo; @@ -970,28 +970,6 @@ impl Pallet { } }); } - - /// Increases the delivery fee factor by a multiplicative factor and stores the resulting value. - /// - /// Returns the new delivery fee factor after the increase. - pub(crate) fn increase_fee_factor(para: ParaId, message_size_factor: FixedU128) -> FixedU128 { - >::mutate(para, |f| { - *f = f.saturating_mul(EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); - *f - }) - } - - /// Decreases the delivery fee factor by a multiplicative factor and stores the resulting value. - /// - /// Does not reduce the fee factor below the initial value, which is currently set as 1. - /// - /// Returns the new delivery fee factor after the decrease. - pub(crate) fn decrease_fee_factor(para: ParaId) -> FixedU128 { - >::mutate(para, |f| { - *f = InitialFactor::get().max(*f / EXPONENTIAL_FEE_BASE); - *f - }) - } } impl XcmpMessageHandler for Pallet { @@ -1203,7 +1181,7 @@ impl SendXcm for Pallet { MultiLocation { parents: 1, interior: X1(Parachain(id)) } => { let xcm = msg.take().ok_or(SendError::MissingArgument)?; let id = ParaId::from(*id); - let price = T::PriceForSiblingDelivery::price_for_parachain_delivery(id, &xcm); + let price = T::PriceForSiblingDelivery::price_for_delivery(id, &xcm); let versioned_xcm = T::VersionWrapper::wrap_version(&d, xcm) .map_err(|()| SendError::DestinationUnsupported)?; Ok(((id, versioned_xcm), price)) @@ -1231,7 +1209,23 @@ impl SendXcm for Pallet { } impl FeeTracker for Pallet { - fn get_fee_factor(para: ParaId) -> FixedU128 { - >::get(para) + type Id = ParaId; + + fn get_fee_factor(id: Self::Id) -> FixedU128 { + >::get(id) + } + + fn increase_fee_factor(id: Self::Id, message_size_factor: FixedU128) -> FixedU128 { + >::mutate(id, |f| { + *f = f.saturating_mul(EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); + *f + }) + } + + fn decrease_fee_factor(id: Self::Id) -> FixedU128 { + >::mutate(id, |f| { + *f = InitialFactor::get().max(*f / EXPONENTIAL_FEE_BASE); + *f + }) } } diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index a3f10fa5428c..e7ae1a68703e 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -23,6 +23,7 @@ use frame_support::{ traits::{ConstU32, Everything, Nothing, OriginTrait}, }; use frame_system::EnsureRoot; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, @@ -205,7 +206,7 @@ impl Config for Test { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = SystemParachainAsSuperuser; type WeightInfo = (); - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index b9bf97d7786f..b6bf8419ec46 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -10,6 +10,8 @@ mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use smallvec::smallvec; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; @@ -412,7 +414,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = (); - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml index f4f75dd31c54..fd8d78c6e8e5 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml @@ -31,6 +31,7 @@ xcm-builder = { package = "staging-xcm-builder", path = "../../../../../../polk xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} westend-runtime = { path = "../../../../../../polkadot/runtime/westend", default-features = false } +westend-runtime-constants = { path = "../../../../../../polkadot/runtime/westend/constants", default-features = false } # Cumulus parachains-common = { path = "../../../../common" } diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs index addbee69830a..3b48e6529ff7 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -14,8 +14,8 @@ // limitations under the License. use crate::*; -use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; use asset_hub_westend_runtime::xcm_config::XcmConfig; +use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -182,13 +182,9 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { test.assert(); let delivery_fees = Westend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); let sender_balance_after = test.sender.balance; @@ -251,13 +247,9 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { test.assert(); let delivery_fees = Westend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); let sender_balance_after = test.sender.balance; diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs index 51b4035c728d..a302344bb07c 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/teleport.rs @@ -16,6 +16,7 @@ #![allow(dead_code)] // use crate::*; +use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig; use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -175,13 +176,9 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { test.assert(); let delivery_fees = Westend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); let sender_balance_after = test.sender.balance; @@ -225,8 +222,14 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = AssetHubWestend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -260,8 +263,14 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = AssetHubWestend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance does not change assert_eq!(receiver_balance_after, receiver_balance_before); } @@ -288,13 +297,9 @@ fn teleport_native_assets_from_relay_to_system_para_works() { test.assert(); let delivery_fees = Westend::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); let sender_balance_after = test.sender.balance; @@ -335,11 +340,17 @@ fn teleport_native_assets_back_from_system_para_to_relay_works() { test.set_dispatchable::(system_para_teleport_assets); test.assert(); + let delivery_fees = AssetHubWestend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -370,11 +381,17 @@ fn teleport_native_assets_from_system_para_to_relay_fails() { test.set_dispatchable::(system_para_teleport_assets); test.assert(); + let delivery_fees = AssetHubWestend::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance does not change assert_eq!(receiver_balance_after, receiver_balance_before); } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index cd49d516a53a..5c51a3a52324 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -34,6 +34,8 @@ use assets_common::{ AssetIdForTrustBackedAssetsConvert, MultiLocationForAssetId, }; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -645,7 +647,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { >; type ControllerOriginConverter = xcm_config::XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -1211,10 +1213,21 @@ impl_runtime_apis! { use xcm_config::{KsmLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + KsmLocation::get(), + ExistentialDeposit::get() + ).into()); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); // No requirement for UMP + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForParentDelivery, + >; fn valid_destination() -> Result { Ok(KsmLocation::get()) } @@ -1270,6 +1283,7 @@ impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 0a7176847017..c53db960cc81 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -16,9 +16,9 @@ use super::{ AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; -use crate::ForeignAssets; +use crate::{ForeignAssets, CENTS}; use assets_common::{ local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation, matching::{ @@ -31,11 +31,9 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{ - impls::ToStakingPot, - xcm_config::AssetFeeAsExistentialDepositMultiplier, -}; +use parachains_common::{impls::ToStakingPot, xcm_config::AssetFeeAsExistentialDepositMultiplier}; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use sp_runtime::traits::ConvertInto; use xcm::latest::prelude::*; use xcm_builder::{ @@ -531,11 +529,21 @@ impl xcm_executor::Config for XcmConfig { /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(KsmLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForParentDelivery = + ExponentialPrice; + /// The means for routing XCM messages which are not for local execution into the right message /// queues. pub type XcmRouter = WithUniqueTopic<( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index 0869748c9361..b58d094deec6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -66,6 +66,8 @@ use assets_common::{ foreign_creators::ForeignCreators, matching::FromSiblingParachain, MultiLocationForAssetId, }; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -581,7 +583,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { EnsureXcm>, >; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -1090,10 +1092,21 @@ impl_runtime_apis! { use xcm_config::{DotLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + xcm_config::DotLocation::get(), + ExistentialDeposit::get() + ).into()); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForParentDelivery, + >; fn valid_destination() -> Result { Ok(DotLocation::get()) } @@ -1149,6 +1162,7 @@ impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index e6d6162a2a3f..92c17ed872c2 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -16,7 +16,7 @@ use super::{ AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ForeignAssets, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, CENTS, }; use assets_common::matching::{ FromSiblingParachain, IsForeignConcreteAsset, StartsWith, StartsWithExplicitGlobalConsensus, @@ -27,11 +27,9 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{ - impls::ToStakingPot, - xcm_config::AssetFeeAsExistentialDepositMultiplier, -}; +use parachains_common::{impls::ToStakingPot, xcm_config::AssetFeeAsExistentialDepositMultiplier}; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use sp_runtime::traits::ConvertInto; use xcm::latest::prelude::*; use xcm_builder::{ @@ -455,11 +453,21 @@ impl xcm_executor::Config for XcmConfig { /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(DotLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForParentDelivery = + ExponentialPrice; + /// The means for routing XCM messages which are not for local execution into the right message /// queues. pub type XcmRouter = WithUniqueTopic<( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index f7f6fdf68e46..cb5fba1684cc 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -60,6 +60,7 @@ polkadot-core-primitives = { path = "../../../../../polkadot/core-primitives", d polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false} polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false} westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false} +westend-runtime = { path = "../../../../../polkadot/runtime/westend", default-features = false } xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} @@ -116,6 +117,7 @@ runtime-benchmarks = [ "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "westend-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", ] @@ -149,6 +151,7 @@ try-runtime = [ "parachain-info/try-runtime", "polkadot-runtime-common/try-runtime", "sp-runtime/try-runtime", + "westend-runtime/try-runtime", ] std = [ "assets-common/std", @@ -210,6 +213,7 @@ std = [ "sp-version/std", "substrate-wasm-builder", "westend-runtime-constants/std", + "westend-runtime/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 40cdd6380261..97b4ae986c2c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1276,25 +1276,21 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::{MaxAssetsIntoHolding, WestendLocation}; use pallet_xcm_benchmarks::asset_instance_from; - use cumulus_primitives_core::ParaId; parameter_types! { pub ExistentialDepositMultiAsset: Option = Some(( xcm_config::WestendLocation::get(), ExistentialDeposit::get() ).into()); - pub ToParachain: ParaId = westend_runtime_constants::system_parachain::BRIDGE_HUB_ID.into(); } impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper< + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< XcmConfig, ExistentialDepositMultiAsset, - PriceForSiblingParachainDelivery, - ToParachain, - (), + xcm_config::PriceForParentDelivery, >; fn valid_destination() -> Result { Ok(WestendLocation::get()) @@ -1351,6 +1347,7 @@ impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index a175c3129fb7..24cd063e3b2d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -14,9 +14,10 @@ // limitations under the License. use super::{ - AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ParachainInfo, - ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, BaseDeliveryFee, + FeeAssetId, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, + RuntimeEvent, RuntimeOrigin, TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, + XcmpQueue, }; use crate::ForeignAssets; use assets_common::{ @@ -37,7 +38,9 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use westend_runtime::Treasury as WestendTreasury; use westend_runtime_constants::system_parachain; use xcm::latest::prelude::*; use xcm_builder::{ @@ -500,6 +503,23 @@ match_types! { }; } +parameter_types! { + pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(::index() as u8)).into(); +} + +pub struct RelayTreasury; +impl Contains for RelayTreasury { + fn contains(location: &MultiLocation) -> bool { + let relay_treasury_location = RelayTreasuryLocation::get(); + *location == relay_treasury_location + } +} + +/// Locations that will not be charged fees in the executor, +/// either execution or delivery. +/// We only waive fees for system functions, which these locations represent. +pub type WaivedLocations = (RelayOrOtherSystemParachains, RelayTreasury); + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -546,12 +566,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - type FeeManager = XcmFeesToAccount< - Self, - RelayOrOtherSystemParachains, - AccountId, - TreasuryAccount, - >; + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; @@ -562,11 +577,14 @@ impl xcm_executor::Config for XcmConfig { /// Local origins on this chain are allowed to dispatch XCM sends/executions. pub type LocalOriginToLocation = SignedToAccountId32; +pub type PriceForParentDelivery = + ExponentialPrice; + /// The means for routing XCM messages which are not for local execution into the right message /// queues. pub type XcmRouter = WithUniqueTopic<( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 51689c828663..215d29185349 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -177,6 +177,21 @@ pub fn teleports_for_native_asset_works< target_account_balance_before_teleport - existential_deposit ); + // Mint funds into account to ensure it has enough balance to pay delivery fees + let delivery_fees = + xcm_helpers::transfer_assets_delivery_fees::( + (native_asset_id, native_asset_to_teleport_away.into()).into(), + 0, + Unlimited, + dest_beneficiary, + dest, + ); + >::mint_into( + &target_account, + delivery_fees.into(), + ) + .unwrap(); + assert_ok!(RuntimeHelper::::do_teleport_assets::( RuntimeHelper::::origin_of(target_account.clone()), dest, diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs index f036f9283dc3..0aebe38fef53 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/xcm_helpers.rs @@ -30,13 +30,47 @@ pub fn transfer_assets_delivery_fees( destination: MultiLocation, ) -> u128 { let message = teleport_assets_dummy_message(assets, fee_asset_item, weight_limit, beneficiary); - let Ok((_, delivery_fees)) = validate_send::(destination, message) else { unreachable!("message can be sent; qed") }; - if let Some(delivery_fee) = delivery_fees.inner().first() { - let Fungible(delivery_fee_amount) = delivery_fee.fun else { unreachable!("asset is fungible; qed"); }; - delivery_fee_amount - } else { - 0 - } + get_fungible_delivery_fees::(destination, message) +} + +/// Returns the delivery fees amount for a query response as a result of the execution +/// of a `ExpectError` instruction with no error. +pub fn query_response_delivery_fees(querier: MultiLocation) -> u128 { + // Message to calculate delivery fees, it's encoded size is what's important. + // This message reports that there was no error, if an error is reported, the encoded size would + // be different. + let message = Xcm(vec![ + SetFeesMode { jit_withdraw: true }, + QueryResponse { + query_id: 0, // Dummy query id + response: Response::ExecutionResult(None), + max_weight: Weight::zero(), + querier: Some(querier), + }, + SetTopic([0u8; 32]), // Dummy topic + ]); + get_fungible_delivery_fees::(querier, message) +} + +/// Returns the delivery fees amount for the execution of `PayOverXcm` +pub fn pay_over_xcm_delivery_fees( + interior: Junctions, + destination: MultiLocation, + beneficiary: MultiLocation, + asset: MultiAsset, +) -> u128 { + // This is a dummy message. + // The encoded size is all that matters for delivery fees. + let message = Xcm(vec![ + DescendOrigin(interior), + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + SetAppendix(Xcm(vec![ + SetFeesMode { jit_withdraw: true }, + ReportError(QueryResponseInfo { destination, query_id: 0, max_weight: Weight::zero() }), + ])), + TransferAsset { beneficiary, assets: vec![asset].into() }, + ]); + get_fungible_delivery_fees::(destination, message) } /// Approximates the actual message sent by the teleport extrinsic. @@ -57,3 +91,18 @@ fn teleport_assets_dummy_message( SetTopic([0u8; 32]), // Dummy topic ]) } + +/// Given a message, a sender, and a destination, it returns the delivery fees +fn get_fungible_delivery_fees(destination: MultiLocation, message: Xcm<()>) -> u128 { + let Ok((_, delivery_fees)) = validate_send::(destination, message) else { + unreachable!("message can be sent; qed") + }; + if let Some(delivery_fee) = delivery_fees.inner().first() { + let Fungible(delivery_fee_amount) = delivery_fee.fun else { + unreachable!("asset is fungible; qed"); + }; + delivery_fee_amount + } else { + 0 + } +} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 5154ba676ef9..190987b1cfeb 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -26,6 +26,8 @@ mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -314,7 +316,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = RootOrFellows; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -671,10 +673,21 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::KsmRelayLocation; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + xcm_config::KsmRelayLocation::get(), + ExistentialDeposit::get() + ).into()); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); // No requirements for UMP + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForParentDelivery, + >; fn valid_destination() -> Result { Ok(KsmRelayLocation::get()) } @@ -715,6 +728,7 @@ impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index fba36e363a97..addc2fc5c3d5 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -16,7 +16,8 @@ use super::{ AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmpQueue, + CENTS, }; use frame_support::{ match_types, parameter_types, @@ -24,11 +25,9 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{ - impls::ToStakingPot, - xcm_config::ConcreteNativeAssetFrom, -}; +use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -220,11 +219,21 @@ impl xcm_executor::Config for XcmConfig { /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(KsmRelayLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForParentDelivery = + ExponentialPrice; + /// The means for routing XCM messages which are not for local execution into the right message /// queues. pub type XcmRouter = WithUniqueTopic<( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index dbf99c037603..dc23135f05d7 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -26,6 +26,8 @@ mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -314,7 +316,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = RootOrFellows; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -671,10 +673,21 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::DotRelayLocation; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + xcm_config::DotRelayLocation::get(), + ExistentialDeposit::get() + ).into()); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); // No requirements for UMP + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForParentDelivery, + >; fn valid_destination() -> Result { Ok(DotRelayLocation::get()) } @@ -715,6 +728,7 @@ impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 6cb3c25ce412..6d1ffb193eb3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -16,7 +16,8 @@ use super::{ AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmpQueue, + CENTS, }; use frame_support::{ match_types, parameter_types, @@ -24,11 +25,9 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{ - impls::ToStakingPot, - xcm_config::ConcreteNativeAssetFrom, -}; +use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -224,11 +223,21 @@ impl xcm_executor::Config for XcmConfig { /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(DotRelayLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForParentDelivery = + ExponentialPrice; + /// The means for routing XCM messages which are not for local execution into the right message /// queues. pub type XcmRouter = WithUniqueTopic<( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index a1c30e8ac7f0..0052207856a3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -999,10 +999,21 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::RelayLocation; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + xcm_config::RelayLocation::get(), + ExistentialDeposit::get() + ).into()); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; - type DeliveryHelper = (); // No requirements for UMP + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForParentDelivery, + >; fn valid_destination() -> Result { Ok(RelayLocation::get()) } @@ -1043,6 +1054,7 @@ impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 3baa90dadcf0..e392ca056d0e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -15,10 +15,10 @@ // along with Cumulus. If not, see . use super::{ - AccountId, AllPalletsWithSystem, Balances, BridgeGrandpaRococoInstance, - BridgeGrandpaWococoInstance, DeliveryRewardInBalance, ParachainInfo, ParachainSystem, - PolkadotXcm, RequiredStakeForStakeAndSlash, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, Balances, BaseDeliveryFee, BridgeGrandpaRococoInstance, + BridgeGrandpaWococoInstance, DeliveryRewardInBalance, FeeAssetId, ParachainInfo, + ParachainSystem, PolkadotXcm, RequiredStakeForStakeAndSlash, Runtime, RuntimeCall, + RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmpQueue, }; use crate::{ bridge_hub_rococo_config::ToBridgeHubWococoHaulBlobExporter, @@ -36,6 +36,7 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use rococo_runtime_constants::system_parachain::SystemParachains; use sp_core::Get; use sp_runtime::traits::AccountIdConversion; @@ -272,6 +273,9 @@ impl xcm_executor::Config for XcmConfig { type Aliasers = Nothing; } +pub type PriceForParentDelivery = + ExponentialPrice; + /// Converts a local signed origin into an XCM multilocation. /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; @@ -280,7 +284,7 @@ pub type LocalOriginToLocation = SignedToAccountId32, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index ff16f93d8f54..cec4152bcc31 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -45,6 +45,7 @@ pub mod fellowship; pub use ambassador::pallet_ambassador_origins; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; use fellowship::{ migration::import_kusama_fellowship, pallet_fellowship_origins, Fellows, FellowshipCollectiveInstance, @@ -98,7 +99,7 @@ pub use sp_runtime::BuildStorage; // Polkadot imports use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use xcm::latest::BodyId; +use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -401,6 +402,20 @@ impl parachain_info::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {} +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::DotLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -410,7 +425,8 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EitherOfDiverse, Fellows>; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = + polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index d8a12ee42dd2..9cf7ee4fe243 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -14,8 +14,9 @@ // limitations under the License. use super::{ - AccountId, AllPalletsWithSystem, Balances, Fellows, ParachainInfo, ParachainSystem, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, Balances, BaseDeliveryFee, FeeAssetId, Fellows, ParachainInfo, + ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + TransactionByteFee, WeightToFee, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -24,11 +25,9 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use parachains_common::{ - impls::ToStakingPot, - xcm_config::ConcreteNativeAssetFrom, -}; +use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -279,11 +278,14 @@ impl xcm_executor::Config for XcmConfig { /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; +pub type PriceForParentDelivery = + ExponentialPrice; + /// The means for routing XCM messages which are not for local execution into the right message /// queues. pub type XcmRouter = WithUniqueTopic<( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 70392c5ecbcc..1ea3eaa2e478 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -224,13 +224,17 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = ConstU32<0>; } +parameter_types! { + pub const TransactionByteFee: Balance = MILLICENTS; +} + impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter>; type WeightToFee = WeightToFee; /// Relay Chain `TransactionByteFee` / 10 - type LengthToFee = ConstantMultiplier>; + type LengthToFee = ConstantMultiplier; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; type OperationalFeeMultiplier = ConstU8<5>; } diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index 3bf2b3e50816..52d72ba84e0a 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -15,8 +15,9 @@ use super::{ AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmpQueue, }; +use crate::common::rococo::currency::CENTS; use frame_support::{ match_types, parameter_types, traits::{ConstU32, EitherOfDiverse, Everything, Nothing}, @@ -26,6 +27,7 @@ use frame_system::EnsureRoot; use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough}; use parachains_common::{xcm_config::RelayOrOtherSystemParachains, TREASURY_PALLET_ID}; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use rococo_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; @@ -184,11 +186,14 @@ impl xcm_executor::Config for XcmConfig { /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; +pub type PriceForParentDelivery = + ExponentialPrice; + /// The means for routing XCM messages which are not for local execution into the right message /// queues. pub type XcmRouter = WithUniqueTopic<( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, )>; @@ -236,6 +241,20 @@ impl cumulus_pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; } +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(RelayLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -248,7 +267,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { >; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index fe0f19c30632..86389425eb5e 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -33,6 +33,7 @@ mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -50,6 +51,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use smallvec::smallvec; use sp_api::impl_runtime_apis; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -488,7 +490,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = (); - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml b/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml index 029d5d10f986..a662a5e80665 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml @@ -42,6 +42,7 @@ polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", de xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false} xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false} +polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -86,6 +87,7 @@ std = [ "parachain-info/std", "parachains-common/std", "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", @@ -118,6 +120,7 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 50c5a445c25f..dcea349f3a0e 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -23,6 +23,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_api::impl_runtime_apis; use sp_core::OpaqueMetadata; use sp_runtime::{ @@ -511,7 +513,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = NoPriceForMessageDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/primitives/utility/Cargo.toml b/cumulus/primitives/utility/Cargo.toml index 9ed1e664ac21..691a4599b2c4 100644 --- a/cumulus/primitives/utility/Cargo.toml +++ b/cumulus/primitives/utility/Cargo.toml @@ -15,11 +15,12 @@ sp-runtime = { path = "../../../substrate/primitives/runtime", default-features sp-std = { path = "../../../substrate/primitives/std", default-features = false} # Polkadot -polkadot-runtime-common = { path = "../../../polkadot/runtime/common", default-features = false} -xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false} +polkadot-runtime-common = { path = "../../../polkadot/runtime/common", default-features = false } +polkadot-runtime-parachains = { path = "../../../polkadot/runtime/parachains", default-features = false } +xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot/xcm/xcm-executor", default-features = false} xcm-builder = { package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder", default-features = false} - +pallet-xcm-benchmarks = { path = "../../../polkadot/xcm/pallet-xcm-benchmarks", default-features = false } # Cumulus cumulus-primitives-core = { path = "../core", default-features = false } @@ -30,7 +31,9 @@ std = [ "codec/std", "cumulus-primitives-core/std", "frame-support/std", + "pallet-xcm-benchmarks/std", "polkadot-runtime-common/std", + "polkadot-runtime-parachains/std", "sp-io/std", "sp-runtime/std", "sp-std/std", @@ -41,7 +44,9 @@ std = [ runtime-benchmarks = [ "frame-support/runtime-benchmarks", + "pallet-xcm-benchmarks/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", + "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", diff --git a/cumulus/primitives/utility/src/lib.rs b/cumulus/primitives/utility/src/lib.rs index 024598a99198..c4ce67194855 100644 --- a/cumulus/primitives/utility/src/lib.rs +++ b/cumulus/primitives/utility/src/lib.rs @@ -28,29 +28,13 @@ use frame_support::{ }, weights::Weight, }; -use polkadot_runtime_common::xcm_sender::ConstantPrice; +use polkadot_runtime_common::xcm_sender::PriceForMessageDelivery; use sp_runtime::{traits::Saturating, SaturatedConversion}; use sp_std::{marker::PhantomData, prelude::*}; use xcm::{latest::prelude::*, WrapVersion}; use xcm_builder::TakeRevenue; use xcm_executor::traits::{MatchesFungibles, TransactAsset, WeightTrader}; -pub trait PriceForParentDelivery { - fn price_for_parent_delivery(message: &Xcm<()>) -> MultiAssets; -} - -impl PriceForParentDelivery for () { - fn price_for_parent_delivery(_: &Xcm<()>) -> MultiAssets { - MultiAssets::new() - } -} - -impl> PriceForParentDelivery for ConstantPrice { - fn price_for_parent_delivery(_: &Xcm<()>) -> MultiAssets { - T::get() - } -} - /// Xcm router which recognises the `Parent` destination and handles it by sending the message into /// the given UMP `UpwardMessageSender` implementation. Thus this essentially adapts an /// `UpwardMessageSender` trait impl into a `SendXcm` trait impl. @@ -63,7 +47,7 @@ impl SendXcm for ParentAsUmp where T: UpwardMessageSender, W: WrapVersion, - P: PriceForParentDelivery, + P: PriceForMessageDelivery, { type Ticket = Vec; @@ -76,7 +60,7 @@ where if d.contains_parents_only(1) { // An upward message for the relay chain. let xcm = msg.take().ok_or(SendError::MissingArgument)?; - let price = P::price_for_parent_delivery(&xcm); + let price = P::price_for_delivery((), &xcm); let versioned_xcm = W::wrap_version(&d, xcm).map_err(|()| SendError::DestinationUnsupported)?; let data = versioned_xcm.encode(); @@ -280,7 +264,7 @@ pub struct XcmFeesTo32ByteAccount, - ReceiverAccount: frame_support::traits::Get>, + ReceiverAccount: Get>, > TakeRevenue for XcmFeesTo32ByteAccount { fn take_revenue(revenue: MultiAsset) { @@ -540,3 +524,58 @@ mod tests { assert_eq!(trader.buy_weight(weight_to_buy, payment, &ctx), Err(XcmError::NotWithdrawable)); } } + +/// Implementation of `pallet_xcm_benchmarks::EnsureDelivery` which helps to ensure delivery to the +/// parent relay chain. Deposits existential deposit for origin (if needed). +/// Deposits estimated fee to the origin account (if needed). +/// Allows to trigger additional logic for specific `ParaId` (e.g. open HRMP channel) (if neeeded). +#[cfg(feature = "runtime-benchmarks")] +pub struct ToParentDeliveryHelper( + sp_std::marker::PhantomData<(XcmConfig, ExistentialDeposit, PriceForDelivery)>, +); + +#[cfg(feature = "runtime-benchmarks")] +impl< + XcmConfig: xcm_executor::Config, + ExistentialDeposit: Get>, + PriceForDelivery: PriceForMessageDelivery, + > pallet_xcm_benchmarks::EnsureDelivery + for ToParentDeliveryHelper +{ + fn ensure_successful_delivery( + origin_ref: &MultiLocation, + _dest: &MultiLocation, + fee_reason: xcm_executor::traits::FeeReason, + ) -> (Option, Option) { + use xcm::latest::{MAX_INSTRUCTIONS_TO_DECODE, MAX_ITEMS_IN_MULTIASSETS}; + use xcm_executor::{traits::FeeManager, FeesMode}; + + let mut fees_mode = None; + if !XcmConfig::FeeManager::is_waived(Some(origin_ref), fee_reason) { + // if not waived, we need to set up accounts for paying and receiving fees + + // mint ED to origin if needed + if let Some(ed) = ExistentialDeposit::get() { + XcmConfig::AssetTransactor::deposit_asset(&ed, &origin_ref, None).unwrap(); + } + + // overestimate delivery fee + let mut max_assets: Vec = Vec::new(); + for i in 0..MAX_ITEMS_IN_MULTIASSETS { + max_assets.push((GeneralIndex(i as u128), 100u128).into()); + } + let overestimated_xcm = + vec![WithdrawAsset(max_assets.into()); MAX_INSTRUCTIONS_TO_DECODE as usize].into(); + let overestimated_fees = PriceForDelivery::price_for_delivery((), &overestimated_xcm); + + // mint overestimated fee to origin + for fee in overestimated_fees.inner() { + XcmConfig::AssetTransactor::deposit_asset(&fee, &origin_ref, None).unwrap(); + } + + // expected worst case - direct withdraw + fees_mode = Some(FeesMode { jit_withdraw: true }); + } + (fees_mode, None) + } +} diff --git a/polkadot/runtime/common/src/xcm_sender.rs b/polkadot/runtime/common/src/xcm_sender.rs index 846206cd88b5..4d31c92cdd3a 100644 --- a/polkadot/runtime/common/src/xcm_sender.rs +++ b/polkadot/runtime/common/src/xcm_sender.rs @@ -31,25 +31,40 @@ use SendError::*; /// Simple value-bearing trait for determining/expressing the assets required to be paid for a /// messages to be delivered to a parachain. -pub trait PriceForParachainDelivery { +pub trait PriceForMessageDelivery { + /// Type used for charging different prices to different destinations + type Id; /// Return the assets required to deliver `message` to the given `para` destination. - fn price_for_parachain_delivery(para: ParaId, message: &Xcm<()>) -> MultiAssets; + fn price_for_delivery(id: Self::Id, message: &Xcm<()>) -> MultiAssets; } -impl PriceForParachainDelivery for () { - fn price_for_parachain_delivery(_: ParaId, _: &Xcm<()>) -> MultiAssets { +impl PriceForMessageDelivery for () { + type Id = (); + + fn price_for_delivery(_: Self::Id, _: &Xcm<()>) -> MultiAssets { + MultiAssets::new() + } +} + +pub struct NoPriceForMessageDelivery(PhantomData); +impl PriceForMessageDelivery for NoPriceForMessageDelivery { + type Id = Id; + + fn price_for_delivery(_: Self::Id, _: &Xcm<()>) -> MultiAssets { MultiAssets::new() } } -/// Implementation of [`PriceForParachainDelivery`] which returns a fixed price. +/// Implementation of [`PriceForMessageDelivery`] which returns a fixed price. pub struct ConstantPrice(sp_std::marker::PhantomData); -impl> PriceForParachainDelivery for ConstantPrice { - fn price_for_parachain_delivery(_: ParaId, _: &Xcm<()>) -> MultiAssets { +impl> PriceForMessageDelivery for ConstantPrice { + type Id = (); + + fn price_for_delivery(_: Self::Id, _: &Xcm<()>) -> MultiAssets { T::get() } } -/// Implementation of [`PriceForParachainDelivery`] which returns an exponentially increasing price. +/// Implementation of [`PriceForMessageDelivery`] which returns an exponentially increasing price. /// The formula for the fee is based on the sum of a base fee plus a message length fee, multiplied /// by a specified factor. In mathematical form: /// @@ -64,13 +79,15 @@ impl> PriceForParachainDelivery for ConstantPrice { /// - `M`: The fee to pay for each and every byte of the message after encoding it. /// - `F`: A fee factor multiplier. It can be understood as the exponent term in the formula. pub struct ExponentialPrice(sp_std::marker::PhantomData<(A, B, M, F)>); -impl, B: Get, M: Get, F: FeeTracker> PriceForParachainDelivery +impl, B: Get, M: Get, F: FeeTracker> PriceForMessageDelivery for ExponentialPrice { - fn price_for_parachain_delivery(para: ParaId, msg: &Xcm<()>) -> MultiAssets { + type Id = F::Id; + + fn price_for_delivery(id: Self::Id, msg: &Xcm<()>) -> MultiAssets { let msg_fee = (msg.encoded_size() as u128).saturating_mul(M::get()); let fee_sum = B::get().saturating_add(msg_fee); - let amount = F::get_fee_factor(para).saturating_mul_int(fee_sum); + let amount = F::get_fee_factor(id).saturating_mul_int(fee_sum); (A::get(), amount).into() } } @@ -78,8 +95,10 @@ impl, B: Get, M: Get, F: FeeTracker> PriceForParacha /// XCM sender for relay chain. It only sends downward message. pub struct ChildParachainRouter(PhantomData<(T, W, P)>); -impl - SendXcm for ChildParachainRouter +impl SendXcm + for ChildParachainRouter +where + P: PriceForMessageDelivery, { type Ticket = (HostConfiguration>, ParaId, Vec); @@ -99,7 +118,7 @@ impl>::config(); let para = id.into(); - let price = P::price_for_parachain_delivery(para, &xcm); + let price = P::price_for_delivery(para, &xcm); let blob = W::wrap_version(&d, xcm).map_err(|()| DestinationUnsupported)?.encode(); >::can_queue_downward_message(&config, ¶, &blob) .map_err(Into::::into)?; @@ -142,7 +161,7 @@ pub struct ToParachainDeliveryHelper< impl< XcmConfig: xcm_executor::Config, ExistentialDeposit: Get>, - PriceForDelivery: PriceForParachainDelivery, + PriceForDelivery: PriceForMessageDelivery, Parachain: Get, ToParachainHelper: EnsureForParachain, > pallet_xcm_benchmarks::EnsureDelivery @@ -175,10 +194,8 @@ impl< // overestimate delivery fee let overestimated_xcm = vec![ClearOrigin; 128].into(); - let overestimated_fees = PriceForDelivery::price_for_parachain_delivery( - Parachain::get(), - &overestimated_xcm, - ); + let overestimated_fees = + PriceForDelivery::price_for_delivery(Parachain::get(), &overestimated_xcm); // mint overestimated fee to origin for fee in overestimated_fees.inner() { @@ -202,7 +219,7 @@ pub trait EnsureForParachain { } #[cfg(feature = "runtime-benchmarks")] impl EnsureForParachain for () { - fn ensure(_para_id: ParaId) { + fn ensure(_: ParaId) { // doing nothing } } @@ -222,7 +239,17 @@ mod tests { struct TestFeeTracker; impl FeeTracker for TestFeeTracker { - fn get_fee_factor(_: ParaId) -> FixedU128 { + type Id = ParaId; + + fn get_fee_factor(_: Self::Id) -> FixedU128 { + FixedU128::from_rational(101, 100) + } + + fn increase_fee_factor(_: Self::Id, _: FixedU128) -> FixedU128 { + FixedU128::from_rational(101, 100) + } + + fn decrease_fee_factor(_: Self::Id) -> FixedU128 { FixedU128::from_rational(101, 100) } } @@ -240,21 +267,21 @@ mod tests { // message_length = 1 let result: u128 = TestFeeTracker::get_fee_factor(id).saturating_mul_int(b + m); assert_eq!( - TestExponentialPrice::price_for_parachain_delivery(id, &Xcm(vec![])), + TestExponentialPrice::price_for_delivery(id, &Xcm(vec![])), (FeeAssetId::get(), result).into() ); // message size = 2 let result: u128 = TestFeeTracker::get_fee_factor(id).saturating_mul_int(b + (2 * m)); assert_eq!( - TestExponentialPrice::price_for_parachain_delivery(id, &Xcm(vec![ClearOrigin])), + TestExponentialPrice::price_for_delivery(id, &Xcm(vec![ClearOrigin])), (FeeAssetId::get(), result).into() ); // message size = 4 let result: u128 = TestFeeTracker::get_fee_factor(id).saturating_mul_int(b + (4 * m)); assert_eq!( - TestExponentialPrice::price_for_parachain_delivery( + TestExponentialPrice::price_for_delivery( id, &Xcm(vec![SetAppendix(Xcm(vec![ClearOrigin]))]) ), diff --git a/polkadot/runtime/parachains/src/dmp.rs b/polkadot/runtime/parachains/src/dmp.rs index bfc3be456e6c..78994a9e34ba 100644 --- a/polkadot/runtime/parachains/src/dmp.rs +++ b/polkadot/runtime/parachains/src/dmp.rs @@ -336,32 +336,26 @@ impl Pallet { ) -> Vec>> { DownwardMessageQueues::::get(&recipient) } +} - /// Increases the delivery fee factor by a multiplicative factor and stores the resulting value. - /// - /// Returns the new delivery fee factor after the increase. - pub(crate) fn increase_fee_factor(para: ParaId, message_size_factor: FixedU128) -> FixedU128 { - >::mutate(para, |f| { +impl FeeTracker for Pallet { + type Id = ParaId; + + fn get_fee_factor(id: Self::Id) -> FixedU128 { + DeliveryFeeFactor::::get(id) + } + + fn increase_fee_factor(id: Self::Id, message_size_factor: FixedU128) -> FixedU128 { + >::mutate(id, |f| { *f = f.saturating_mul(EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); *f }) } - /// Decreases the delivery fee factor by a multiplicative factor and stores the resulting value. - /// - /// Does not reduce the fee factor below the initial value, which is currently set as 1. - /// - /// Returns the new delivery fee factor after the decrease. - pub(crate) fn decrease_fee_factor(para: ParaId) -> FixedU128 { - >::mutate(para, |f| { + fn decrease_fee_factor(id: Self::Id) -> FixedU128 { + >::mutate(id, |f| { *f = InitialFactor::get().max(*f / EXPONENTIAL_FEE_BASE); *f }) } } - -impl FeeTracker for Pallet { - fn get_fee_factor(para: ParaId) -> FixedU128 { - DeliveryFeeFactor::::get(para) - } -} diff --git a/polkadot/runtime/parachains/src/lib.rs b/polkadot/runtime/parachains/src/lib.rs index 7477a06d16a3..bc35ade4c6eb 100644 --- a/polkadot/runtime/parachains/src/lib.rs +++ b/polkadot/runtime/parachains/src/lib.rs @@ -59,9 +59,21 @@ use sp_runtime::{DispatchResult, FixedU128}; /// Trait for tracking message delivery fees on a transport protocol. pub trait FeeTracker { + /// Type used for assigning different fee factors to different destinations + type Id; /// Returns the evolving exponential fee factor which will be used to calculate the delivery /// fees. - fn get_fee_factor(para: ParaId) -> FixedU128; + fn get_fee_factor(id: Self::Id) -> FixedU128; + /// Increases the delivery fee factor by a factor based on message size and records the result. + /// + /// Returns the new delivery fee factor after the increase. + fn increase_fee_factor(id: Self::Id, message_size_factor: FixedU128) -> FixedU128; + /// Decreases the delivery fee factor by a constant factor and records the result. + /// + /// Does not reduce the fee factor below the initial value, which is currently set as 1. + /// + /// Returns the new delivery fee factor after the decrease. + fn decrease_fee_factor(id: Self::Id) -> FixedU128; } /// Schedule a para to be initialized at the start of the next session with the given genesis data. diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4ea4532b1199..a74fdc878655 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2063,6 +2063,7 @@ sp_api::impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 98eb22aba946..94c3e0df9f25 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2230,6 +2230,7 @@ sp_api::impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index 87e63fbe3107..9939f16aa29f 100644 --- a/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for `pallet_xcm_benchmarks::fungible` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-10-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `runner-nbnwcyh-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 1024 @@ -55,8 +55,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `101` // Estimated: `3593` - // Minimum execution time: 24_642_000 picoseconds. - Weight::from_parts(24_973_000, 3593) + // Minimum execution time: 24_815_000 picoseconds. + Weight::from_parts(25_098_000, 3593) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -66,8 +66,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `101` // Estimated: `6196` - // Minimum execution time: 50_882_000 picoseconds. - Weight::from_parts(51_516_000, 6196) + // Minimum execution time: 51_268_000 picoseconds. + Weight::from_parts(51_857_000, 6196) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -85,8 +85,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `210` // Estimated: `6196` - // Minimum execution time: 73_923_000 picoseconds. - Weight::from_parts(75_454_000, 6196) + // Minimum execution time: 74_113_000 picoseconds. + Weight::from_parts(74_721_000, 6196) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -111,8 +111,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `109` // Estimated: `3574` - // Minimum execution time: 29_035_000 picoseconds. - Weight::from_parts(30_086_000, 3574) + // Minimum execution time: 28_919_000 picoseconds. + Weight::from_parts(29_703_000, 3574) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -122,8 +122,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 22_094_000 picoseconds. - Weight::from_parts(22_560_000, 3593) + // Minimum execution time: 21_685_000 picoseconds. + Weight::from_parts(22_528_000, 3593) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -133,8 +133,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3593` - // Minimum execution time: 24_771_000 picoseconds. - Weight::from_parts(25_280_000, 3593) + // Minimum execution time: 25_192_000 picoseconds. + Weight::from_parts(25_445_000, 3593) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -152,8 +152,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `109` // Estimated: `3593` - // Minimum execution time: 49_777_000 picoseconds. - Weight::from_parts(50_833_000, 3593) + // Minimum execution time: 49_349_000 picoseconds. + Weight::from_parts(50_476_000, 3593) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -171,8 +171,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `109` // Estimated: `3593` - // Minimum execution time: 51_425_000 picoseconds. - Weight::from_parts(52_213_000, 3593) + // Minimum execution time: 51_386_000 picoseconds. + Weight::from_parts(52_141_000, 3593) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) } diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs index 02b5f0c6b05a..d32eb8d4a52f 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs @@ -15,7 +15,7 @@ // along with Polkadot. If not, see . use super::*; -use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; +use crate::{account_and_location, new_executor, AssetTransactorOf, EnsureDelivery, XcmCallOf}; use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; use frame_support::{ pallet_prelude::Get, @@ -24,7 +24,7 @@ use frame_support::{ }; use sp_runtime::traits::{Bounded, Zero}; use sp_std::{prelude::*, vec}; -use xcm::latest::prelude::*; +use xcm::latest::{prelude::*, MAX_ITEMS_IN_MULTIASSETS}; use xcm_executor::traits::{ConvertLocation, FeeReason, TransactAsset}; benchmarks_instance_pallet! { @@ -88,7 +88,6 @@ benchmarks_instance_pallet! { let dest_location = T::valid_destination()?; let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap(); - use crate::EnsureDelivery; let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( &sender_location, &dest_location, @@ -142,16 +141,33 @@ benchmarks_instance_pallet! { } initiate_reserve_withdraw { + let (sender_account, sender_location) = account_and_location::(1); let holding = T::worst_case_holding(1); - let assets_filter = MultiAssetFilter::Definite(holding.clone()); + let assets_filter = MultiAssetFilter::Definite(holding.clone().into_inner().into_iter().take(MAX_ITEMS_IN_MULTIASSETS).collect::>().into()); let reserve = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; - let mut executor = new_executor::(Default::default()); + + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &sender_location, + &reserve, + FeeReason::InitiateReserveWithdraw, + ); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + + let mut executor = new_executor::(sender_location); executor.set_holding(holding.into()); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } let instruction = Instruction::InitiateReserveWithdraw { assets: assets_filter, reserve, xcm: Xcm(vec![]) }; let xcm = Xcm(vec![instruction]); }: { executor.bench_process(xcm)?; } verify { + // Check we charged the delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); // The execute completing successfully is as good as we can check. // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 } diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs index 4583ecdba89f..c6b76e0ffade 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs @@ -15,27 +15,45 @@ // along with Polkadot. If not, see . use super::*; -use crate::{new_executor, XcmCallOf}; +use crate::{account_and_location, new_executor, EnsureDelivery, XcmCallOf}; use codec::Encode; use frame_benchmarking::{benchmarks, BenchmarkError}; -use frame_support::dispatch::GetDispatchInfo; +use frame_support::{dispatch::GetDispatchInfo, traits::fungible::Inspect}; use sp_std::vec; use xcm::{ latest::{prelude::*, MaxDispatchErrorLen, MaybeErrorCode, Weight}, DoubleEncoded, }; -use xcm_executor::{ExecutorError, FeesMode}; +use xcm_executor::{ + traits::{ConvertLocation, FeeReason}, + ExecutorError, FeesMode, +}; benchmarks! { report_holding { + let (sender_account, sender_location) = account_and_location::(1); let holding = T::worst_case_holding(0); + let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; - let mut executor = new_executor::(Default::default()); + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &sender_location, + &destination, + FeeReason::Report, + ); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + + let mut executor = new_executor::(sender_location); executor.set_holding(holding.clone().into()); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } let instruction = Instruction::>::ReportHolding { response_info: QueryResponseInfo { - destination: T::valid_destination()?, + destination, query_id: Default::default(), max_weight: Weight::MAX, }, @@ -44,11 +62,11 @@ benchmarks! { }; let xcm = Xcm(vec![instruction]); - } : { executor.bench_process(xcm)?; } verify { - // The completion of execution above is enough to validate this is completed. + // Check we charged the delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); } // This benchmark does not use any additional orders or instructions. This should be managed @@ -182,11 +200,26 @@ benchmarks! { } report_error { - let mut executor = new_executor::(Default::default()); - executor.set_error(Some((0u32, XcmError::Unimplemented))); + let (sender_account, sender_location) = account_and_location::(1); let query_id = Default::default(); - let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; let max_weight = Default::default(); + let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; + + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &sender_location, + &destination, + FeeReason::Report, + ); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + + let mut executor = new_executor::(sender_location); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } + executor.set_error(Some((0u32, XcmError::Unimplemented))); let instruction = Instruction::ReportError(QueryResponseInfo { query_id, destination, max_weight @@ -195,7 +228,8 @@ benchmarks! { }: { executor.bench_process(xcm)?; } verify { - // the execution succeeding is all we need to verify this xcm was successful + // Check we charged the delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); } claim_asset { @@ -360,10 +394,24 @@ benchmarks! { } query_pallet { + let (sender_account, sender_location) = account_and_location::(1); let query_id = Default::default(); let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; let max_weight = Default::default(); - let mut executor = new_executor::(Default::default()); + + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &sender_location, + &destination, + FeeReason::QueryPallet, + ); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + let mut executor = new_executor::(sender_location); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } let instruction = Instruction::QueryPallet { module_name: b"frame_system".to_vec(), @@ -373,6 +421,8 @@ benchmarks! { }: { executor.bench_process(xcm)?; } verify { + // Check we charged the delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 } @@ -394,11 +444,25 @@ benchmarks! { } report_transact_status { + let (sender_account, sender_location) = account_and_location::(1); let query_id = Default::default(); let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; let max_weight = Default::default(); - let mut executor = new_executor::(Default::default()); + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &sender_location, + &destination, + FeeReason::Report, + ); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + + let mut executor = new_executor::(sender_location); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } executor.set_transact_status(b"MyError".to_vec().into()); let instruction = Instruction::ReportTransactStatus(QueryResponseInfo { @@ -410,6 +474,8 @@ benchmarks! { }: { executor.bench_process(xcm)?; } verify { + // Check we charged the delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 } @@ -491,14 +557,30 @@ benchmarks! { let inner_xcm = Xcm(vec![ClearOrigin; x as usize]); // Get `origin`, `network` and `destination` from configured runtime. let (origin, network, destination) = T::export_message_origin_and_destination()?; + + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &origin, + &destination.into(), + FeeReason::Export(network), + ); + let sender_account = T::AccountIdConverter::convert_location(&origin).unwrap(); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + let mut executor = new_executor::(origin); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } let xcm = Xcm(vec![ExportMessage { network, destination, xcm: inner_xcm, }]); }: { executor.bench_process(xcm)?; } verify { - // The execute completing successfully is as good as we can check. + // Check we charged the delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 } @@ -517,14 +599,30 @@ benchmarks! { lock_asset { let (unlocker, owner, asset) = T::unlockable_asset()?; + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &owner, + &unlocker, + FeeReason::LockAsset, + ); + let sender_account = T::AccountIdConverter::convert_location(&owner).unwrap(); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + let mut executor = new_executor::(owner); executor.set_holding(asset.clone().into()); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } let instruction = Instruction::LockAsset { asset, unlocker }; let xcm = Xcm(vec![instruction]); }: { executor.bench_process(xcm)?; } verify { + // Check delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 } @@ -595,13 +693,29 @@ benchmarks! { .enact() .map_err(|_| BenchmarkError::Skip)?; + let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery( + &owner, + &locker, + FeeReason::RequestUnlock, + ); + let sender_account = T::AccountIdConverter::convert_location(&owner).unwrap(); + let sender_account_balance_before = T::TransactAsset::balance(&sender_account); + // ... then request for an unlock with the RequestUnlock instruction. let mut executor = new_executor::(owner); + if let Some(expected_fees_mode) = expected_fees_mode { + executor.set_fees_mode(expected_fees_mode); + } + if let Some(expected_assets_in_holding) = expected_assets_in_holding { + executor.set_holding(expected_assets_in_holding.into()); + } let instruction = Instruction::RequestUnlock { asset, locker }; let xcm = Xcm(vec![instruction]); }: { executor.bench_process(xcm)?; } verify { + // Check we charged the delivery fees + assert!(T::TransactAsset::balance(&sender_account) <= sender_account_balance_before); // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 } diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 7099542dd415..4cb95ed5ac6c 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -23,7 +23,7 @@ use frame_support::{ traits::{Everything, OriginTrait}, weights::Weight, }; -use sp_core::H256; +use sp_core::{ConstU32, H256}; use sp_runtime::traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}; use xcm_builder::{ test_utils::{ @@ -40,6 +40,7 @@ frame_support::construct_runtime!( pub enum Test { System: frame_system::{Pallet, Call, Config, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, XcmGenericBenchmarks: generic::{Pallet}, } ); @@ -137,6 +138,26 @@ impl xcm_executor::Config for XcmConfig { type Aliasers = Aliasers; } +parameter_types! { + pub const ExistentialDeposit: u64 = 7; +} + +impl pallet_balances::Config for Test { + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = u64; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type RuntimeHoldReason = RuntimeHoldReason; + type FreezeIdentifier = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; +} + impl crate::Config for Test { type XcmConfig = XcmConfig; type AccountIdConverter = AccountIdConverter; @@ -156,6 +177,7 @@ impl crate::Config for Test { } impl generic::Config for Test { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { @@ -188,7 +210,7 @@ impl generic::Config for Test { fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { let assets: MultiAsset = (Concrete(Here.into()), 100).into(); - Ok((Default::default(), Default::default(), assets)) + Ok((Default::default(), account_id_junction::(1).into(), assets)) } fn export_message_origin_and_destination( diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs index f207c238a39f..cbdfa8d0112c 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs @@ -38,6 +38,11 @@ pub mod pallet { + From> + Encode; + /// The type of `fungible` that is being used under the hood. + /// + /// This is useful for testing and checking. + type TransactAsset: frame_support::traits::fungible::Mutate; + /// The response which causes the most runtime weight. fn worst_case_response() -> (u64, Response); diff --git a/polkadot/xcm/src/v3/mod.rs b/polkadot/xcm/src/v3/mod.rs index 6f1e8e783113..a3490108e8b4 100644 --- a/polkadot/xcm/src/v3/mod.rs +++ b/polkadot/xcm/src/v3/mod.rs @@ -45,7 +45,7 @@ pub use junction::{BodyId, BodyPart, Junction, NetworkId}; pub use junctions::Junctions; pub use multiasset::{ AssetId, AssetInstance, Fungibility, MultiAsset, MultiAssetFilter, MultiAssets, - WildFungibility, WildMultiAsset, + WildFungibility, WildMultiAsset, MAX_ITEMS_IN_MULTIASSETS, }; pub use multilocation::{ Ancestor, AncestorThen, InteriorMultiLocation, MultiLocation, Parent, ParentThen, @@ -70,7 +70,7 @@ pub type QueryId = u64; #[scale_info(bounds(), skip_type_params(Call))] pub struct Xcm(pub Vec>); -const MAX_INSTRUCTIONS_TO_DECODE: u8 = 100; +pub const MAX_INSTRUCTIONS_TO_DECODE: u8 = 100; environmental::environmental!(instructions_count: u8); diff --git a/substrate/frame/support/procedural/src/pallet/expand/warnings.rs b/substrate/frame/support/procedural/src/pallet/expand/warnings.rs index ae5890878a2f..6ce2097c2684 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/warnings.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/warnings.rs @@ -34,7 +34,7 @@ pub(crate) fn weight_witness_warning( return } let CallWeightDef::Immediate(w) = &method.weight else { - return; + return }; let partial_warning = Warning::new_deprecated("UncheckedWeightWitness") @@ -67,7 +67,7 @@ pub(crate) fn weight_constant_warning( return } let syn::Expr::Lit(lit) = weight else { - return; + return }; let warning = Warning::new_deprecated("ConstantWeight") From 97aab4d9b8b66a50b36d24613253fb7b31c4971d Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 17 Oct 2023 22:26:48 +0200 Subject: [PATCH 098/116] Add tests for XCMP and UMP delivery fees --- cumulus/pallets/parachain-system/src/lib.rs | 38 ++++- cumulus/pallets/parachain-system/src/tests.rs | 42 ++++++ cumulus/pallets/xcmp-queue/src/lib.rs | 134 ++++++++++++------ cumulus/pallets/xcmp-queue/src/mock.rs | 23 ++- cumulus/pallets/xcmp-queue/src/tests.rs | 74 +++++++++- cumulus/primitives/core/src/lib.rs | 2 +- polkadot/parachain/src/primitives.rs | 2 +- polkadot/runtime/parachains/src/dmp.rs | 4 +- 8 files changed, 257 insertions(+), 62 deletions(-) diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 3b1d0525d15f..0c36c1c03037 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -29,7 +29,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_primitives_core::{ - relay_chain, AbridgedHostConfiguration, ChannelStatus, CollationInfo, DmpMessageHandler, + relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, DmpMessageHandler, GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError, OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender, XcmpMessageHandler, XcmpMessageSource, @@ -258,6 +258,7 @@ pub mod pallet { /// Handles actually sending upward messages by moving them from `PendingUpwardMessages` to /// `UpwardMessages`. Decreases the delivery fee factor if after sending messages, the queue /// total size is less than the threshold (see [`ump_constants::THRESHOLD_FACTOR`]). + /// Also does the sending for HRMP messages it takes from `OutboundXcmpMessageSource`. fn on_finalize(_: BlockNumberFor) { >::kill(); >::kill(); @@ -1084,10 +1085,17 @@ impl GetChannelInfo for Pallet { ChannelStatus::Ready(max_size_now as usize, max_size_ever as usize) } - fn get_channel_max(id: ParaId) -> Option { + fn get_channel_info(id: ParaId) -> Option { let channels = Self::relevant_messaging_state()?.egress_channels; let index = channels.binary_search_by_key(&id, |item| item.0).ok()?; - Some(channels[index].1.max_message_size as usize) + let info = ChannelInfo { + max_capacity: channels[index].1.max_capacity, + max_total_size: channels[index].1.max_total_size, + max_message_size: channels[index].1.max_message_size, + msg_count: channels[index].1.msg_count, + total_size: channels[index].1.total_size, + }; + Some(info) } } @@ -1492,6 +1500,26 @@ impl Pallet { }) } + /// Open HRMP channel for using it in benchmarks or tests. + /// + /// The caller assumes that the pallet will accept regular outbound message to the sibling + /// `target_parachain` after this call. No other assumptions are made. + #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] + pub fn open_custom_outbound_hrmp_channel_for_benchmarks_or_tests( + target_parachain: ParaId, + channel: cumulus_primitives_core::AbridgedHrmpChannel + ) { + RelevantMessagingState::::put(MessagingStateSnapshot { + dmq_mqc_head: Default::default(), + relay_dispatch_queue_remaining_capacity: Default::default(), + ingress_channels: Default::default(), + egress_channels: vec![( + target_parachain, + channel, + )], + }) + } + /// Prepare/insert relevant data for `schedule_code_upgrade` for benchmarks. #[cfg(feature = "runtime-benchmarks")] pub fn initialize_for_set_code_benchmark(max_code_size: u32) { @@ -1560,6 +1588,7 @@ impl Pallet { cfg.max_upward_queue_size.saturating_div(ump_constants::THRESHOLD_FACTOR); // We check the threshold against total size and not number of messages since messages // could be big or small. + >::append(message.clone()); let pending_messages = PendingUpwardMessages::::get(); let total_size: usize = pending_messages.iter().map(UpwardMessage::len).sum(); if total_size > threshold as usize { @@ -1578,10 +1607,9 @@ impl Pallet { // returned back to the sender. // // Thus fall through here. + >::append(message.clone()); }; - >::append(message.clone()); - // The relay ump does not use using_encoded // We apply the same this to use the same hash let hash = sp_io::hashing::blake2_256(&message); diff --git a/cumulus/pallets/parachain-system/src/tests.rs b/cumulus/pallets/parachain-system/src/tests.rs index 626196790bc9..a9876b16c9fe 100755 --- a/cumulus/pallets/parachain-system/src/tests.rs +++ b/cumulus/pallets/parachain-system/src/tests.rs @@ -1496,3 +1496,45 @@ fn deposits_relay_parent_storage_root() { }, ); } + +#[test] +fn ump_fee_factor_increases_and_decreases() { + BlockTests::new() + .with_relay_sproof_builder(|_, _, sproof| { + sproof.host_config.max_upward_queue_size = 100; + sproof.host_config.max_upward_message_num_per_candidate = 1; + }) + .add_with_post_test( + 1, + || { + // Fee factor increases in `send_upward_message` + ParachainSystem::send_upward_message(b"Test".to_vec()).unwrap(); + assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_u32(1)); + + ParachainSystem::send_upward_message( + b"This message will be enough to increase the fee factor".to_vec() + ).unwrap(); + assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_rational(105, 100)); + }, + || { + // Factor decreases in `on_finalize`, but only if we are below the threshold + let messages = UpwardMessages::::get(); + assert_eq!(messages, vec![b"Test".to_vec()]); + assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_rational(105, 100)); + }, + ) + .add_with_post_test( + 2, + || { + // We do nothing here + }, + || { + let messages = UpwardMessages::::get(); + assert_eq!(messages, vec![ + b"This message will be enough to increase the fee factor".to_vec(), + ]); + // Now the delivery fee factor is decreased, since we are below the threshold + assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_u32(1)); + }, + ); +} diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index 66204b021d78..262af91a1dc6 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -22,6 +22,16 @@ //! Also provides an implementation of `SendXcm` which can be placed in a router tuple for relaying //! XCM over XCMP if the destination is `Parent/Parachain`. It requires an implementation of //! `XcmExecutor` for dispatching incoming XCM messages. +//! +//! To prevent out of memory errors on the `OutboundXcmpMessages` queue, an exponential fee factor (`DeliveryFeeFactor`) +//! is set, much like the one used in DMP. +//! The fee factor increases whenever the total size of messages in a particular channel passes a threshold. +//! This threshold is defined as a percentage of the maximum total size the channel can have. +//! More concretely, the threshold is `max_total_size` / `THRESHOLD_FACTOR`, where: +//! - `max_total_size` is the maximum size, in bytes, of the channel, not number of messages. +//! It is defined in the channel configuration. +//! - `THRESHOLD_FACTOR` just declares which percentage of the max size is the actual threshold. +//! If it's 2, then the threshold is half of the max size, if it's 4, it's a quarter, and so on. #![cfg_attr(not(feature = "std"), no_std)] @@ -66,8 +76,19 @@ pub type OverweightIndex = u64; const LOG_TARGET: &str = "xcmp_queue"; const DEFAULT_POV_SIZE: u64 = 64 * 1024; // 64 KB -const EXPONENTIAL_FEE_BASE: FixedU128 = FixedU128::from_rational(105, 100); // 1.05 -const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0.001 + +/// Constants related to delivery fee calculation +pub mod delivery_fee_constants { + use super::FixedU128; + + /// Fees will start increasing when queue is half full + pub const THRESHOLD_FACTOR: u32 = 2; + /// The base number the delivery fee factor gets multiplied by every time it is increased. + /// Also, the number it gets divided by when decreased. + pub const EXPONENTIAL_FEE_BASE: FixedU128 = FixedU128::from_rational(105, 100); // 1.05 + /// The contribution of each KB to a fee factor increase + pub const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0.001 +} // Maximum amount of messages to process per block. This is a temporary measure until we properly // account for proof size weights. @@ -415,7 +436,7 @@ pub struct InboundChannelDetails { } /// Struct containing detailed information about the outbound channel. -#[derive(Clone, Eq, PartialEq, Encode, Decode, TypeInfo)] +#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode, TypeInfo)] pub struct OutboundChannelDetails { /// The `ParaId` of the parachain that this channel is connected with. recipient: ParaId, @@ -515,56 +536,73 @@ impl Pallet { /// length prefixed and can thus decode each fragment from the aggregate stream. With this, /// we can concatenate them into a single aggregate blob without needing to be concerned /// about encoding fragment boundaries. + /// + /// If successful, returns the number of pages in the outbound queue after enqueuing the new fragment. fn send_fragment( recipient: ParaId, format: XcmpMessageFormat, fragment: Fragment, ) -> Result { - let data = fragment.encode(); - - // Optimization note: `max_message_size` could potentially be stored in - // `OutboundXcmpMessages` once known; that way it's only accessed when a new page is needed. + let encoded_fragment = fragment.encode(); - let max_message_size = - T::ChannelInfo::get_channel_max(recipient).ok_or(MessageSendError::NoChannel)?; - if data.len() > max_message_size { + let channel_info = + T::ChannelInfo::get_channel_info(recipient).ok_or(MessageSendError::NoChannel)?; + let max_message_size = channel_info.max_message_size as usize; + // Max message size refers to aggregates, or pages. Not to individual fragments. + if encoded_fragment.len() > max_message_size { return Err(MessageSendError::TooBig) } - let mut s = >::get(); - let details = if let Some(details) = s.iter_mut().find(|item| item.recipient == recipient) { + let mut all_channels = >::get(); + let channel_details = if let Some(details) = all_channels.iter_mut().find(|channel| channel.recipient == recipient) { details } else { - s.push(OutboundChannelDetails::new(recipient)); - s.last_mut().expect("can't be empty; a new element was just pushed; qed") + all_channels.push(OutboundChannelDetails::new(recipient)); + all_channels.last_mut().expect("can't be empty; a new element was just pushed; qed") }; - let have_active = details.last_index > details.first_index; - let appended = have_active && - >::mutate(recipient, details.last_index - 1, |s| { - if XcmpMessageFormat::decode_with_depth_limit(MAX_XCM_DECODE_DEPTH, &mut &s[..]) != - Ok(format) - { - return false - } - if s.len() + data.len() > max_message_size { - return false - } - s.extend_from_slice(&data[..]); - true - }); - if appended { - Ok((details.last_index - details.first_index - 1) as u32) + let have_active = channel_details.last_index > channel_details.first_index; + // Try to append fragment to the last page, if there is enough space. + // We return the size of the last page inside of the option, to not calculate it again. + let appended_to_last_page = have_active.then(|| >::mutate(recipient, channel_details.last_index - 1, |page| { + if XcmpMessageFormat::decode_with_depth_limit(MAX_XCM_DECODE_DEPTH, &mut &page[..]) != + Ok(format) + { + return None; + } + if page.len() + encoded_fragment.len() > max_message_size { + return None; + } + page.extend_from_slice(&encoded_fragment[..]); + Some(page.len()) + })).flatten(); + + let (number_of_pages, last_page_size) = if let Some(size) = appended_to_last_page { + let number_of_pages = (channel_details.last_index - channel_details.first_index) as u32; + (number_of_pages, size) } else { // Need to add a new page. - let page_index = details.last_index; - details.last_index += 1; + let page_index = channel_details.last_index; + channel_details.last_index += 1; let mut new_page = format.encode(); - new_page.extend_from_slice(&data[..]); + new_page.extend_from_slice(&encoded_fragment[..]); + let last_page_size = new_page.len(); + let number_of_pages = (channel_details.last_index - channel_details.first_index) as u32; >::insert(recipient, page_index, new_page); - let r = (details.last_index - details.first_index - 1) as u32; - >::put(s); - Ok(r) + >::put(all_channels); + (number_of_pages, last_page_size) + }; + + // We have to count the total size here since `channel_info.total_size` is not updated at this point in time. + // We assume all previous pages are filled, which, in practice, is not always the case. + let total_size = number_of_pages.saturating_sub(1) * max_message_size as u32 + last_page_size as u32; + let threshold = channel_info.max_total_size / delivery_fee_constants::THRESHOLD_FACTOR; + if total_size > threshold { + let message_size_factor = FixedU128::from((encoded_fragment.len() / 1024) as u128) + .saturating_mul(delivery_fee_constants::MESSAGE_SIZE_FEE_BASE); + Self::increase_fee_factor(recipient, message_size_factor); } + + Ok(number_of_pages) } /// Sends a signal to the `dest` chain over XCMP. This is guaranteed to be dispatched on this @@ -669,7 +707,6 @@ impl Pallet { messages_processed: &mut u8, max_weight: Weight, max_individual_weight: Weight, - should_decrease_fee_factor: bool, ) -> (Weight, bool) { let data = >::get(sender, sent_at); let mut last_remaining_fragments; @@ -734,10 +771,6 @@ impl Pallet { debug_assert!(false, "Invalid incoming XCMP message data"); remaining_fragments = &b""[..]; } - - if should_decrease_fee_factor { - Self::decrease_fee_factor(sender); - } } }, XcmpMessageFormat::ConcatenatedEncodedBlob => { @@ -892,15 +925,12 @@ impl Pallet { } else { // Process up to one block's worth for now. let weight_remaining = weight_available.saturating_sub(weight_used); - let should_decrease_fee_factor = - (status[index].message_metadata.len() as u32) <= suspend_threshold; let (weight_processed, is_empty) = Self::process_xcmp_message( sender, status[index].message_metadata[0], &mut messages_processed, weight_remaining, xcmp_max_individual_weight, - should_decrease_fee_factor, ); if is_empty { status[index].message_metadata.remove(0); @@ -1029,7 +1059,7 @@ impl XcmpMessageHandler for Pallet { if count > suspend_threshold { let message_size_factor = FixedU128::from((data_ref.len() / 1024) as u128) - .saturating_mul(MESSAGE_SIZE_FEE_BASE); + .saturating_mul(delivery_fee_constants::MESSAGE_SIZE_FEE_BASE); Self::increase_fee_factor(sender, message_size_factor); } }, @@ -1129,6 +1159,16 @@ impl XcmpMessageSource for Pallet { result.push((para_id, page)); } + // TODO: Remove the expect + let max_total_size = T::ChannelInfo::get_channel_info(para_id).expect("this should be here; qed").max_total_size; + let threshold = max_total_size + .saturating_div(delivery_fee_constants::THRESHOLD_FACTOR); + let remaining_total_size: usize = (first_index..last_index) + .map(|index| OutboundXcmpMessages::::decode_len(para_id, index).unwrap()).sum(); + if remaining_total_size <= threshold as usize { + Self::decrease_fee_factor(para_id); + } + *status = OutboundChannelDetails { recipient: para_id, state: outbound_state, @@ -1217,14 +1257,14 @@ impl FeeTracker for Pallet { fn increase_fee_factor(id: Self::Id, message_size_factor: FixedU128) -> FixedU128 { >::mutate(id, |f| { - *f = f.saturating_mul(EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); + *f = f.saturating_mul(delivery_fee_constants::EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); *f }) } fn decrease_fee_factor(id: Self::Id) -> FixedU128 { >::mutate(id, |f| { - *f = InitialFactor::get().max(*f / EXPONENTIAL_FEE_BASE); + *f = InitialFactor::get().max(*f / delivery_fee_constants::EXPONENTIAL_FEE_BASE); *f }) } diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index e7ae1a68703e..bc0710e34653 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -23,7 +23,6 @@ use frame_support::{ traits::{ConstU32, Everything, Nothing, OriginTrait}, }; use frame_system::EnsureRoot; -use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, @@ -86,8 +85,10 @@ parameter_types! { pub const MaxReserves: u32 = 50; } +pub type Balance = u64; + impl pallet_balances::Config for Test { - type Balance = u64; + type Balance = Balance; type RuntimeEvent = RuntimeEvent; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; @@ -197,6 +198,22 @@ impl ConvertOrigin } } +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(RelayChain::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: Balance = 300_000_000; + /// The fee per byte + pub const ByteFee: Balance = 1_000_000; +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + ByteFee, + XcmpQueue, +>; + impl Config for Test { type RuntimeEvent = RuntimeEvent; type XcmExecutor = xcm_executor::XcmExecutor; @@ -206,7 +223,7 @@ impl Config for Test { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = SystemParachainAsSuperuser; type WeightInfo = (); - type PriceForSiblingDelivery = NoPriceForMessageDelivery; + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/cumulus/pallets/xcmp-queue/src/tests.rs b/cumulus/pallets/xcmp-queue/src/tests.rs index cdeab7ef6ac4..380078298171 100644 --- a/cumulus/pallets/xcmp-queue/src/tests.rs +++ b/cumulus/pallets/xcmp-queue/src/tests.rs @@ -49,7 +49,6 @@ fn bad_message_is_handled() { &mut 0, Weight::from_parts(10_000_000_000, 0), Weight::from_parts(10_000_000_000, 0), - true, ); }); } @@ -74,7 +73,6 @@ fn handle_blob_message() { &mut 0, Weight::from_parts(10_000_000_000, 0), Weight::from_parts(10_000_000_000, 0), - true, ); }); } @@ -93,7 +91,6 @@ fn handle_invalid_data() { &mut 0, Weight::from_parts(10_000_000_000, 0), Weight::from_parts(10_000_000_000, 0), - true, ); }); } @@ -373,3 +370,74 @@ fn xcmp_queue_send_xcm_works() { .any(|(para_id, _)| para_id == &sibling_para_id)); }) } + +#[test] +fn verify_fee_factor_increase_and_decrease() { + use sp_runtime::FixedU128; + use cumulus_primitives_core::AbridgedHrmpChannel; + + let sibling_para_id = ParaId::from(12345); + let destination = (Parent, Parachain(sibling_para_id.into())).into(); + let xcm = Xcm(vec![ClearOrigin; 100]); + let versioned_xcm = VersionedXcm::from(xcm.clone()); + let mut xcmp_message = XcmpMessageFormat::ConcatenatedVersionedXcm.encode(); + xcmp_message.extend(versioned_xcm.encode()); + + new_test_ext().execute_with(|| { + let initial = InitialFactor::get(); + assert_eq!(DeliveryFeeFactor::::get(sibling_para_id), initial); + + // Open channel so messages can actually be sent + ParachainSystem::open_custom_outbound_hrmp_channel_for_benchmarks_or_tests( + sibling_para_id, + AbridgedHrmpChannel { + max_capacity: 10, + max_total_size: 1000, + max_message_size: 104, + msg_count: 0, + total_size: 0, + mqc_head: None, + }, + ); + + // Fee factor is only increased in `send_fragment`, which is called by `send_xcm`. + // When queue is not congested, fee factor doesn't change. + assert_ok!(send_xcm::(destination, xcm.clone())); // Size 104 + assert_ok!(send_xcm::(destination, xcm.clone())); // Size 208 + assert_ok!(send_xcm::(destination, xcm.clone())); // Size 312 + assert_ok!(send_xcm::(destination, xcm.clone())); // Size 416 + assert_eq!(DeliveryFeeFactor::::get(sibling_para_id), initial); + + // Sending the message right now is cheap + let (_, delivery_fees) = validate_send::(destination, xcm.clone()) + .expect("message can be sent; qed"); + let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else { unreachable!("asset is fungible; qed"); }; + assert_eq!(delivery_fee_amount, 402_000_000); + + let smaller_xcm = Xcm(vec![ClearOrigin; 30]); + + // When we get to half of `max_total_size`, because `THRESHOLD_FACTOR` is 2, + // then the fee factor starts to increase. + assert_ok!(send_xcm::(destination, xcm.clone())); // Size 520 + assert_eq!(DeliveryFeeFactor::::get(sibling_para_id), FixedU128::from_float(1.05)); + + for _ in 0..12 { // We finish at size 929 + assert_ok!(send_xcm::(destination, smaller_xcm.clone())); + } + assert!(DeliveryFeeFactor::::get(sibling_para_id) > FixedU128::from_float(1.88)); + + // Sending the message right now is expensive + let (_, delivery_fees) = validate_send::(destination, xcm.clone()) + .expect("message can be sent; qed"); + let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else { unreachable!("asset is fungible; qed"); }; + assert_eq!(delivery_fee_amount, 758_030_955); + + // Fee factor only decreases in `take_outbound_messages` + for _ in 0..5 { // We take 5 100 byte pages + XcmpQueue::take_outbound_messages(1); + } + assert!(DeliveryFeeFactor::::get(sibling_para_id) < FixedU128::from_float(1.72)); + XcmpQueue::take_outbound_messages(1); + assert!(DeliveryFeeFactor::::get(sibling_para_id) < FixedU128::from_float(1.63)); + }); +} diff --git a/cumulus/primitives/core/src/lib.rs b/cumulus/primitives/core/src/lib.rs index faaef09b26e1..f216af2aaee7 100644 --- a/cumulus/primitives/core/src/lib.rs +++ b/cumulus/primitives/core/src/lib.rs @@ -96,7 +96,7 @@ pub struct ChannelInfo { pub trait GetChannelInfo { fn get_channel_status(id: ParaId) -> ChannelStatus; - fn get_channel_max(id: ParaId) -> Option; + fn get_channel_info(id: ParaId) -> Option; } /// Something that should be called when sending an upward message. diff --git a/polkadot/parachain/src/primitives.rs b/polkadot/parachain/src/primitives.rs index 5f77810f5c23..3247e841422e 100644 --- a/polkadot/parachain/src/primitives.rs +++ b/polkadot/parachain/src/primitives.rs @@ -333,7 +333,7 @@ impl DmpMessageHandler for () { } /// The aggregate XCMP message format. -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] pub enum XcmpMessageFormat { /// Encoded `VersionedXcm` messages, all concatenated. ConcatenatedVersionedXcm, diff --git a/polkadot/runtime/parachains/src/dmp.rs b/polkadot/runtime/parachains/src/dmp.rs index 78994a9e34ba..15147e9210e2 100644 --- a/polkadot/runtime/parachains/src/dmp.rs +++ b/polkadot/runtime/parachains/src/dmp.rs @@ -17,12 +17,12 @@ //! To prevent Out of Memory errors on the `DownwardMessageQueue`, an //! exponential fee factor (`DeliveryFeeFactor`) is set. The fee factor //! increments exponentially after the number of messages in the -//! `DownwardMessageQueue` pass a threshold. This threshold is set as: +//! `DownwardMessageQueue` passes a threshold. This threshold is set as: //! //! ```ignore //! // Maximum max sized messages that can be send to //! // the DownwardMessageQueue before it runs out of memory -//! max_messsages = MAX_POSSIBLE_ALLOCATION / max_downward_message_size +//! max_messages = MAX_POSSIBLE_ALLOCATION / max_downward_message_size //! threshold = max_messages / THRESHOLD_FACTOR //! ``` //! Based on the THRESHOLD_FACTOR, the threshold is set as a fraction of the From 7f4d6d97dabd56e123781f052e28a979a29e1f86 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 17 Oct 2023 22:38:26 +0200 Subject: [PATCH 099/116] Remove an expect --- cumulus/pallets/xcmp-queue/src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index 262af91a1dc6..1603826e7825 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -866,7 +866,6 @@ impl Pallet { let QueueConfigData { resume_threshold, - suspend_threshold, threshold_weight, weight_restrict_decay, xcmp_max_individual_weight, @@ -1159,8 +1158,13 @@ impl XcmpMessageSource for Pallet { result.push((para_id, page)); } - // TODO: Remove the expect - let max_total_size = T::ChannelInfo::get_channel_info(para_id).expect("this should be here; qed").max_total_size; + let max_total_size = match T::ChannelInfo::get_channel_info(para_id) { + Some(channel_info) => channel_info.max_total_size, + None => { + log::warn!("calling `get_channel_info` with no RelevantMessagingState?!"); + MAX_POSSIBLE_ALLOCATION // We use this as a fallback in case the messaging state is not present + }, + }; let threshold = max_total_size .saturating_div(delivery_fee_constants::THRESHOLD_FACTOR); let remaining_total_size: usize = (first_index..last_index) From 5b427bbcd010f9d2d96707dfb519fa8b0d56f368 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 17 Oct 2023 22:47:30 +0200 Subject: [PATCH 100/116] Add missing import --- cumulus/pallets/xcmp-queue/Cargo.toml | 2 ++ cumulus/pallets/xcmp-queue/src/lib.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/cumulus/pallets/xcmp-queue/Cargo.toml b/cumulus/pallets/xcmp-queue/Cargo.toml index ab0f816337d7..4ec2ce023c6d 100644 --- a/cumulus/pallets/xcmp-queue/Cargo.toml +++ b/cumulus/pallets/xcmp-queue/Cargo.toml @@ -14,6 +14,7 @@ scale-info = { version = "2.9.0", default-features = false, features = ["derive" frame-support = { path = "../../../substrate/frame/support", default-features = false} frame-system = { path = "../../../substrate/frame/system", default-features = false} sp-io = { path = "../../../substrate/primitives/io", default-features = false} +sp-core = { path = "../../../substrate/primitives/core", default-features = false } sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false} sp-std = { path = "../../../substrate/primitives/std", default-features = false} @@ -56,6 +57,7 @@ std = [ "sp-io/std", "sp-runtime/std", "sp-std/std", + "sp-core/std", "xcm-executor/std", "xcm/std", ] diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index 1603826e7825..eb88281fe8a5 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -65,6 +65,7 @@ use rand_chacha::{ }; use scale_info::TypeInfo; use sp_runtime::{FixedU128, RuntimeDebug, Saturating}; +use sp_core::MAX_POSSIBLE_ALLOCATION; use sp_std::{convert::TryFrom, prelude::*}; use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH}; use xcm_executor::traits::ConvertOrigin; From fad641e754258c1396d478d1b5e184faab252753 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 17 Oct 2023 22:56:58 +0200 Subject: [PATCH 101/116] Remove unused import --- cumulus/pallets/xcmp-queue/Cargo.toml | 2 +- .../runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/Cargo.toml b/cumulus/pallets/xcmp-queue/Cargo.toml index 4ec2ce023c6d..02a3e7839835 100644 --- a/cumulus/pallets/xcmp-queue/Cargo.toml +++ b/cumulus/pallets/xcmp-queue/Cargo.toml @@ -54,10 +54,10 @@ std = [ "polkadot-runtime-common/std", "polkadot-runtime-parachains/std", "scale-info/std", + "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-std/std", - "sp-core/std", "xcm-executor/std", "xcm/std", ] diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 026a55507996..6e0a74e87c8c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -32,7 +32,7 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::{ConcreteNativeAssetFrom, ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, + xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; From 6a937708e2961f8a7aafb6271cbafacf0c37fa4b Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 17 Oct 2023 23:17:44 +0200 Subject: [PATCH 102/116] Move warn to trace --- polkadot/xcm/xcm-builder/src/fee_handling.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/xcm/xcm-builder/src/fee_handling.rs b/polkadot/xcm/xcm-builder/src/fee_handling.rs index 049055471d32..1386747c9778 100644 --- a/polkadot/xcm/xcm-builder/src/fee_handling.rs +++ b/polkadot/xcm/xcm-builder/src/fee_handling.rs @@ -46,7 +46,7 @@ impl< let dest = AccountId32 { network: None, id: receiver.into() }.into(); for asset in fees.into_inner() { if let Err(e) = XcmConfig::AssetTransactor::deposit_asset(&asset, &dest, context) { - log::warn!( + log::trace!( target: "xcm::fees", "`AssetTransactor::deposit_asset` returned error: {:?}, burning fees: {:?}", e, asset, From 45b924580234b51c6b6f16044810c44c8aa867a3 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 17 Oct 2023 21:21:39 +0000 Subject: [PATCH 103/116] ".git/.scripts/commands/fmt/fmt.sh" --- cumulus/pallets/parachain-system/src/lib.rs | 15 ++-- cumulus/pallets/parachain-system/src/tests.rs | 22 ++++-- cumulus/pallets/xcmp-queue/src/lib.rs | 75 ++++++++++++------- cumulus/pallets/xcmp-queue/src/tests.rs | 2 +- .../asset-hub-westend/src/xcm_config.rs | 5 +- .../contracts-rococo/src/xcm_config.rs | 5 +- 6 files changed, 77 insertions(+), 47 deletions(-) diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 0c36c1c03037..369281ccd8ee 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -29,10 +29,10 @@ use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_primitives_core::{ - relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, DmpMessageHandler, - GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError, - OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender, - XcmpMessageHandler, XcmpMessageSource, + relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, + DmpMessageHandler, GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, + MessageSendError, OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, + UpwardMessageSender, XcmpMessageHandler, XcmpMessageSource, }; use cumulus_primitives_parachain_inherent::{MessageQueueChain, ParachainInherentData}; use frame_support::{ @@ -1507,16 +1507,13 @@ impl Pallet { #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] pub fn open_custom_outbound_hrmp_channel_for_benchmarks_or_tests( target_parachain: ParaId, - channel: cumulus_primitives_core::AbridgedHrmpChannel + channel: cumulus_primitives_core::AbridgedHrmpChannel, ) { RelevantMessagingState::::put(MessagingStateSnapshot { dmq_mqc_head: Default::default(), relay_dispatch_queue_remaining_capacity: Default::default(), ingress_channels: Default::default(), - egress_channels: vec![( - target_parachain, - channel, - )], + egress_channels: vec![(target_parachain, channel)], }) } diff --git a/cumulus/pallets/parachain-system/src/tests.rs b/cumulus/pallets/parachain-system/src/tests.rs index a9876b16c9fe..3f5b4f649e32 100755 --- a/cumulus/pallets/parachain-system/src/tests.rs +++ b/cumulus/pallets/parachain-system/src/tests.rs @@ -1512,15 +1512,22 @@ fn ump_fee_factor_increases_and_decreases() { assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_u32(1)); ParachainSystem::send_upward_message( - b"This message will be enough to increase the fee factor".to_vec() - ).unwrap(); - assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_rational(105, 100)); + b"This message will be enough to increase the fee factor".to_vec(), + ) + .unwrap(); + assert_eq!( + UpwardDeliveryFeeFactor::::get(), + FixedU128::from_rational(105, 100) + ); }, || { // Factor decreases in `on_finalize`, but only if we are below the threshold let messages = UpwardMessages::::get(); assert_eq!(messages, vec![b"Test".to_vec()]); - assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_rational(105, 100)); + assert_eq!( + UpwardDeliveryFeeFactor::::get(), + FixedU128::from_rational(105, 100) + ); }, ) .add_with_post_test( @@ -1530,9 +1537,10 @@ fn ump_fee_factor_increases_and_decreases() { }, || { let messages = UpwardMessages::::get(); - assert_eq!(messages, vec![ - b"This message will be enough to increase the fee factor".to_vec(), - ]); + assert_eq!( + messages, + vec![b"This message will be enough to increase the fee factor".to_vec(),] + ); // Now the delivery fee factor is decreased, since we are below the threshold assert_eq!(UpwardDeliveryFeeFactor::::get(), FixedU128::from_u32(1)); }, diff --git a/cumulus/pallets/xcmp-queue/src/lib.rs b/cumulus/pallets/xcmp-queue/src/lib.rs index eb88281fe8a5..b382314b83df 100644 --- a/cumulus/pallets/xcmp-queue/src/lib.rs +++ b/cumulus/pallets/xcmp-queue/src/lib.rs @@ -23,11 +23,11 @@ //! XCM over XCMP if the destination is `Parent/Parachain`. It requires an implementation of //! `XcmExecutor` for dispatching incoming XCM messages. //! -//! To prevent out of memory errors on the `OutboundXcmpMessages` queue, an exponential fee factor (`DeliveryFeeFactor`) -//! is set, much like the one used in DMP. -//! The fee factor increases whenever the total size of messages in a particular channel passes a threshold. -//! This threshold is defined as a percentage of the maximum total size the channel can have. -//! More concretely, the threshold is `max_total_size` / `THRESHOLD_FACTOR`, where: +//! To prevent out of memory errors on the `OutboundXcmpMessages` queue, an exponential fee factor +//! (`DeliveryFeeFactor`) is set, much like the one used in DMP. +//! The fee factor increases whenever the total size of messages in a particular channel passes a +//! threshold. This threshold is defined as a percentage of the maximum total size the channel can +//! have. More concretely, the threshold is `max_total_size` / `THRESHOLD_FACTOR`, where: //! - `max_total_size` is the maximum size, in bytes, of the channel, not number of messages. //! It is defined in the channel configuration. //! - `THRESHOLD_FACTOR` just declares which percentage of the max size is the actual threshold. @@ -64,8 +64,8 @@ use rand_chacha::{ ChaChaRng, }; use scale_info::TypeInfo; -use sp_runtime::{FixedU128, RuntimeDebug, Saturating}; use sp_core::MAX_POSSIBLE_ALLOCATION; +use sp_runtime::{FixedU128, RuntimeDebug, Saturating}; use sp_std::{convert::TryFrom, prelude::*}; use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH}; use xcm_executor::traits::ConvertOrigin; @@ -538,7 +538,8 @@ impl Pallet { /// we can concatenate them into a single aggregate blob without needing to be concerned /// about encoding fragment boundaries. /// - /// If successful, returns the number of pages in the outbound queue after enqueuing the new fragment. + /// If successful, returns the number of pages in the outbound queue after enqueuing the new + /// fragment. fn send_fragment( recipient: ParaId, format: XcmpMessageFormat, @@ -555,27 +556,41 @@ impl Pallet { } let mut all_channels = >::get(); - let channel_details = if let Some(details) = all_channels.iter_mut().find(|channel| channel.recipient == recipient) { + let channel_details = if let Some(details) = + all_channels.iter_mut().find(|channel| channel.recipient == recipient) + { details } else { all_channels.push(OutboundChannelDetails::new(recipient)); - all_channels.last_mut().expect("can't be empty; a new element was just pushed; qed") + all_channels + .last_mut() + .expect("can't be empty; a new element was just pushed; qed") }; let have_active = channel_details.last_index > channel_details.first_index; // Try to append fragment to the last page, if there is enough space. // We return the size of the last page inside of the option, to not calculate it again. - let appended_to_last_page = have_active.then(|| >::mutate(recipient, channel_details.last_index - 1, |page| { - if XcmpMessageFormat::decode_with_depth_limit(MAX_XCM_DECODE_DEPTH, &mut &page[..]) != - Ok(format) - { - return None; - } - if page.len() + encoded_fragment.len() > max_message_size { - return None; - } - page.extend_from_slice(&encoded_fragment[..]); - Some(page.len()) - })).flatten(); + let appended_to_last_page = have_active + .then(|| { + >::mutate( + recipient, + channel_details.last_index - 1, + |page| { + if XcmpMessageFormat::decode_with_depth_limit( + MAX_XCM_DECODE_DEPTH, + &mut &page[..], + ) != Ok(format) + { + return None + } + if page.len() + encoded_fragment.len() > max_message_size { + return None + } + page.extend_from_slice(&encoded_fragment[..]); + Some(page.len()) + }, + ) + }) + .flatten(); let (number_of_pages, last_page_size) = if let Some(size) = appended_to_last_page { let number_of_pages = (channel_details.last_index - channel_details.first_index) as u32; @@ -593,9 +608,11 @@ impl Pallet { (number_of_pages, last_page_size) }; - // We have to count the total size here since `channel_info.total_size` is not updated at this point in time. - // We assume all previous pages are filled, which, in practice, is not always the case. - let total_size = number_of_pages.saturating_sub(1) * max_message_size as u32 + last_page_size as u32; + // We have to count the total size here since `channel_info.total_size` is not updated at + // this point in time. We assume all previous pages are filled, which, in practice, is not + // always the case. + let total_size = + number_of_pages.saturating_sub(1) * max_message_size as u32 + last_page_size as u32; let threshold = channel_info.max_total_size / delivery_fee_constants::THRESHOLD_FACTOR; if total_size > threshold { let message_size_factor = FixedU128::from((encoded_fragment.len() / 1024) as u128) @@ -1166,10 +1183,10 @@ impl XcmpMessageSource for Pallet { MAX_POSSIBLE_ALLOCATION // We use this as a fallback in case the messaging state is not present }, }; - let threshold = max_total_size - .saturating_div(delivery_fee_constants::THRESHOLD_FACTOR); + let threshold = max_total_size.saturating_div(delivery_fee_constants::THRESHOLD_FACTOR); let remaining_total_size: usize = (first_index..last_index) - .map(|index| OutboundXcmpMessages::::decode_len(para_id, index).unwrap()).sum(); + .map(|index| OutboundXcmpMessages::::decode_len(para_id, index).unwrap()) + .sum(); if remaining_total_size <= threshold as usize { Self::decrease_fee_factor(para_id); } @@ -1262,7 +1279,9 @@ impl FeeTracker for Pallet { fn increase_fee_factor(id: Self::Id, message_size_factor: FixedU128) -> FixedU128 { >::mutate(id, |f| { - *f = f.saturating_mul(delivery_fee_constants::EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor)); + *f = f.saturating_mul( + delivery_fee_constants::EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor), + ); *f }) } diff --git a/cumulus/pallets/xcmp-queue/src/tests.rs b/cumulus/pallets/xcmp-queue/src/tests.rs index 380078298171..4916006fc932 100644 --- a/cumulus/pallets/xcmp-queue/src/tests.rs +++ b/cumulus/pallets/xcmp-queue/src/tests.rs @@ -373,8 +373,8 @@ fn xcmp_queue_send_xcm_works() { #[test] fn verify_fee_factor_increase_and_decrease() { - use sp_runtime::FixedU128; use cumulus_primitives_core::AbridgedHrmpChannel; + use sp_runtime::FixedU128; let sibling_para_id = ParaId::from(12345); let destination = (Parent, Parachain(sibling_para_id.into())).into(); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 31e57abef8c1..be7039bc9744 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -32,7 +32,10 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - xcm_config::{AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, + xcm_config::{ + AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, + RelayOrOtherSystemParachains, + }, TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index b0c0809d08de..c086043feefa 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -25,7 +25,10 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough}; -use parachains_common::{xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, TREASURY_PALLET_ID}; +use parachains_common::{ + xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, + TREASURY_PALLET_ID, +}; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; use rococo_runtime_constants::system_parachain::SystemParachains; From 5737b62c72b89be012fa13c53330de6183b1ec0b Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 17 Oct 2023 23:56:03 +0200 Subject: [PATCH 104/116] Add prdoc --- prdoc/pr_1234.prdoc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 prdoc/pr_1234.prdoc diff --git a/prdoc/pr_1234.prdoc b/prdoc/pr_1234.prdoc new file mode 100644 index 000000000000..cc22a02d88b9 --- /dev/null +++ b/prdoc/pr_1234.prdoc @@ -0,0 +1,20 @@ +# Schema: Parity PR Documentation Schema (prdoc) +# See doc at https://github.com/paritytech/prdoc + +title: Introduce XcmFeesToAccount fee manager + +doc: + - audience: Builder + description: | + Now all XCM sending, unless done by the system for the system, will be charged delivery fees. + All runtimes are now configured to send these delivery fees to a treasury account. + The fee formula is `delivery_fee_factor * (base_fee + encoded_msg_len * per_byte_fee)`. + +migrations: + db: [] + + runtime: [] + +crates: [] + +host_functions: [] From 9c1fced1ade9126bc42ed21321d6898f6e3b109b Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 08:13:39 +0200 Subject: [PATCH 105/116] Fix function call outside of externalities --- cumulus/pallets/xcmp-queue/src/tests.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cumulus/pallets/xcmp-queue/src/tests.rs b/cumulus/pallets/xcmp-queue/src/tests.rs index 4916006fc932..cf6d947609d2 100644 --- a/cumulus/pallets/xcmp-queue/src/tests.rs +++ b/cumulus/pallets/xcmp-queue/src/tests.rs @@ -324,13 +324,14 @@ fn xcmp_queue_consumes_dest_and_msg_on_ok_validate() { let dest = (Parent, X1(Parachain(5555))); let mut dest_wrapper = Some(dest.into()); let mut msg_wrapper = Some(message.clone()); - assert!(::validate(&mut dest_wrapper, &mut msg_wrapper).is_ok()); - - // check wrapper were consumed - assert_eq!(None, dest_wrapper.take()); - assert_eq!(None, msg_wrapper.take()); new_test_ext().execute_with(|| { + assert!(::validate(&mut dest_wrapper, &mut msg_wrapper).is_ok()); + + // check wrapper were consumed + assert_eq!(None, dest_wrapper.take()); + assert_eq!(None, msg_wrapper.take()); + // another try with router chain with asserting sender assert_eq!( Err(SendError::Transport("NoChannel")), From ff3cf19399fa6539e05ccf6052b983d483ad02c9 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 11:58:59 +0200 Subject: [PATCH 106/116] Fix rococo bridge hub test --- Cargo.lock | 3 +++ .../asset-hub-rococo/src/tests/teleport.rs | 4 +++- .../assets/asset-hub-westend/Cargo.toml | 2 +- .../bridges/bridge-hub-rococo/Cargo.toml | 3 +++ .../bridge-hub-rococo/src/tests/teleport.rs | 7 ++++-- .../emulated/common/src/macros.rs | 22 +++++++++++++------ .../assets/asset-hub-rococo/src/lib.rs | 18 +++++++++++++-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- 8 files changed, 47 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c56725f4803..469d8b5b4e68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2004,7 +2004,9 @@ dependencies = [ name = "bridge-hub-rococo-integration-tests" version = "1.0.0" dependencies = [ + "asset-test-utils", "bp-messages", + "bridge-hub-rococo-runtime", "cumulus-pallet-dmp-queue", "cumulus-pallet-xcmp-queue", "frame-support", @@ -2017,6 +2019,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-parachains", "staging-xcm", + "staging-xcm-executor", "xcm-emulator", ] diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs index 21afed179184..8e114a5d83da 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs @@ -14,6 +14,7 @@ // limitations under the License. use crate::*; +use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -362,7 +363,8 @@ fn teleport_to_other_system_parachains_works() { let native_asset: VersionedMultiAssets = (Parent, amount).into(); test_parachain_is_trusted_teleporter!( - AssetHubRococo, // Origin + AssetHubRococo, // Origin + AssetHubRococoXcmConfig, // XCM Configuration vec![BridgeHubRococo], // Destinations (native_asset, amount) ); diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml index fd8d78c6e8e5..4b6b8874b6a4 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/Cargo.toml @@ -36,7 +36,7 @@ westend-runtime-constants = { path = "../../../../../../polkadot/runtime/westend # Cumulus parachains-common = { path = "../../../../common" } asset-hub-westend-runtime = { path = "../../../../runtimes/assets/asset-hub-westend" } -asset-test-utils = { path = "../../../../runtimes/assets/test-utils" } +asset-test-utils = { path = "../../../../runtimes/assets/test-utils", default-features = false } cumulus-pallet-dmp-queue = { default-features = false, path = "../../../../../pallets/dmp-queue" } cumulus-pallet-parachain-system = { default-features = false, path = "../../../../../pallets/parachain-system" } diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml index 7ecf87158241..b3ce2a99f70a 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml @@ -19,13 +19,16 @@ polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false} # Cumulus +asset-test-utils = { path = "../../../../../parachains/runtimes/assets/test-utils", default-features = false } parachains-common = { path = "../../../../common" } cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false} cumulus-pallet-dmp-queue = { path = "../../../../../pallets/dmp-queue", default-features = false} pallet-bridge-messages = { path = "../../../../../../bridges/modules/messages", default-features = false} bp-messages = { path = "../../../../../../bridges/primitives/messages", default-features = false} +bridge-hub-rococo-runtime = { path = "../../../../../parachains/runtimes/bridge-hubs/bridge-hub-rococo", default-features = false } # Local xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs index 4c7e37fab623..bd16f48825ed 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs @@ -14,14 +14,17 @@ // limitations under the License. use crate::*; +use asset_test_utils::xcm_helpers; +use bridge_hub_rococo_runtime::xcm_config::XcmConfig; #[test] fn teleport_to_other_system_parachains_works() { let amount = BRIDGE_HUB_ROCOCO_ED * 100; - let native_asset: VersionedMultiAssets = (Parent, amount).into(); + let native_asset: MultiAssets = (Parent, amount).into(); test_parachain_is_trusted_teleporter!( - BridgeHubRococo, // Origin + BridgeHubRococo, // Origin + XcmConfig, // XCM configuration vec![AssetHubRococo], // Destinations (native_asset, amount) ); diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index e87c361ebeac..f91c81674ae9 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -15,7 +15,7 @@ #[macro_export] macro_rules! test_parachain_is_trusted_teleporter { - ( $sender_para:ty, vec![$( $receiver_para:ty ),+], ($assets:expr, $amount:expr) ) => { + ( $sender_para:ty, $sender_xcm_config:ty, vec![$( $receiver_para:ty ),+], ($assets:expr, $amount:expr) ) => { $crate::paste::paste! { // init Origin variables let sender = [<$sender_para Sender>]::get(); @@ -32,19 +32,22 @@ macro_rules! test_parachain_is_trusted_teleporter { let para_receiver_balance_before = <$receiver_para as $crate::Chain>::account_data_of(receiver.clone()).free; let para_destination = - <$sender_para>::sibling_location_of(<$receiver_para>::para_id()).into(); - let beneficiary = + <$sender_para>::sibling_location_of(<$receiver_para>::para_id()); + let beneficiary: MultiLocation = $crate::AccountId32 { network: None, id: receiver.clone().into() }.into(); + dbg!(&origin); + dbg!(¶_destination); + // Send XCM message from Origin Parachain // We are only testing the limited teleport version, which should be ok since success will // depend only on a proper `XcmConfig` at destination. <$sender_para>::execute_with(|| { assert_ok!(<$sender_para as [<$sender_para Pallet>]>::PolkadotXcm::limited_teleport_assets( origin.clone(), - bx!(para_destination), - bx!(beneficiary), - bx!($assets.clone()), + bx!(para_destination.into()), + bx!(beneficiary.into()), + bx!($assets.clone().into()), fee_asset_item, weight_limit.clone(), )); @@ -89,8 +92,13 @@ macro_rules! test_parachain_is_trusted_teleporter { <$sender_para as $crate::Chain>::account_data_of(sender.clone()).free; let para_receiver_balance_after = <$receiver_para as $crate::Chain>::account_data_of(receiver.clone()).free; + let delivery_fees = <$sender_para>::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + <$sender_xcm_config as xcm_executor::Config>::XcmSender, + >($assets.clone(), fee_asset_item, weight_limit.clone(), beneficiary, para_destination) + }); - assert_eq!(para_sender_balance_before - $amount, para_sender_balance_after); + assert_eq!(para_sender_balance_before - $amount - delivery_fees, para_sender_balance_after); assert!(para_receiver_balance_after > para_receiver_balance_before); // Update sender balance diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 3328ff0edaf4..24cf6eccd97e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -93,7 +93,7 @@ pub use sp_runtime::BuildStorage; // Polkadot imports use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use xcm::latest::BodyId; +use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; use crate::xcm_config::{ @@ -636,6 +636,20 @@ impl parachain_info::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {} +parameter_types! { + /// The asset ID for the asset that we use to pay for message delivery fees. + pub FeeAssetId: AssetId = Concrete(xcm_config::TokenLocation::get()); + /// The base fee for the message delivery fees. + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); +} + +pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + XcmpQueue, +>; + impl cumulus_pallet_xcmp_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; @@ -645,7 +659,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = xcm_config::XcmOriginToTransactDispatchOrigin; type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo; - type PriceForSiblingDelivery = (); + type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 49a604a72ba1..3df23112153e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -365,7 +365,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types! { /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = Concrete(xcm_config::RelayLocation::get()); + pub FeeAssetId: AssetId = Concrete(xcm_config::TokenLocation::get()); /// The base fee for the message delivery fees. pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } From 794a52d6bf1cf8475834875a298a4fa2b02528a3 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 12:27:16 +0200 Subject: [PATCH 107/116] Remove 'Here' from waived locations --- polkadot/runtime/rococo/src/xcm_config.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 342e93c89ebc..06b65ff99dd7 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -144,9 +144,6 @@ match_types! { pub type OnlyParachains: impl Contains = { MultiLocation { parents: 0, interior: X1(Parachain(_)) } }; - pub type HereLocation: impl Contains = { - MultiLocation { parents: 0, interior: Here } - }; } /// The barriers one of which must be passed for an XCM message to be executed. @@ -195,7 +192,7 @@ impl xcm_executor::Config for XcmConfig { type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type FeeManager = - XcmFeesToAccount; + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; From 237d25d0acfde727e2586b1a8af04afa82e60852 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 12:27:23 +0200 Subject: [PATCH 108/116] Fix test --- .../runtimes/bridge-hubs/test-utils/src/test_cases.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs index d4e5aac34369..e77af189b4fd 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs @@ -186,7 +186,7 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works< XcmConfig::AssetTransactor::deposit_asset( &ed, &sibling_parachain_location, - &XcmContext::with_message_id([0; 32]), + Some(&XcmContext::with_message_id([0; 32])), ) .expect("deposited ed"); } @@ -194,7 +194,7 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works< XcmConfig::AssetTransactor::deposit_asset( &fee, &sibling_parachain_location, - &XcmContext::with_message_id([0; 32]), + Some(&XcmContext::with_message_id([0; 32])), ) .expect("deposited fee"); From 4686838cf97f56d5cc695aff05f2a56c9738755d Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 12:36:14 +0200 Subject: [PATCH 109/116] Add XcmFeesToAccount to westend runtime --- polkadot/runtime/westend/src/xcm_config.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index d82b8f264da7..ead0b9bd3596 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -19,7 +19,7 @@ use super::{ parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, FellowshipAdmin, GeneralAdmin, ParaId, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, - TransactionByteFee, WeightToFee, XcmPallet, + TransactionByteFee, WeightToFee, XcmPallet, Treasury, }; use frame_support::{ @@ -44,6 +44,7 @@ use xcm_builder::{ DescribeFamily, HashedDescription, IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeesToAccount, }; use xcm_executor::XcmExecutor; @@ -53,6 +54,7 @@ parameter_types! { pub const UniversalLocation: InteriorMultiLocation = X1(GlobalConsensus(ThisNetwork::get())); pub CheckAccount: AccountId = XcmPallet::check_account(); pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local); + pub TreasuryAccount: Option = Some(Treasury::account_id()); /// The asset ID for the asset that we use to pay for message delivery fees. pub FeeAssetId: AssetId = Concrete(TokenLocation::get()); /// The base fee for the message delivery fees. @@ -183,7 +185,8 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); + type FeeManager = + XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; From bf9e431d9b07461c4f4193bdb76363a8267cdce1 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 18 Oct 2023 10:40:39 +0000 Subject: [PATCH 110/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../assets/asset-hub-rococo/src/tests/teleport.rs | 4 ++-- .../bridges/bridge-hub-rococo/src/tests/teleport.rs | 4 ++-- .../parachains/runtimes/assets/test-utils/src/lib.rs | 2 +- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 10 +++++----- polkadot/runtime/rococo/src/xcm_config.rs | 3 +-- polkadot/runtime/westend/src/xcm_config.rs | 5 ++--- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs index 8e114a5d83da..1e7bd0c34498 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs @@ -363,9 +363,9 @@ fn teleport_to_other_system_parachains_works() { let native_asset: VersionedMultiAssets = (Parent, amount).into(); test_parachain_is_trusted_teleporter!( - AssetHubRococo, // Origin + AssetHubRococo, // Origin AssetHubRococoXcmConfig, // XCM Configuration - vec![BridgeHubRococo], // Destinations + vec![BridgeHubRococo], // Destinations (native_asset, amount) ); } diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs index bd16f48825ed..17cae781503f 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs @@ -23,8 +23,8 @@ fn teleport_to_other_system_parachains_works() { let native_asset: MultiAssets = (Parent, amount).into(); test_parachain_is_trusted_teleporter!( - BridgeHubRococo, // Origin - XcmConfig, // XCM configuration + BridgeHubRococo, // Origin + XcmConfig, // XCM configuration vec![AssetHubRococo], // Destinations (native_asset, amount) ); diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs b/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs index 8b98b005a1ff..e0f05fa7b0a4 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/lib.rs @@ -17,6 +17,6 @@ //! Module contains predefined test-case scenarios for `Runtime` with various assets. pub mod test_cases; -pub mod xcm_helpers; pub mod test_cases_over_bridge; +pub mod xcm_helpers; pub use parachains_runtimes_test_utils::*; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index b00fdd78663e..0f6dfb13684e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -44,11 +44,11 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, - DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete, - ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete, ParentAsSuperuser, + ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeesToAccount, }; use xcm_executor::{ traits::{ExportXcm, WithOriginFilter}, diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 06b65ff99dd7..fb1653c549e1 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -191,8 +191,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index ead0b9bd3596..dd6a29885ad6 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -19,7 +19,7 @@ use super::{ parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, FellowshipAdmin, GeneralAdmin, ParaId, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, - TransactionByteFee, WeightToFee, XcmPallet, Treasury, + TransactionByteFee, Treasury, WeightToFee, XcmPallet, }; use frame_support::{ @@ -185,8 +185,7 @@ impl xcm_executor::Config for XcmConfig { type SubscriptionService = XcmPallet; type PalletInstancesInfo = AllPalletsWithSystem; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = - XcmFeesToAccount; + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; From 74bb3e0ac7241425fb46c16c3e1df98cfd1a9224 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 13:45:15 +0200 Subject: [PATCH 111/116] Add delivery fees to asset hub rococo tests --- Cargo.lock | 4 ++ .../assets/asset-hub-rococo/Cargo.toml | 4 ++ .../assets/asset-hub-rococo/src/lib.rs | 1 + .../src/tests/reserve_transfer.rs | 42 +++++++++++++-- .../asset-hub-rococo/src/tests/teleport.rs | 51 ++++++++++++++++--- .../bridge-hub-rococo/src/tests/teleport.rs | 1 - .../emulated/common/src/macros.rs | 2 +- .../assets/asset-hub-rococo/Cargo.toml | 4 ++ .../assets/asset-hub-rococo/src/xcm_config.rs | 28 +++++++++- 9 files changed, 122 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 469d8b5b4e68..033219583bd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,6 +798,7 @@ version = "1.0.0" dependencies = [ "assert_matches", "asset-hub-rococo-runtime", + "asset-test-utils", "frame-support", "frame-system", "integration-tests-common", @@ -810,8 +811,10 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime-parachains", + "rococo-runtime", "sp-runtime", "staging-xcm", + "staging-xcm-executor", "xcm-emulator", ] @@ -871,6 +874,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-common", "primitive-types", + "rococo-runtime", "rococo-runtime-constants", "scale-info", "smallvec", diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml index 52682c6eefd6..cb4a7b53d446 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml @@ -25,8 +25,11 @@ polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" } xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false} pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false} +xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false} +rococo-runtime = { path = "../../../../../../polkadot/runtime/rococo", default-features = false } # Cumulus +asset-test-utils = { path = "../../../../runtimes/assets/test-utils", default-features = false } parachains-common = { path = "../../../../common" } asset-hub-rococo-runtime = { path = "../../../../runtimes/assets/asset-hub-rococo" } @@ -48,4 +51,5 @@ runtime-benchmarks = [ "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "rococo-runtime/runtime-benchmarks", ] diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs index e0e9dcbdce74..7be297aa7318 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs @@ -20,6 +20,7 @@ pub use frame_support::{ sp_runtime::{AccountId32, DispatchError, DispatchResult}, traits::fungibles::Inspect, }; +pub use asset_test_utils::xcm_helpers; pub use integration_tests_common::{ constants::{ asset_hub_rococo::ED as ASSET_HUB_ROCOCO_ED, rococo::ED as ROCOCO_ED, PROOF_SIZE_THRESHOLD, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 0c136e2789f5..753e25b64d0f 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -14,6 +14,8 @@ // limitations under the License. use crate::*; +use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; +use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -182,10 +184,16 @@ fn limited_reserve_transfer_native_asset_from_relay_to_system_para_fails() { test.set_dispatchable::(relay_limited_reserve_transfer_assets); test.assert(); + let delivery_fees = Rococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } @@ -244,7 +252,13 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = Rococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); assert_eq!(receiver_balance_before, receiver_balance_after); } @@ -306,7 +320,17 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } @@ -338,7 +362,17 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + let delivery_fees = AssetHubRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( + test.args.assets.clone(), + 0, + test.args.weight_limit, + test.args.beneficiary, + test.args.dest, + ) + }); + + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // TODO: Check receiver balance when Penpal runtime is improved to propery handle reserve // transfers } diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs index 1e7bd0c34498..61dcccee7699 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs @@ -14,6 +14,7 @@ // limitations under the License. use crate::*; +use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { @@ -172,11 +173,17 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { test.set_dispatchable::(relay_limited_teleport_assets); test.assert(); + let delivery_fees = Rococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -213,8 +220,14 @@ fn limited_teleport_native_assets_back_from_system_para_to_relay_works() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = AssetHubRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -248,8 +261,14 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = AssetHubRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance does not change assert_eq!(receiver_balance_after, receiver_balance_before); } @@ -275,11 +294,17 @@ fn teleport_native_assets_from_relay_to_system_para_works() { test.set_dispatchable::(relay_teleport_assets); test.assert(); + let delivery_fees = Rococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -316,8 +341,14 @@ fn teleport_native_assets_back_from_system_para_to_relay_works() { let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; + let delivery_fees = AssetHubRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); } @@ -348,11 +379,17 @@ fn teleport_native_assets_from_system_para_to_relay_fails() { test.set_dispatchable::(system_para_teleport_assets); test.assert(); + let delivery_fees = AssetHubRococo::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + let sender_balance_after = test.sender.balance; let receiver_balance_after = test.receiver.balance; // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send, sender_balance_after); + assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance does not change assert_eq!(receiver_balance_after, receiver_balance_before); } @@ -360,7 +397,7 @@ fn teleport_native_assets_from_system_para_to_relay_fails() { #[test] fn teleport_to_other_system_parachains_works() { let amount = ASSET_HUB_ROCOCO_ED * 100; - let native_asset: VersionedMultiAssets = (Parent, amount).into(); + let native_asset: MultiAssets = (Parent, amount).into(); test_parachain_is_trusted_teleporter!( AssetHubRococo, // Origin diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs index 17cae781503f..f00288a4d8c7 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/teleport.rs @@ -14,7 +14,6 @@ // limitations under the License. use crate::*; -use asset_test_utils::xcm_helpers; use bridge_hub_rococo_runtime::xcm_config::XcmConfig; #[test] diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index f91c81674ae9..5ce940264029 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -93,7 +93,7 @@ macro_rules! test_parachain_is_trusted_teleporter { let para_receiver_balance_after = <$receiver_para as $crate::Chain>::account_data_of(receiver.clone()).free; let delivery_fees = <$sender_para>::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::< + asset_test_utils::xcm_helpers::transfer_assets_delivery_fees::< <$sender_xcm_config as xcm_executor::Config>::XcmSender, >($assets.clone(), fee_asset_item, weight_limit.clone(), beneficiary, para_destination) }); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index af0ce6d5814e..ba874469e03d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -55,6 +55,7 @@ sp-weights = { path = "../../../../../substrate/primitives/weights", default-fea primitive-types = { version = "0.12.1", default-features = false, features = ["codec", "scale-info", "num-traits"] } # Polkadot +rococo-runtime = { path = "../../../../../polkadot/runtime/rococo", default-features = false } rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false} pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false} pallet-xcm-benchmarks = { path = "../../../../../polkadot/xcm/pallet-xcm-benchmarks", default-features = false, optional = true } @@ -133,6 +134,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", + "rococo-runtime/runtime-benchmarks", ] try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", @@ -166,6 +168,7 @@ try-runtime = [ "parachain-info/try-runtime", "polkadot-runtime-common/try-runtime", "sp-runtime/try-runtime", + "rococo-runtime/try-runtime", ] std = [ "assets-common/std", @@ -236,6 +239,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "rococo-runtime/std", ] experimental = [ "pallet-aura/experimental" ] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 6db4a7874057..1459242c82b8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -27,12 +27,17 @@ use frame_support::{ match_types, parameter_types, traits::{ConstU32, Contains, Equals, Everything, Get, Nothing, PalletInfoAccess}, }; +use rococo_runtime::Treasury as RococoTreasury; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; +use sp_runtime::traits::AccountIdConversion; use parachains_common::{ impls::ToStakingPot, xcm_config::{AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem}, + TREASURY_PALLET_ID, }; +use parachains_common::xcm_config::RelayOrOtherSystemParachains; +use rococo_runtime_constants::system_parachain::SystemParachains; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::ConvertInto; use xcm::latest::prelude::*; @@ -46,6 +51,7 @@ use xcm_builder::{ SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeesToAccount, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -67,6 +73,7 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); + pub TreasuryAccount: Option = Some(TREASURY_PALLET_ID.into_account_truncating()); } /// Adapter for resolving `NetworkId` based on `pub storage Flavor: RuntimeFlavor`. @@ -521,6 +528,24 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = ForeignAssetsInstance, >; +parameter_types! { + pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(::index() as u8)).into(); +} + +pub struct RelayTreasury; +impl Contains for RelayTreasury { + fn contains(location: &MultiLocation) -> bool { + let relay_treasury_location = RelayTreasuryLocation::get(); + *location == relay_treasury_location + } +} + + +/// Locations that will not be charged fees in the executor, +/// either execution or delivery. +/// We only waive fees for system functions, which these locations represent. +pub type WaivedLocations = (RelayOrOtherSystemParachains, RelayTreasury); + /// Cases where a remote origin is accepted as trusted Teleporter for a given asset: /// /// - ROC with the parent Relay Chain and sibling system parachains; and @@ -588,8 +613,7 @@ impl xcm_executor::Config for XcmConfig { type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type AssetLocker = (); type AssetExchanger = (); - // TODO:check-parameter: change and assert in tests when (https://github.com/paritytech/polkadot-sdk/pull/1234) merged - type FeeManager = (); + type FeeManager = XcmFeesToAccount; type MessageExporter = (); type UniversalAliases = (bridging::to_wococo::UniversalAliases, bridging::to_rococo::UniversalAliases); From 997a42682945b1456036b601581e9911ed9bf756 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 18 Oct 2023 11:49:43 +0000 Subject: [PATCH 112/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../src/tests/reserve_transfer.rs | 22 ++++++------------- .../asset-hub-rococo/src/tests/teleport.rs | 2 +- .../assets/asset-hub-rococo/src/xcm_config.rs | 14 ++++++------ 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs index 7be297aa7318..42f54bdf49df 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/lib.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub use asset_test_utils::xcm_helpers; pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, @@ -20,7 +21,6 @@ pub use frame_support::{ sp_runtime::{AccountId32, DispatchError, DispatchResult}, traits::fungibles::Inspect, }; -pub use asset_test_utils::xcm_helpers; pub use integration_tests_common::{ constants::{ asset_hub_rococo::ED as ASSET_HUB_ROCOCO_ED, rococo::ED as ROCOCO_ED, PROOF_SIZE_THRESHOLD, diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 753e25b64d0f..fb25607c635e 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -14,8 +14,8 @@ // limitations under the License. use crate::*; -use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; +use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -321,13 +321,9 @@ fn limited_reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubRococo::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); @@ -363,13 +359,9 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let delivery_fees = AssetHubRococo::execute_with(|| { - xcm_helpers::transfer_assets_delivery_fees::<::XcmSender>( - test.args.assets.clone(), - 0, - test.args.weight_limit, - test.args.beneficiary, - test.args.dest, - ) + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs index 61dcccee7699..4b2ea0e160cb 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/src/tests/teleport.rs @@ -14,8 +14,8 @@ // limitations under the License. use crate::*; -use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; +use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 1459242c82b8..ed99b4b35c06 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -27,19 +27,20 @@ use frame_support::{ match_types, parameter_types, traits::{ConstU32, Contains, Equals, Everything, Get, Nothing, PalletInfoAccess}, }; -use rococo_runtime::Treasury as RococoTreasury; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use sp_runtime::traits::AccountIdConversion; use parachains_common::{ impls::ToStakingPot, - xcm_config::{AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem}, + xcm_config::{ + AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, + RelayOrOtherSystemParachains, + }, TREASURY_PALLET_ID, }; -use parachains_common::xcm_config::RelayOrOtherSystemParachains; -use rococo_runtime_constants::system_parachain::SystemParachains; use polkadot_parachain_primitives::primitives::Sibling; -use sp_runtime::traits::ConvertInto; +use rococo_runtime::Treasury as RococoTreasury; +use rococo_runtime_constants::system_parachain::SystemParachains; +use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllAssets, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -540,7 +541,6 @@ impl Contains for RelayTreasury { } } - /// Locations that will not be charged fees in the executor, /// either execution or delivery. /// We only waive fees for system functions, which these locations represent. From ffcd09fb756812a4657a98fc0a06ddb84dfa2da9 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 14:08:05 +0200 Subject: [PATCH 113/116] Fix rococo benchmarks --- .../emulated/assets/asset-hub-rococo/Cargo.toml | 3 ++- .../runtimes/assets/asset-hub-rococo/Cargo.toml | 6 +++--- .../runtimes/assets/asset-hub-rococo/src/lib.rs | 13 +++++++++++++ .../runtimes/assets/asset-hub-westend/src/lib.rs | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml index cb4a7b53d446..baaa4da6ed7a 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml @@ -50,6 +50,7 @@ runtime-benchmarks = [ "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", "rococo-runtime/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index ba874469e03d..ba846a850c84 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -131,10 +131,10 @@ runtime-benchmarks = [ "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", + "rococo-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "rococo-runtime/runtime-benchmarks", ] try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", @@ -167,8 +167,8 @@ try-runtime = [ "pallet-xcm/try-runtime", "parachain-info/try-runtime", "polkadot-runtime-common/try-runtime", - "sp-runtime/try-runtime", "rococo-runtime/try-runtime", + "sp-runtime/try-runtime", ] std = [ "assets-common/std", @@ -221,6 +221,7 @@ std = [ "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", "rococo-runtime-constants/std", + "rococo-runtime/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", @@ -239,7 +240,6 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "rococo-runtime/std", ] experimental = [ "pallet-aura/experimental" ] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 24cf6eccd97e..a0eef7e43a4b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1329,9 +1329,21 @@ impl_runtime_apis! { use xcm_config::{TokenLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; + parameter_types! { + pub ExistentialDepositMultiAsset: Option = Some(( + TokenLocation::get(), + ExistentialDeposit::get() + ).into()); + } + impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + XcmConfig, + ExistentialDepositMultiAsset, + xcm_config::PriceForParentDelivery, + >; fn valid_destination() -> Result { Ok(TokenLocation::get()) } @@ -1387,6 +1399,7 @@ impl_runtime_apis! { } impl pallet_xcm_benchmarks::generic::Config for Runtime { + type TransactAsset = Balances; type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 97b4ae986c2c..a7dc3a84777e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1279,7 +1279,7 @@ impl_runtime_apis! { parameter_types! { pub ExistentialDepositMultiAsset: Option = Some(( - xcm_config::WestendLocation::get(), + WestendLocation::get(), ExistentialDeposit::get() ).into()); } From b24cc020b4cce7e64935a70d3b242bd837013730 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 16:26:28 +0200 Subject: [PATCH 114/116] Fix asset hub rococo bridge test for now --- .../emulated/assets/asset-hub-rococo/Cargo.toml | 2 +- .../assets/asset-hub-rococo/src/xcm_config.rs | 8 ++++++-- .../assets/test-utils/src/test_cases_over_bridge.rs | 11 ++++++++++- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml index baaa4da6ed7a..db58d8d33039 100644 --- a/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo/Cargo.toml @@ -51,6 +51,6 @@ runtime-benchmarks = [ "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "rococo-runtime/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index ed99b4b35c06..01982a486583 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -14,11 +14,12 @@ // limitations under the License. use super::{ - AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ForeignAssets, + FeeAssetId, BaseDeliveryFee, AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ForeignAssets, ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeFlavor, RuntimeOrigin, ToRococoXcmRouter, ToWococoXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use assets_common::{ local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation, matching::{FromSiblingParachain, IsForeignConcreteAsset}, @@ -626,10 +627,13 @@ impl xcm_executor::Config for XcmConfig { /// Forms the basis for local origins sending/executing XCMs. pub type LocalOriginToLocation = SignedToAccountId32; +pub type PriceForParentDelivery = + ExponentialPrice; + /// For routing XCM messages which do not cross local consensus boundary. type LocalXcmRouter = ( // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, ); diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs index a967384fb6dc..56ad55a5622a 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs @@ -20,7 +20,7 @@ use codec::Encode; use cumulus_primitives_core::XcmpMessageSource; use frame_support::{ assert_ok, - traits::{Currency, OnFinalize, OnInitialize, OriginTrait, ProcessMessageError}, + traits::{Currency, OnFinalize, OnInitialize, OriginTrait, ProcessMessageError, fungible::Mutate}, }; use frame_system::pallet_prelude::BlockNumberFor; use parachains_common::{AccountId, Balance}; @@ -164,6 +164,15 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works< }), }; + // Make sure sender has enough funds for paying delivery fees + // TODO: Get this fee via weighing the corresponding message + let delivery_fees = 1324039894; + >::mint_into( + &alice_account, + delivery_fees.into(), + ) + .unwrap(); + // do pallet_xcm call reserve transfer assert_ok!(>::limited_reserve_transfer_assets( RuntimeHelper::::origin_of(alice_account.clone()), diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 3df23112153e..6b6d84649d76 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1031,7 +1031,7 @@ impl_runtime_apis! { parameter_types! { pub ExistentialDepositMultiAsset: Option = Some(( - xcm_config::RelayLocation::get(), + TokenLocation::get(), ExistentialDeposit::get() ).into()); } From a4e332fbb71ff0142a739d92a5e996e5f23fa559 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 18 Oct 2023 16:32:10 +0200 Subject: [PATCH 115/116] Use derive impl for balances in mock --- .../pallet-xcm-benchmarks/src/fungible/mock.rs | 14 ++------------ .../xcm/pallet-xcm-benchmarks/src/generic/mock.rs | 15 +++------------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index dd23f9222772..5ddf0b27cc59 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -19,7 +19,7 @@ use crate::{fungible as xcm_balances_benchmark, mock::*}; use frame_benchmarking::BenchmarkError; use frame_support::{ - parameter_types, + parameter_types, derive_impl, traits::{ConstU32, Everything, Nothing}, weights::Weight, }; @@ -75,20 +75,10 @@ parameter_types! { pub const ExistentialDeposit: u64 = 7; } +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); type ReserveIdentifier = [u8; 8]; - type Balance = u64; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; - type WeightInfo = (); - type RuntimeHoldReason = RuntimeHoldReason; - type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; - type MaxFreezes = ConstU32<0>; } parameter_types! { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 4cb95ed5ac6c..619bf29ebc41 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -20,10 +20,11 @@ use crate::{generic, mock::*, *}; use codec::Decode; use frame_support::{ match_types, parameter_types, + derive_impl, traits::{Everything, OriginTrait}, weights::Weight, }; -use sp_core::{ConstU32, H256}; +use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}; use xcm_builder::{ test_utils::{ @@ -142,20 +143,10 @@ parameter_types! { pub const ExistentialDeposit: u64 = 7; } +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); type ReserveIdentifier = [u8; 8]; - type Balance = u64; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; - type WeightInfo = (); - type RuntimeHoldReason = RuntimeHoldReason; - type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; - type MaxFreezes = ConstU32<0>; } impl crate::Config for Test { From f3a5ce64a20ff5fa75c7bfbc53dbe0589282fd93 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 18 Oct 2023 14:37:02 +0000 Subject: [PATCH 116/116] ".git/.scripts/commands/fmt/fmt.sh" --- .../assets/asset-hub-rococo/src/xcm_config.rs | 11 ++++++----- .../assets/test-utils/src/test_cases_over_bridge.rs | 11 +++++------ .../xcm/pallet-xcm-benchmarks/src/fungible/mock.rs | 2 +- .../xcm/pallet-xcm-benchmarks/src/generic/mock.rs | 3 +-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 01982a486583..d25f336f1afe 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -14,12 +14,12 @@ // limitations under the License. use super::{ - FeeAssetId, BaseDeliveryFee, AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ForeignAssets, - ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, Runtime, - RuntimeCall, RuntimeEvent, RuntimeFlavor, RuntimeOrigin, ToRococoXcmRouter, ToWococoXcmRouter, - TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, BaseDeliveryFee, + FeeAssetId, ForeignAssets, ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, + PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeFlavor, RuntimeOrigin, + ToRococoXcmRouter, ToWococoXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, + WeightToFee, XcmpQueue, }; -use polkadot_runtime_common::xcm_sender::ExponentialPrice; use assets_common::{ local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation, matching::{FromSiblingParachain, IsForeignConcreteAsset}, @@ -39,6 +39,7 @@ use parachains_common::{ TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::xcm_sender::ExponentialPrice; use rococo_runtime::Treasury as RococoTreasury; use rococo_runtime_constants::system_parachain::SystemParachains; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs index 56ad55a5622a..9852453d283b 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs @@ -20,7 +20,9 @@ use codec::Encode; use cumulus_primitives_core::XcmpMessageSource; use frame_support::{ assert_ok, - traits::{Currency, OnFinalize, OnInitialize, OriginTrait, ProcessMessageError, fungible::Mutate}, + traits::{ + fungible::Mutate, Currency, OnFinalize, OnInitialize, OriginTrait, ProcessMessageError, + }, }; use frame_system::pallet_prelude::BlockNumberFor; use parachains_common::{AccountId, Balance}; @@ -167,11 +169,8 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works< // Make sure sender has enough funds for paying delivery fees // TODO: Get this fee via weighing the corresponding message let delivery_fees = 1324039894; - >::mint_into( - &alice_account, - delivery_fees.into(), - ) - .unwrap(); + >::mint_into(&alice_account, delivery_fees.into()) + .unwrap(); // do pallet_xcm call reserve transfer assert_ok!(>::limited_reserve_transfer_assets( diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index 5ddf0b27cc59..9adc706fc18a 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -19,7 +19,7 @@ use crate::{fungible as xcm_balances_benchmark, mock::*}; use frame_benchmarking::BenchmarkError; use frame_support::{ - parameter_types, derive_impl, + derive_impl, parameter_types, traits::{ConstU32, Everything, Nothing}, weights::Weight, }; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 619bf29ebc41..710ff0d80192 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -19,8 +19,7 @@ use crate::{generic, mock::*, *}; use codec::Decode; use frame_support::{ - match_types, parameter_types, - derive_impl, + derive_impl, match_types, parameter_types, traits::{Everything, OriginTrait}, weights::Weight, };