Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
272c31d
Introduce XcmFeesToAccount fee manager
KiChjang Apr 4, 2023
13f5944
Fixes
KiChjang Apr 4, 2023
3d0cfde
Fixes
KiChjang Apr 4, 2023
c28700d
Put system parachain IDs into consts
KiChjang Apr 4, 2023
d5b760b
Fixes
KiChjang Apr 4, 2023
a2d3604
Remove XcmFeesToAccount config for Westend
KiChjang Apr 4, 2023
7e99987
Include Encointer as a system parachain
KiChjang Apr 4, 2023
04d4410
Emit warning when deposit_asset fails
KiChjang Apr 5, 2023
5d6e2c2
Add comment on what happens when deposit_asset errors
KiChjang Apr 5, 2023
7e4cc0a
Fixes
KiChjang Apr 5, 2023
17c0f5c
Move SystemParachains to constants
KiChjang Apr 6, 2023
12b816e
Fixes
KiChjang Apr 6, 2023
d22046f
Fixes
KiChjang Apr 6, 2023
6c9f3f9
cargo fmt
KiChjang Apr 7, 2023
424c903
Added BridgeHubs constants (#7053)
bkontur Apr 12, 2023
7b140f0
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
KiChjang Apr 13, 2023
a852957
Add SystemParachain type to Westmint
KiChjang Apr 13, 2023
e1b6af0
Fixes
KiChjang Apr 20, 2023
20b4f66
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
KiChjang Apr 20, 2023
09828da
Fixes
KiChjang Apr 24, 2023
0e06f73
Waive fee handling during benchmarking
KiChjang Apr 28, 2023
6a4fd76
Fixes
KiChjang Apr 28, 2023
6eccb05
Fixes
KiChjang Apr 28, 2023
2df8cbf
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
KiChjang Apr 28, 2023
de0e397
Rename to ASSET_HUB_ID
KiChjang Jun 22, 2023
8bb8fb9
Rename all asset parachains to AssetHub
KiChjang Jun 22, 2023
3ea877f
Merge branch 'master' into kckyeung/xcm-fee-manager
KiChjang Jun 22, 2023
4843e58
Fix typo
KiChjang Jun 22, 2023
7c3bb1a
".git/.scripts/commands/fmt/fmt.sh"
Jun 22, 2023
50a008e
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
Jul 4, 2023
76a4cd0
Merge branch 'master' into kckyeung/xcm-fee-manager
KiChjang Aug 2, 2023
7d61d2e
Fixes
KiChjang Aug 2, 2023
18945f8
Fixes
KiChjang Aug 2, 2023
6f4a8bb
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
KiChjang Aug 3, 2023
4fa5016
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
Aug 8, 2023
88b9582
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
Aug 13, 2023
2c7d14c
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
Aug 15, 2023
57b3a6d
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-fee-ma…
Aug 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion runtime/kusama/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features
sp-weights = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }

xcm = { package = "xcm", path = "../../../xcm", default-features = false }

[features]
default = ["std"]
std = [
Expand All @@ -23,5 +25,6 @@ std = [
"runtime-common/std",
"sp-core/std",
"sp-runtime/std",
"sp-weights/std"
"sp-weights/std",
"xcm/std",
]
18 changes: 18 additions & 0 deletions runtime/kusama/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ pub mod fee {
}
}

/// System Parachains.
pub mod system_parachain {
use xcm::latest::prelude::*;

/// 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.
pub const BRIDGE_HUB_ID: u32 = 1002;

frame_support::match_types! {
pub type SystemParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) }
};
}
}

#[cfg(test)]
mod tests {
use super::{
Expand Down
12 changes: 6 additions & 6 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,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,
LocalCheckAccount, SovereignAccountOf, AssetHub, TokenLocation, XcmConfig,
};

impl pallet_session_benchmarking::Config for Runtime {}
Expand All @@ -2121,7 +2121,7 @@ sp_api::impl_runtime_apis! {
type XcmConfig = XcmConfig;
type AccountIdConverter = SovereignAccountOf;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(Statemine::get())
Ok(AssetHub::get())
}
fn worst_case_holding(_depositable_count: u32) -> MultiAssets {
// Kusama only knows about KSM.
Expand All @@ -2134,7 +2134,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;
Expand Down Expand Up @@ -2173,15 +2173,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<MultiLocation, BenchmarkError> {
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))
Expand Down
29 changes: 18 additions & 11 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

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,
traits::{Contains, Everything, Nothing},
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},
Expand All @@ -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;

Expand All @@ -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<AccountId> = Some(Treasury::account_id());
}

/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to
Expand Down Expand Up @@ -126,14 +128,19 @@ 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 Encointer: MultiLocation = Parachain(1001).into_location();
pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get());
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 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<KsmForStatemine>, xcm_builder::Case<KsmForEncointer>);
pub type TrustedTeleporters = (
xcm_builder::Case<KsmForAssetHub>,
xcm_builder::Case<KsmForEncointer>,
xcm_builder::Case<KsmForBridgeHub>,
);

