Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a7414f5

Browse files
ozgunozerkfranciscoaguirrebkonturacatangiu
authored andcommittedAug 2, 2024
relax XcmFeeToAccount trait bound on AccountId (paritytech#4959)
Fixes paritytech#4960 Configuring `FeeManager` enforces the boundary `Into<[u8; 32]>` for the `AccountId` type. Here is how it works currently: Configuration: ```rust type FeeManager = XcmFeeManagerFromComponents< IsChildSystemParachain<primitives::Id>, XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>, >; ``` `XcmToFeeAccount` struct: ```rust /// A `HandleFee` implementation that simply deposits the fees into a specific on-chain /// `ReceiverAccount`. /// /// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets. If /// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be /// logged and the fee burned. pub struct XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>( PhantomData<(AssetTransactor, AccountId, ReceiverAccount)>, ); impl< AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 32]>, ReceiverAccount: Get<AccountId>, > HandleFee for XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount> { fn handle_fee(fee: Assets, context: Option<&XcmContext>, _reason: FeeReason) -> Assets { deposit_or_burn_fee::<AssetTransactor, _>(fee, context, ReceiverAccount::get()); Assets::new() } } ``` `deposit_or_burn_fee()` function: ```rust /// Try to deposit the given fee in the specified account. /// Burns the fee in case of a failure. pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 32]>>( fee: Assets, context: Option<&XcmContext>, receiver: AccountId, ) { let dest = AccountId32 { network: None, id: receiver.into() }.into(); for asset in fee.into_inner() { if let Err(e) = AssetTransactor::deposit_asset(&asset, &dest, context) { log::trace!( target: "xcm::fees", "`AssetTransactor::deposit_asset` returned error: {:?}. Burning fee: {:?}. \ They might be burned.", e, asset, ); } } } ``` --- In order to use **another** `AccountId` type (for example, 20 byte addresses for compatibility with Ethereum or Bitcoin), one has to duplicate the code as the following (roughly changing every `32` to `20`): ```rust /// A `HandleFee` implementation that simply deposits the fees into a specific on-chain /// `ReceiverAccount`. /// /// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets. If /// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be /// logged and the fee burned. pub struct XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>( PhantomData<(AssetTransactor, AccountId, ReceiverAccount)>, ); impl< AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 20]>, ReceiverAccount: Get<AccountId>, > HandleFee for XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount> { fn handle_fee(fee: XcmAssets, context: Option<&XcmContext>, _reason: FeeReason) -> XcmAssets { deposit_or_burn_fee::<AssetTransactor, _>(fee, context, ReceiverAccount::get()); XcmAssets::new() } } pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 20]>>( fee: XcmAssets, context: Option<&XcmContext>, receiver: AccountId, ) { let dest = AccountKey20 { network: None, key: receiver.into() }.into(); for asset in fee.into_inner() { if let Err(e) = AssetTransactor::deposit_asset(&asset, &dest, context) { log::trace!( target: "xcm::fees", "`AssetTransactor::deposit_asset` returned error: {:?}. Burning fee: {:?}. \ They might be burned.", e, asset, ); } } } ``` --- This results in code duplication, which can be avoided simply by relaxing the trait enforced by `XcmFeeToAccount`. In this PR, I propose to introduce a new trait called `IntoLocation` to be able to express both `Into<[u8; 32]>` and `Into<[u8; 20]>` should be accepted (and every other `AccountId` type as long as they implement this trait). Currently, `deposit_or_burn_fee()` function converts the `receiver: AccountId` to a location. I think converting an account to `Location` should not be the responsibility of `deposit_or_burn_fee()` function. This trait also decouples the conversion of `AccountId` to `Location`, from `deposit_or_burn_fee()` function. And exposes `IntoLocation` trait. Thus, allowing everyone to come up with their `AccountId` type and make it compatible for configuring `FeeManager`. --- Note 1: if there is a better file/location to put `IntoLocation`, I'm all ears Note 2: making `deposit_or_burn_fee` or `XcmToFeeAccount` generic was not possible from what I understood, due to Rust currently do not support a way to express the generic should implement either `trait A` or `trait B` (since the compiler cannot guarantee they won't overlap). In this case, they are `Into<[u8; 32]>` and `Into<[u8; 20]>`. See [this](rust-lang/rust#20400) and [this](rust-lang/rfcs#1672 (comment)). Note 3: I should also submit a PR to `frontier` that implements `IntoLocation` for `AccountId20` if this PR gets accepted. ### Summary this new trait: - decouples the conversion of `AccountId` to `Location`, from `deposit_or_burn_fee()` function - makes `XcmFeeToAccount` accept every possible `AccountId` type as long as they they implement `IntoLocation` - backwards compatible - keeps the API simple and clean while making it less restrictive @franciscoaguirre and @gupnik are already aware of the issue, so tagging them here for visibility. --------- Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]> Co-authored-by: command-bot <>
1 parent 13dd252 commit a7414f5

File tree

20 files changed

+172
-88
lines changed

20 files changed

+172
-88
lines changed
 

‎Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ use xcm_builder::{
5555
EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter,
5656
GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete, LocalMint,
5757
NetworkExportTableItem, NoChecking, NonFungiblesAdapter, ParentAsSuperuser, ParentIsPreset,
58-
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
58+
RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
5959
SignedAccountId32AsNative, SignedToAccountId32, SovereignPaidRemoteExporter,
6060
SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit,
6161
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
62-
XcmFeeManagerFromComponents, XcmFeeToAccount,
62+
XcmFeeManagerFromComponents,
6363
};
6464
use xcm_executor::XcmExecutor;
6565

@@ -413,7 +413,7 @@ impl xcm_executor::Config for XcmConfig {
413413
type AssetExchanger = ();
414414
type FeeManager = XcmFeeManagerFromComponents<
415415
WaivedLocations,
416-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
416+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
417417
>;
418418
type MessageExporter = ();
419419
type UniversalAliases =

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ use xcm_builder::{
5151
EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter,
5252
GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete, LocalMint,
5353
NetworkExportTableItem, NoChecking, NonFungiblesAdapter, ParentAsSuperuser, ParentIsPreset,
54-
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
54+
RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
5555
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith,
5656
StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
5757
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
58-
XcmFeeToAccount,
5958
};
6059
use xcm_executor::XcmExecutor;
6160

@@ -429,7 +428,7 @@ impl xcm_executor::Config for XcmConfig {
429428
type AssetExchanger = ();
430429
type FeeManager = XcmFeeManagerFromComponents<
431430
WaivedLocations,
432-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
431+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
433432
>;
434433
type MessageExporter = ();
435434
type UniversalAliases = (bridging::to_rococo::UniversalAliases,);

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

+14-11
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ use xcm_builder::{
4949
AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom,
5050
AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
5151
FrameTransactionalProcessor, FungibleAdapter, HandleFee, IsConcrete, ParentAsSuperuser,
52-
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
53-
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
54-
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
55-
XcmFeeToAccount,
52+
ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative,
53+
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
54+
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
55+
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
5656
};
5757
use xcm_executor::{
5858
traits::{FeeManager, FeeReason, FeeReason::Export, TransactAsset},
@@ -223,7 +223,7 @@ impl xcm_executor::Config for XcmConfig {
223223
Self::AssetTransactor,
224224
crate::EthereumOutboundQueue,
225225
>,
226-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
226+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
227227
),
228228
>;
229229
type MessageExporter = (
@@ -354,24 +354,27 @@ impl<
354354
match asset.fun {
355355
Fungible(total_fee) => {
356356
let source_fee = total_fee / 2;
357-
deposit_or_burn_fee::<AssetTransactor, _>(
357+
deposit_or_burn_fee::<AssetTransactor>(
358358
Asset { id: asset.id.clone(), fun: Fungible(source_fee) }.into(),
359359
maybe_context,
360-
source_para_account.clone(),
360+
AccountId32 { network: None, id: source_para_account.clone().into() }
361+
.into(),
361362
);
362363

363364
let dest_fee = total_fee - source_fee;
364-
deposit_or_burn_fee::<AssetTransactor, _>(
365+
deposit_or_burn_fee::<AssetTransactor>(
365366
Asset { id: asset.id, fun: Fungible(dest_fee) }.into(),
366367
maybe_context,
367-
dest_para_account.clone(),
368+
AccountId32 { network: None, id: dest_para_account.clone().into() }
369+
.into(),
368370
);
369371
},
370372
NonFungible(_) => {
371-
deposit_or_burn_fee::<AssetTransactor, _>(
373+
deposit_or_burn_fee::<AssetTransactor>(
372374
asset.into(),
373375
maybe_context,
374-
source_para_account.clone(),
376+
AccountId32 { network: None, id: source_para_account.clone().into() }
377+
.into(),
375378
);
376379
},
377380
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ use xcm_builder::{
4242
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
4343
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FrameTransactionalProcessor,
4444
FungibleAdapter, IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
45-
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
46-
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
47-
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
48-
XcmFeeManagerFromComponents, XcmFeeToAccount,
45+
SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
46+
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
47+
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
48+
XcmFeeManagerFromComponents,
4949
};
5050
use xcm_executor::XcmExecutor;
5151

@@ -195,7 +195,7 @@ impl xcm_executor::Config for XcmConfig {
195195
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
196196
type FeeManager = XcmFeeManagerFromComponents<
197197
WaivedLocations,
198-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
198+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
199199
>;
200200
type MessageExporter = (crate::bridge_to_rococo_config::ToBridgeHubRococoHaulBlobExporter,);
201201
type UniversalAliases = Nothing;

‎cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ use xcm_builder::{
4040
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
4141
FrameTransactionalProcessor, FungibleAdapter, IsConcrete, LocatableAssetId,
4242
OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
43-
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
44-
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
45-
UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
46-
XcmFeeToAccount,
43+
SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
44+
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
45+
TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
46+
XcmFeeManagerFromComponents,
4747
};
4848
use xcm_executor::XcmExecutor;
4949

@@ -209,7 +209,7 @@ impl xcm_executor::Config for XcmConfig {
209209
type AssetExchanger = ();
210210
type FeeManager = XcmFeeManagerFromComponents<
211211
WaivedLocations,
212-
XcmFeeToAccount<Self::AssetTransactor, AccountId, WestendTreasuryAccount>,
212+
SendXcmFeeToAccount<Self::AssetTransactor, WestendTreasuryAccount>,
213213
>;
214214
type MessageExporter = ();
215215
type UniversalAliases = Nothing;

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ use xcm_builder::{
4242
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
4343
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
4444
FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentAsSuperuser,
45-
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
46-
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
47-
TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
48-
XcmFeeManagerFromComponents, XcmFeeToAccount,
45+
ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative,
46+
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
47+
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
48+
WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
4949
};
5050
use xcm_executor::XcmExecutor;
5151

@@ -191,7 +191,7 @@ impl xcm_executor::Config for XcmConfig {
191191
type AssetExchanger = ();
192192
type FeeManager = XcmFeeManagerFromComponents<
193193
WaivedLocations,
194-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
194+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
195195
>;
196196
type MessageExporter = ();
197197
type UniversalAliases = Nothing;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ use xcm_builder::{
4343
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
4444
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FrameTransactionalProcessor,
4545
FungibleAdapter, IsConcrete, NonFungibleAdapter, ParentAsSuperuser, ParentIsPreset,
46-
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
46+
RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
4747
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
4848
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
49-
XcmFeeManagerFromComponents, XcmFeeToAccount,
49+
XcmFeeManagerFromComponents,
5050
};
5151
use xcm_executor::XcmExecutor;
5252

@@ -213,7 +213,7 @@ impl xcm_executor::Config for XcmConfig {
213213
type AssetExchanger = ();
214214
type FeeManager = XcmFeeManagerFromComponents<
215215
WaivedLocations,
216-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
216+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
217217
>;
218218
type MessageExporter = ();
219219
type UniversalAliases = Nothing;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ use xcm_builder::{
4343
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
4444
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FrameTransactionalProcessor,
4545
FungibleAdapter, IsConcrete, NonFungibleAdapter, ParentAsSuperuser, ParentIsPreset,
46-
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
46+
RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
4747
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
4848
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
49-
XcmFeeManagerFromComponents, XcmFeeToAccount,
49+
XcmFeeManagerFromComponents,
5050
};
5151
use xcm_executor::XcmExecutor;
5252

@@ -221,7 +221,7 @@ impl xcm_executor::Config for XcmConfig {
221221
type AssetExchanger = ();
222222
type FeeManager = XcmFeeManagerFromComponents<
223223
WaivedLocations,
224-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
224+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
225225
>;
226226
type MessageExporter = ();
227227
type UniversalAliases = Nothing;

‎cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ use xcm_builder::{
4040
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
4141
DenyReserveTransferToRelayChain, DenyThenTry, DescribeTerminus, EnsureXcmOrigin,
4242
FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, ParentAsSuperuser,
43-
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
44-
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
45-
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
46-
XcmFeeManagerFromComponents, XcmFeeToAccount,
43+
ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative,
44+
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
45+
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
46+
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
4747
};
4848
use xcm_executor::XcmExecutor;
4949

@@ -219,7 +219,7 @@ impl xcm_executor::Config for XcmConfig {
219219
type AssetExchanger = ();
220220
type FeeManager = XcmFeeManagerFromComponents<
221221
WaivedLocations,
222-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
222+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
223223
>;
224224
type MessageExporter = ();
225225
type UniversalAliases = Nothing;

‎cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ use xcm_builder::{
4040
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
4141
DenyReserveTransferToRelayChain, DenyThenTry, DescribeTerminus, EnsureXcmOrigin,
4242
FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, ParentAsSuperuser,
43-
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
44-
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
45-
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
46-
XcmFeeManagerFromComponents, XcmFeeToAccount,
43+
ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative,
44+
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
45+
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
46+
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
4747
};
4848
use xcm_executor::XcmExecutor;
4949

@@ -227,7 +227,7 @@ impl xcm_executor::Config for XcmConfig {
227227
type AssetExchanger = ();
228228
type FeeManager = XcmFeeManagerFromComponents<
229229
WaivedLocations,
230-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
230+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
231231
>;
232232
type MessageExporter = ();
233233
type UniversalAliases = Nothing;

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ use xcm_builder::{
4747
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AsPrefixedGeneralIndex,
4848
ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor,
4949
FungibleAdapter, FungiblesAdapter, IsConcrete, LocalMint, NativeAsset, NoChecking,
50-
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
51-
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
52-
SovereignSignedViaLocation, StartsWith, TakeWeightCredit, TrailingSetTopicAsId,
53-
UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
54-
XcmFeeToAccount,
50+
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount,
51+
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
52+
SignedToAccountId32, SovereignSignedViaLocation, StartsWith, TakeWeightCredit,
53+
TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
54+
XcmFeeManagerFromComponents,
5555
};
5656
use xcm_executor::{traits::JustTry, XcmExecutor};
5757

@@ -351,7 +351,7 @@ impl xcm_executor::Config for XcmConfig {
351351
type AssetExchanger = ();
352352
type FeeManager = XcmFeeManagerFromComponents<
353353
(),
354-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
354+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
355355
>;
356356
type MessageExporter = ();
357357
type UniversalAliases = Nothing;

‎polkadot/runtime/rococo/src/xcm_config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ use xcm_builder::{
4141
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
4242
ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily, FixedWeightBounds,
4343
FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsChildSystemParachain,
44-
IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative,
45-
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
46-
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
47-
XcmFeeManagerFromComponents, XcmFeeToAccount,
44+
IsConcrete, MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount,
45+
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
46+
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
47+
XcmFeeManagerFromComponents,
4848
};
4949
use xcm_executor::XcmExecutor;
5050

@@ -213,7 +213,7 @@ impl xcm_executor::Config for XcmConfig {
213213
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
214214
type FeeManager = XcmFeeManagerFromComponents<
215215
WaivedLocations,
216-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
216+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
217217
>;
218218
type MessageExporter = ();
219219
type UniversalAliases = Nothing;

‎polkadot/runtime/westend/src/xcm_config.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ use xcm_builder::{
4242
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
4343
ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily, FrameTransactionalProcessor,
4444
FungibleAdapter, HashedDescription, IsChildSystemParachain, IsConcrete, MintLocation,
45-
OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32,
45+
OriginToPluralityVoice, SendXcmFeeToAccount, SignedAccountId32AsNative, SignedToAccountId32,
4646
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
4747
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
48-
XcmFeeToAccount,
4948
};
5049
use xcm_executor::XcmExecutor;
5150

@@ -211,7 +210,7 @@ impl xcm_executor::Config for XcmConfig {
211210
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
212211
type FeeManager = XcmFeeManagerFromComponents<
213212
WaivedLocations,
214-
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
213+
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
215214
>;
216215
type MessageExporter = ();
217216
type UniversalAliases = Nothing;

‎polkadot/xcm/Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ impl-trait-for-tuples = { workspace = true }
1717
log = { workspace = true }
1818
codec = { features = ["derive", "max-encoded-len"], workspace = true }
1919
scale-info = { features = ["derive", "serde"], workspace = true }
20+
sp-runtime = { workspace = true }
2021
sp-weights = { features = ["serde"], workspace = true }
2122
serde = { features = ["alloc", "derive", "rc"], workspace = true }
2223
schemars = { default-features = true, optional = true, workspace = true }
@@ -38,6 +39,11 @@ std = [
3839
"log/std",
3940
"scale-info/std",
4041
"serde/std",
42+
"sp-runtime/std",
4143
"sp-weights/std",
4244
]
43-
json-schema = ["bounded-collections/json-schema", "dep:schemars", "sp-weights/json-schema"]
45+
json-schema = [
46+
"bounded-collections/json-schema",
47+
"dep:schemars",
48+
"sp-weights/json-schema",
49+
]

‎polkadot/xcm/pallet-xcm/src/mock.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ use xcm_builder::{
3535
AllowTopLevelPaidExecutionFrom, Case, ChildParachainAsNative, ChildParachainConvertsVia,
3636
ChildSystemParachainAsSuperuser, DescribeAllTerminal, EnsureDecodableXcm, FixedRateOfFungible,
3737
FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter,
38-
HashedDescription, IsConcrete, MatchedConvertedConcreteId, NoChecking,
38+
HashedDescription, IsConcrete, MatchedConvertedConcreteId, NoChecking, SendXcmFeeToAccount,
3939
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
40-
XcmFeeManagerFromComponents, XcmFeeToAccount,
40+
XcmFeeManagerFromComponents,
4141
};
4242
use xcm_executor::{
4343
traits::{Identity, JustTry},
@@ -504,7 +504,7 @@ impl xcm_executor::Config for XcmConfig {
504504
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
505505
type FeeManager = XcmFeeManagerFromComponents<
506506
EverythingBut<XcmFeesNotWaivedLocations>,
507-
XcmFeeToAccount<Self::AssetTransactor, AccountId, XcmFeesTargetAccount>,
507+
SendXcmFeeToAccount<Self::AssetTransactor, XcmFeesTargetAccount>,
508508
>;
509509
type MessageExporter = ();
510510
type UniversalAliases = Nothing;

‎polkadot/xcm/src/v4/location.rs

+6
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ impl From<[u8; 32]> for Location {
534534
}
535535
}
536536

537+
impl From<sp_runtime::AccountId32> for Location {
538+
fn from(id: sp_runtime::AccountId32) -> Self {
539+
Junction::AccountId32 { network: None, id: id.into() }.into()
540+
}
541+
}
542+
537543
xcm_procedural::impl_conversion_functions_for_location_v4!();
538544

539545
#[cfg(test)]

‎polkadot/xcm/xcm-builder/src/fee_handling.rs

+46-21
Original file line numberDiff line numberDiff line change
@@ -68,45 +68,70 @@ impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
6868
}
6969
}
7070

71-
/// Try to deposit the given fee in the specified account.
72-
/// Burns the fee in case of a failure.
73-
pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 32]>>(
74-
fee: Assets,
75-
context: Option<&XcmContext>,
76-
receiver: AccountId,
77-
) {
78-
let dest = AccountId32 { network: None, id: receiver.into() }.into();
79-
for asset in fee.into_inner() {
80-
if let Err(e) = AssetTransactor::deposit_asset(&asset, &dest, context) {
81-
log::trace!(
82-
target: "xcm::fees",
83-
"`AssetTransactor::deposit_asset` returned error: {:?}. Burning fee: {:?}. \
84-
They might be burned.",
85-
e, asset,
86-
);
87-
}
88-
}
89-
}
90-
9171
/// A `HandleFee` implementation that simply deposits the fees into a specific on-chain
9272
/// `ReceiverAccount`.
9373
///
9474
/// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets. If
9575
/// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be
9676
/// logged and the fee burned.
77+
#[deprecated(
78+
note = "`XcmFeeToAccount` will be removed in January 2025. Use `SendXcmFeeToAccount` instead."
79+
)]
9780
pub struct XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>(
9881
PhantomData<(AssetTransactor, AccountId, ReceiverAccount)>,
9982
);
10083

84+
#[allow(deprecated)]
10185
impl<
10286
AssetTransactor: TransactAsset,
10387
AccountId: Clone + Into<[u8; 32]>,
10488
ReceiverAccount: Get<AccountId>,
10589
> HandleFee for XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>
10690
{
10791
fn handle_fee(fee: Assets, context: Option<&XcmContext>, _reason: FeeReason) -> Assets {
108-
deposit_or_burn_fee::<AssetTransactor, _>(fee, context, ReceiverAccount::get());
92+
let dest = AccountId32 { network: None, id: ReceiverAccount::get().into() }.into();
93+
deposit_or_burn_fee::<AssetTransactor>(fee, context, dest);
94+
95+
Assets::new()
96+
}
97+
}
98+
99+
/// A `HandleFee` implementation that simply deposits the fees into a specific on-chain
100+
/// `ReceiverAccount`.
101+
///
102+
/// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets. If
103+
/// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be
104+
/// logged and the fee burned.
105+
///
106+
/// `ReceiverAccount` should implement `Get<Location>`.
107+
pub struct SendXcmFeeToAccount<AssetTransactor, ReceiverAccount>(
108+
PhantomData<(AssetTransactor, ReceiverAccount)>,
109+
);
110+
111+
impl<AssetTransactor: TransactAsset, ReceiverAccount: Get<Location>> HandleFee
112+
for SendXcmFeeToAccount<AssetTransactor, ReceiverAccount>
113+
{
114+
fn handle_fee(fee: Assets, context: Option<&XcmContext>, _reason: FeeReason) -> Assets {
115+
deposit_or_burn_fee::<AssetTransactor>(fee, context, ReceiverAccount::get());
109116

110117
Assets::new()
111118
}
112119
}
120+
121+
/// Try to deposit the given fee in the specified account.
122+
/// Burns the fee in case of a failure.
123+
pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset>(
124+
fee: Assets,
125+
context: Option<&XcmContext>,
126+
dest: Location,
127+
) {
128+
for asset in fee.into_inner() {
129+
if let Err(e) = AssetTransactor::deposit_asset(&asset, &dest, context) {
130+
log::trace!(
131+
target: "xcm::fees",
132+
"`AssetTransactor::deposit_asset` returned error: {e:?}. Burning fee: {asset:?}. \
133+
They might be burned.",
134+
);
135+
}
136+
}
137+
}

‎polkadot/xcm/xcm-builder/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub use currency_adapter::CurrencyAdapter;
5656

5757
mod fee_handling;
5858
pub use fee_handling::{
59-
deposit_or_burn_fee, HandleFee, XcmFeeManagerFromComponents, XcmFeeToAccount,
59+
deposit_or_burn_fee, HandleFee, SendXcmFeeToAccount, XcmFeeManagerFromComponents,
6060
};
6161

6262
mod filter_asset_location;

‎prdoc/pr_4959.prdoc

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: relax XcmFeeToAccount trait bound on AccountId
5+
6+
doc:
7+
- audience: Runtime Dev
8+
description: |
9+
This PR relaxes the trait bound on AccountId for the XcmFeeToAccount struct by introducing a new struct called `SendXcmFeeToAccount`.
10+
The old one (`XcmFeeToAccount`) will be deprecated at January 2025.
11+
12+
crates:
13+
- name: staging-xcm-builder
14+
bump: minor
15+
- name: staging-xcm
16+
bump: minor
17+
- name: pallet-xcm
18+
bump: minor
19+
- name: asset-hub-rococo-runtime
20+
bump: minor
21+
- name: asset-hub-westend-runtime
22+
bump: minor
23+
- name: bridge-hub-rococo-runtime
24+
bump: minor
25+
- name: bridge-hub-westend-runtime
26+
bump: minor
27+
- name: collectives-westend-runtime
28+
bump: minor
29+
- name: contracts-rococo-runtime
30+
bump: minor
31+
- name: coretime-rococo-runtime
32+
bump: minor
33+
- name: coretime-westend-runtime
34+
bump: minor
35+
- name: people-rococo-runtime
36+
bump: minor
37+
- name: people-westend-runtime
38+
bump: minor
39+
- name: penpal-runtime
40+
bump: minor
41+
- name: rococo-runtime
42+
bump: minor
43+
- name: westend-runtime
44+
bump: minor
45+

0 commit comments

Comments
 (0)
Please sign in to comment.