Skip to content

Commit dd9514f

Browse files
jpserratacatangiuactions-user
authored
add FeeManager to pallet xcm (#5363)
Closes #2082 change send xcm to use `xcm::executor::FeeManager` to determine if the sender should be charged. I had to change the `FeeManager` of the penpal config to ensure the same test behaviour as before. For the other tests, I'm using the `FeeManager` from the `xcm::executor::FeeManager` as this one is used to check if the fee can be waived on the charge fees method. --------- Co-authored-by: Adrian Catangiu <adrian@parity.io> Co-authored-by: GitHub Action <action@github.com>
1 parent a5de3b1 commit dd9514f

11 files changed

Lines changed: 51 additions & 10 deletions

File tree

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use xcm_builder::{
6666
use xcm_executor::XcmExecutor;
6767

6868
parameter_types! {
69+
pub const RootLocation: Location = Location::here();
6970
pub const TokenLocation: Location = Location::parent();
7071
pub const RelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
7172
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
@@ -315,6 +316,7 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
315316
/// either execution or delivery.
316317
/// We only waive fees for system functions, which these locations represent.
317318
pub type WaivedLocations = (
319+
Equals<RootLocation>,
318320
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
319321
Equals<RelayTreasuryLocation>,
320322
);

cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ use xcm_builder::{
6363
use xcm_executor::XcmExecutor;
6464

6565
parameter_types! {
66+
pub const RootLocation: Location = Location::here();
6667
pub const WestendLocation: Location = Location::parent();
6768
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
6869
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
@@ -336,6 +337,7 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
336337
/// either execution or delivery.
337338
/// We only waive fees for system functions, which these locations represent.
338339
pub type WaivedLocations = (
340+
Equals<RootLocation>,
339341
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
340342
Equals<RelayTreasuryLocation>,
341343
FellowshipEntities,

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use xcm_executor::{
5757
};
5858

5959
parameter_types! {
60+
pub const RootLocation: Location = Location::here();
6061
pub const TokenLocation: Location = Location::parent();
6162
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
6263
pub RelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
@@ -164,6 +165,7 @@ pub type Barrier = TrailingSetTopicAsId<
164165
/// either execution or delivery.
165166
/// We only waive fees for system functions, which these locations represent.
166167
pub type WaivedLocations = (
168+
Equals<RootLocation>,
167169
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
168170
Equals<RelayTreasuryLocation>,
169171
);

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use xcm_executor::{
5656
};
5757

5858
parameter_types! {
59+
pub const RootLocation: Location = Location::here();
5960
pub const WestendLocation: Location = Location::parent();
6061
pub const RelayNetwork: NetworkId = NetworkId::ByGenesis(WESTEND_GENESIS_HASH);
6162
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
@@ -161,6 +162,7 @@ pub type Barrier = TrailingSetTopicAsId<
161162
/// either execution or delivery.
162163
/// We only waive fees for system functions, which these locations represent.
163164
pub type WaivedLocations = (
165+
Equals<RootLocation>,
164166
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
165167
Equals<RelayTreasuryLocation>,
166168
);

cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use xcm_builder::{
5151
use xcm_executor::XcmExecutor;
5252

5353
parameter_types! {
54+
pub const RootLocation: Location = Location::here();
5455
pub const RelayLocation: Location = Location::parent();
5556
pub const RelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
5657
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
@@ -166,6 +167,7 @@ pub type Barrier = TrailingSetTopicAsId<
166167
/// either execution or delivery.
167168
/// We only waive fees for system functions, which these locations represent.
168169
pub type WaivedLocations = (
170+
Equals<RootLocation>,
169171
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
170172
Equals<RelayTreasuryLocation>,
171173
);

cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use xcm_builder::{
5252
use xcm_executor::XcmExecutor;
5353

5454
parameter_types! {
55+
pub const RootLocation: Location = Location::here();
5556
pub const RocRelayLocation: Location = Location::parent();
5657
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH));
5758
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
@@ -177,6 +178,7 @@ parameter_types! {
177178
/// Locations that will not be charged fees in the executor, neither for execution nor delivery.
178179
/// We only waive fees for system functions, which these locations represent.
179180
pub type WaivedLocations = (
181+
Equals<RootLocation>,
180182
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
181183
Equals<RelayTreasuryLocation>,
182184
);

cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use xcm_builder::{
5252
use xcm_executor::XcmExecutor;
5353

5454
parameter_types! {
55+
pub const RootLocation: Location = Location::here();
5556
pub const TokenRelayLocation: Location = Location::parent();
5657
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
5758
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
@@ -185,6 +186,7 @@ parameter_types! {
185186
/// Locations that will not be charged fees in the executor, neither for execution nor delivery.
186187
/// We only waive fees for system functions, which these locations represent.
187188
pub type WaivedLocations = (
189+
Equals<RootLocation>,
188190
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
189191
Equals<RelayTreasuryLocation>,
190192
);

cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use core::marker::PhantomData;
3434
use frame_support::{
3535
parameter_types,
3636
traits::{
37-
tokens::imbalance::ResolveAssetTo, ConstU32, Contains, ContainsPair, Everything,
37+
tokens::imbalance::ResolveAssetTo, ConstU32, Contains, ContainsPair, Equals, Everything,
3838
EverythingBut, Get, Nothing, PalletInfoAccess,
3939
},
4040
weights::Weight,
@@ -210,6 +210,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
210210
);
211211

212212
parameter_types! {
213+
pub const RootLocation: Location = Location::here();
213214
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
214215
pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
215216
pub const MaxInstructions: u32 = 100;
@@ -336,6 +337,7 @@ pub type TrustedReserves = (
336337
pub type TrustedTeleporters =
337338
(AssetFromChain<LocalTeleportableToAssetHub, SystemAssetHubLocation>,);
338339

340+
pub type WaivedLocations = Equals<RootLocation>;
339341
/// `AssetId`/`Balance` converter for `TrustBackedAssets`.
340342
pub type TrustBackedAssetsConvertedConcreteId =
341343
assets_common::TrustBackedAssetsConvertedConcreteId<AssetsPalletLocation, Balance>;
@@ -399,7 +401,7 @@ impl xcm_executor::Config for XcmConfig {
399401
type AssetLocker = ();
400402
type AssetExchanger = PoolAssetsExchanger;
401403
type FeeManager = XcmFeeManagerFromComponents<
402-
(),
404+
WaivedLocations,
403405
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
404406
>;
405407
type MessageExporter = ();

polkadot/xcm/pallet-xcm/src/lib.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use xcm_runtime_apis::{
7575

7676
#[cfg(any(feature = "try-runtime", test))]
7777
use sp_runtime::TryRuntimeError;
78+
use xcm_executor::traits::{FeeManager, FeeReason};
7879

7980
pub trait WeightInfo {
8081
fn send() -> Weight;
@@ -240,7 +241,7 @@ pub mod pallet {
240241
type XcmExecuteFilter: Contains<(Location, Xcm<<Self as Config>::RuntimeCall>)>;
241242

242243
/// Something to execute an XCM message.
243-
type XcmExecutor: ExecuteXcm<<Self as Config>::RuntimeCall> + XcmAssetTransfers;
244+
type XcmExecutor: ExecuteXcm<<Self as Config>::RuntimeCall> + XcmAssetTransfers + FeeManager;
244245

245246
/// Our XCM filter which messages to be teleported using the dedicated extrinsic must pass.
246247
type XcmTeleportFilter: Contains<(Location, Vec<Asset>)>;
@@ -2468,17 +2469,17 @@ impl<T: Config> Pallet<T> {
24682469
mut message: Xcm<()>,
24692470
) -> Result<XcmHash, SendError> {
24702471
let interior = interior.into();
2472+
let local_origin = interior.clone().into();
24712473
let dest = dest.into();
2472-
let maybe_fee_payer = if interior != Junctions::Here {
2474+
let is_waived =
2475+
<T::XcmExecutor as FeeManager>::is_waived(Some(&local_origin), FeeReason::ChargeFees);
2476+
if interior != Junctions::Here {
24732477
message.0.insert(0, DescendOrigin(interior.clone()));
2474-
Some(interior.into())
2475-
} else {
2476-
None
2477-
};
2478+
}
24782479
tracing::debug!(target: "xcm::send_xcm", "{:?}, {:?}", dest.clone(), message.clone());
24792480
let (ticket, price) = validate_send::<T::XcmRouter>(dest, message)?;
2480-
if let Some(fee_payer) = maybe_fee_payer {
2481-
Self::charge_fees(fee_payer, price).map_err(|e| {
2481+
if !is_waived {
2482+
Self::charge_fees(local_origin, price).map_err(|e| {
24822483
tracing::error!(
24832484
target: "xcm::pallet_xcm::send_xcm",
24842485
?e,

polkadot/xcm/xcm-executor/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ impl<Config: config::Config> XcmAssetTransfers for XcmExecutor<Config> {
304304
type AssetTransactor = Config::AssetTransactor;
305305
}
306306

307+
impl<Config: config::Config> FeeManager for XcmExecutor<Config> {
308+
fn is_waived(origin: Option<&Location>, r: FeeReason) -> bool {
309+
Config::FeeManager::is_waived(origin, r)
310+
}
311+
312+
fn handle_fee(fee: Assets, context: Option<&XcmContext>, r: FeeReason) {
313+
Config::FeeManager::handle_fee(fee, context, r)
314+
}
315+
}
316+
307317
#[derive(Debug)]
308318
pub struct ExecutorError {
309319
pub index: u32,

0 commit comments

Comments
 (0)