match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
Expand Down Expand Up @@ -339,7 +346,7 @@ impl xcm_executor::Config for XcmConfig {
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager = ();
type FeeManager = XcmFeesToAccount<Self, SystemParachains, AccountId, TreasuryAccount>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this change () -> XcmFeesToAccount
Is there any change or consequence for non-system parachains or end users?
I mean, is there anything which will start failing after this is upgraded on-live?
Something like: non-system parachain should drip their sovereign account on relay chain?
If so, maybe should be part of release notes or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be -- with or without a FeeManager, we've still been collecting fees, the only difference here is that previously we were just burning them after collecting them, but with this change, we simply deposit them to the treasury account.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual impl FeeManager for () here behaves as everything is waived now,
so, iiuc charge_fees and takes_fee they never do AssetTransactor::withdraw_asset, but now with XcmFeesToAccount they will do AssetTransactor::withdraw_asset,

so I think this is the change, that origin needs to have some balance > ED + fees, but I dont know how much this is a really issue. I can imaging just some scenarios/calls from some non-system parachain that does not have sovereign account with balance on relay chain, so after this change they will need to drip some DOTs/KSMs to pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so I just took a look at where we collect fees in the XCM executor: it looks like any instruction where it creates and sends an XCM back to the origin would require the origin to pay for fees, and this includes the Query* instructions, the Report* instructions, the ExportMessage instruction and most of the cross-chain asset transfer instructions (e.g. InitiateTeleport).

This isn't a huge deal, I think what we do need to do is to display delivery fees in the UI clearly so that users are informed about how much they need to pay, otherwise their XCM would fail to be sent.

// No bridges yet...
type MessageExporter = ();
type UniversalAliases = Nothing;
Expand All @@ -357,7 +364,7 @@ parameter_types! {

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parachain(1000).into());
pub ReachableDest: Option<MultiLocation> = Some(Parachain(ASSET_HUB_ID).into());
}

/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
Expand Down
5 changes: 4 additions & 1 deletion runtime/polkadot/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features
sp-weights = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }

xcm = { package = "xcm", path = "../../../xcm", default-features = false }

[features]
default = ["std"]
std = [
Expand All @@ -23,5 +25,6 @@ std = [
"runtime-common/std",
"sp-core/std",
"sp-runtime/std",
"sp-weights/std"
"sp-weights/std",
"xcm/std",
]
14 changes: 12 additions & 2 deletions runtime/polkadot/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,20 @@ pub mod xcm {

/// System Parachains.
pub mod system_parachain {
/// Statemint parachain ID.
pub const STATEMINT_ID: u32 = 1000;
use xcm::latest::prelude::*;

/// 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.
pub const BRIDGE_HUB_ID: u32 = 1002;

frame_support::match_types! {
pub type SystemParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | COLLECTIVES_ID | BRIDGE_HUB_ID)) }
};
}
}

#[cfg(test)]
Expand Down
12 changes: 6 additions & 6 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ 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::{XcmConfig, AssetHubLocation, TokenLocation, LocalCheckAccount, SovereignAccountOf};

impl pallet_session_benchmarking::Config for Runtime {}
impl pallet_offences_benchmarking::Config for Runtime {}
Expand All @@ -2080,7 +2080,7 @@ sp_api::impl_runtime_apis! {
type XcmConfig = XcmConfig;
type AccountIdConverter = SovereignAccountOf;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(StatemintLocation::get())
Ok(AssetHubLocation::get())
}
fn worst_case_holding(_depositable_count: u32) -> MultiAssets {
// Polkadot only knows about DOT
Expand All @@ -2090,7 +2090,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;
Expand Down Expand Up @@ -2129,15 +2129,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<MultiLocation, BenchmarkError> {
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))
Expand Down
23 changes: 15 additions & 8 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use super::{
parachains_origin, AccountId, AllPalletsWithSystem, Balances, CouncilCollective, Dmp,
FellowshipAdmin, ParaId, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin,
TransactionByteFee, WeightToFee, XcmPallet,
TransactionByteFee, Treasury, WeightToFee, XcmPallet,
};
use frame_support::{
match_types, parameter_types,
Expand All @@ -44,7 +44,7 @@ use xcm_builder::{
ChildParachainAsNative, ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter,
IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
WeightInfoBounds, WithComputedOrigin,
WeightInfoBounds, WithComputedOrigin, XcmFeesToAccount,
};
use xcm_executor::traits::WithOriginFilter;

Expand All @@ -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<AccountId> = Some(Treasury::account_id());
}

/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to
Expand Down Expand Up @@ -131,16 +133,21 @@ pub type XcmRouter = (

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.
pub type TrustedTeleporters =
(xcm_builder::Case<DotForStatemint>, xcm_builder::Case<DotForCollectives>);
/// Polkadot Relay recognizes/respects the Asset Hub, Collectives and Bridge hub chains as a
/// teleporter.
pub type TrustedTeleporters = (
xcm_builder::Case<DotForAssetHub>,
xcm_builder::Case<DotForCollectives>,
xcm_builder::Case<DotForBridgeHub>,
);

match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
Expand Down Expand Up @@ -340,7 +347,7 @@ impl xcm_executor::Config for XcmConfig {
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager = ();
type FeeManager = XcmFeesToAccount<Self, SystemParachains, AccountId, TreasuryAccount>;
// No bridges yet...
type MessageExporter = ();
type UniversalAliases = Nothing;
Expand Down
5 changes: 4 additions & 1 deletion runtime/rococo/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features
sp-weights = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }

xcm = { package = "xcm", path = "../../../xcm", default-features = false }

[features]
default = ["std"]
std = [
Expand All @@ -23,5 +25,6 @@ std = [
"runtime-common/std",
"sp-core/std",
"sp-runtime/std",
"sp-weights/std"
"sp-weights/std",
"xcm/std",
]
20 changes: 20 additions & 0 deletions runtime/rococo/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ pub mod fee {
}
}

/// System Parachains.
pub mod system_parachain {
use xcm::latest::prelude::*;

/// 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.
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> = {
MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | CONTRACTS_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) }
};
}
}

#[cfg(test)]
mod tests {
use super::{
Expand Down
Loading