Skip to content

Commit 0b3d067

Browse files
Added AllSiblingSystemParachains matcher to be used at a parachain level (#2422)
As suggested in this thread: polkadot-fellows/runtimes#87 (comment) We already have the `IsChildSystemParachain`, which may be used at relay chain, but it can't be used at a parachain level. So let's use `AllSiblingSystemParachains` for that. I was thinking about `AllSystemParachains`, but it may cause wrong impression that it can be used at a relay chain level. --------- Co-authored-by: joe petrowski <[email protected]>
1 parent 4df313f commit 0b3d067

File tree

12 files changed

+93
-122
lines changed

12 files changed

+93
-122
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachains/common/src/xcm_config.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ impl<SystemParachainMatcher: Contains<MultiLocation>, Runtime: parachain_info::C
100100
}
101101
}
102102

103+
/// Contains all sibling system parachains, including the one where this matcher is used.
104+
///
105+
/// This structure can only be used at a parachain level. In the Relay Chain, please use
106+
/// the `xcm_builder::IsChildSystemParachain` matcher.
107+
pub struct AllSiblingSystemParachains;
108+
109+
impl Contains<MultiLocation> for AllSiblingSystemParachains {
110+
fn contains(l: &MultiLocation) -> bool {
111+
log::trace!(target: "xcm::contains", "AllSiblingSystemParachains location: {:?}", l);
112+
match *l {
113+
// System parachain
114+
MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
115+
ParaId::from(id).is_system(),
116+
// Everything else
117+
_ => false,
118+
}
119+
}
120+
}
121+
103122
/// Accepts an asset if it is a concrete asset from the system (Relay Chain or system parachain).
104123
pub struct ConcreteAssetFromSystem<AssetLocation>(PhantomData<AssetLocation>);
105124
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
@@ -122,12 +141,14 @@ impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
122141

123142
#[cfg(test)]
124143
mod tests {
125-
use frame_support::parameter_types;
144+
use frame_support::{parameter_types, traits::Contains};
126145

127146
use super::{
128-
ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here, MultiAsset, MultiLocation,
129-
PalletInstance, Parachain, Parent,
147+
AllSiblingSystemParachains, ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here,
148+
MultiAsset, MultiLocation, PalletInstance, Parachain, Parent,
130149
};
150+
use polkadot_primitives::LOWEST_PUBLIC_ID;
151+
use xcm::latest::prelude::*;
131152

132153
parameter_types! {
133154
pub const RelayLocation: MultiLocation = MultiLocation::parent();
@@ -180,4 +201,19 @@ mod tests {
180201
);
181202
}
182203
}
204+
205+
#[test]
206+
fn all_sibling_system_parachains_works() {
207+
// system parachain
208+
assert!(AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(Parachain(1)))));
209+
// non-system parachain
210+
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(
211+
1,
212+
X1(Parachain(LOWEST_PUBLIC_ID.into()))
213+
)));
214+
// when used at relay chain
215+
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(0, X1(Parachain(1)))));
216+
// when used with non-parachain
217+
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(OnlyChild))));
218+
}
183219
}

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ use pallet_xcm::XcmPassthrough;
3232
use parachains_common::{
3333
impls::ToStakingPot,
3434
xcm_config::{
35-
AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem,
36-
RelayOrOtherSystemParachains,
35+
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
36+
ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
3737
},
3838
TREASURY_PALLET_ID,
3939
};
4040
use polkadot_parachain_primitives::primitives::Sibling;
4141
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
42-
use rococo_runtime_constants::system_parachain;
4342
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
4443
use xcm::latest::prelude::*;
4544
use xcm_builder::{
@@ -513,25 +512,13 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
513512
ForeignAssetsInstance,
514513
>;
515514

516-
match_types! {
517-
pub type SystemParachains: impl Contains<MultiLocation> = {
518-
MultiLocation {
519-
parents: 1,
520-
interior: X1(Parachain(
521-
system_parachain::ASSET_HUB_ID |
522-
system_parachain::BRIDGE_HUB_ID |
523-
system_parachain::CONTRACTS_ID |
524-
system_parachain::ENCOINTER_ID
525-
)),
526-
}
527-
};
528-
}
529-
530515
/// Locations that will not be charged fees in the executor,
531516
/// either execution or delivery.
532517
/// We only waive fees for system functions, which these locations represent.
533-
pub type WaivedLocations =
534-
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
518+
pub type WaivedLocations = (
519+
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
520+
Equals<RelayTreasuryLocation>,
521+
);
535522

536523
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
537524
///

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ use pallet_xcm::XcmPassthrough;
3232
use parachains_common::{
3333
impls::ToStakingPot,
3434
xcm_config::{
35-
AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem,
36-
RelayOrOtherSystemParachains,
35+
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
36+
ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
3737
},
3838
TREASURY_PALLET_ID,
3939
};
4040
use polkadot_parachain_primitives::primitives::Sibling;
4141
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
4242
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
43-
use westend_runtime_constants::system_parachain;
4443
use xcm::latest::prelude::*;
4544
use xcm_builder::{
4645
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
@@ -520,24 +519,13 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
520519
ForeignAssetsInstance,
521520
>;
522521

523-
match_types! {
524-
pub type SystemParachains: impl Contains<MultiLocation> = {
525-
MultiLocation {
526-
parents: 1,
527-
interior: X1(Parachain(
528-
system_parachain::ASSET_HUB_ID |
529-
system_parachain::COLLECTIVES_ID |
530-
system_parachain::BRIDGE_HUB_ID
531-
)),
532-
}
533-
};
534-
}
535-
536522
/// Locations that will not be charged fees in the executor,
537523
/// either execution or delivery.
538524
/// We only waive fees for system functions, which these locations represent.
539-
pub type WaivedLocations =
540-
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
525+
pub type WaivedLocations = (
526+
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
527+
Equals<RelayTreasuryLocation>,
528+
);
541529

542530
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
543531
///

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ use frame_system::EnsureRoot;
3333
use pallet_xcm::XcmPassthrough;
3434
use parachains_common::{
3535
impls::ToStakingPot,
36-
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
36+
xcm_config::{
37+
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
38+
},
3739
TREASURY_PALLET_ID,
3840
};
3941
use polkadot_parachain_primitives::primitives::Sibling;
4042
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
41-
use rococo_runtime_constants::system_parachain;
4243
use sp_core::Get;
4344
use sp_runtime::traits::AccountIdConversion;
4445
use sp_std::marker::PhantomData;
@@ -220,25 +221,13 @@ pub type Barrier = TrailingSetTopicAsId<
220221
>,
221222
>;
222223

223-
match_types! {
224-
pub type SystemParachains: impl Contains<MultiLocation> = {
225-
MultiLocation {
226-
parents: 1,
227-
interior: X1(Parachain(
228-
system_parachain::ASSET_HUB_ID |
229-
system_parachain::BRIDGE_HUB_ID |
230-
system_parachain::CONTRACTS_ID |
231-
system_parachain::ENCOINTER_ID
232-
)),
233-
}
234-
};
235-
}
236-
237224
/// Locations that will not be charged fees in the executor,
238225
/// either execution or delivery.
239226
/// We only waive fees for system functions, which these locations represent.
240-
pub type WaivedLocations =
241-
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
227+
pub type WaivedLocations = (
228+
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
229+
Equals<RelayTreasuryLocation>,
230+
);
242231

243232
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
244233
/// - NativeToken with the parent Relay Chain and sibling parachains.

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ use frame_system::EnsureRoot;
2828
use pallet_xcm::XcmPassthrough;
2929
use parachains_common::{
3030
impls::ToStakingPot,
31-
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
31+
xcm_config::{
32+
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
33+
},
3234
TREASURY_PALLET_ID,
3335
};
3436
use polkadot_parachain_primitives::primitives::Sibling;
3537
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
3638
use sp_runtime::traits::AccountIdConversion;
37-
use westend_runtime_constants::system_parachain;
3839
use xcm::latest::prelude::*;
3940
use xcm_builder::{
4041
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
@@ -209,24 +210,13 @@ pub type Barrier = TrailingSetTopicAsId<
209210
>,
210211
>;
211212

212-
match_types! {
213-
pub type SystemParachains: impl Contains<MultiLocation> = {
214-
MultiLocation {
215-
parents: 1,
216-
interior: X1(Parachain(
217-
system_parachain::ASSET_HUB_ID |
218-
system_parachain::BRIDGE_HUB_ID |
219-
system_parachain::COLLECTIVES_ID
220-
)),
221-
}
222-
};
223-
}
224-
225213
/// Locations that will not be charged fees in the executor,
226214
/// either execution or delivery.
227215
/// We only waive fees for system functions, which these locations represent.
228-
pub type WaivedLocations =
229-
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
216+
pub type WaivedLocations = (
217+
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
218+
Equals<RelayTreasuryLocation>,
219+
);
230220

231221
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
232222
/// - NativeToken with the parent Relay Chain and sibling parachains.

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ use frame_system::EnsureRoot;
2727
use pallet_xcm::XcmPassthrough;
2828
use parachains_common::{
2929
impls::ToStakingPot,
30-
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
30+
xcm_config::{
31+
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
32+
},
3133
};
3234
use polkadot_parachain_primitives::primitives::Sibling;
3335
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
34-
use westend_runtime_constants::system_parachain;
3536
use xcm::latest::prelude::*;
3637
use xcm_builder::{
3738
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
@@ -250,24 +251,13 @@ pub type Barrier = TrailingSetTopicAsId<
250251
>,
251252
>;
252253

253-
match_types! {
254-
pub type SystemParachains: impl Contains<MultiLocation> = {
255-
MultiLocation {
256-
parents: 1,
257-
interior: X1(Parachain(
258-
system_parachain::ASSET_HUB_ID |
259-
system_parachain::BRIDGE_HUB_ID |
260-
system_parachain::COLLECTIVES_ID
261-
)),
262-
}
263-
};
264-
}
265-
266254
/// Locations that will not be charged fees in the executor,
267255
/// either execution or delivery.
268256
/// We only waive fees for system functions, which these locations represent.
269-
pub type WaivedLocations =
270-
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
257+
pub type WaivedLocations = (
258+
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
259+
Equals<RelayTreasuryLocation>,
260+
);
271261

272262
/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
273263
/// - DOT with the parent Relay Chain and sibling parachains.

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ use frame_support::{
2727
use frame_system::EnsureRoot;
2828
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
2929
use parachains_common::{
30-
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
30+
xcm_config::{
31+
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
32+
},
3133
TREASURY_PALLET_ID,
3234
};
3335
use polkadot_parachain_primitives::primitives::Sibling;
3436
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
35-
use rococo_runtime_constants::system_parachain;
3637
use sp_runtime::traits::AccountIdConversion;
3738
use xcm::latest::prelude::*;
3839
use xcm_builder::{
@@ -158,25 +159,13 @@ pub type Barrier = TrailingSetTopicAsId<
158159
>,
159160
>;
160161

161-
match_types! {
162-
pub type SystemParachains: impl Contains<MultiLocation> = {
163-
MultiLocation {
164-
parents: 1,
165-
interior: X1(Parachain(
166-
system_parachain::ASSET_HUB_ID |
167-
system_parachain::BRIDGE_HUB_ID |
168-
system_parachain::CONTRACTS_ID |
169-
system_parachain::ENCOINTER_ID
170-
)),
171-
}
172-
};
173-
}
174-
175162
/// Locations that will not be charged fees in the executor,
176163
/// either execution or delivery.
177164
/// We only waive fees for system functions, which these locations represent.
178-
pub type WaivedLocations =
179-
(RelayOrOtherSystemParachains<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
165+
pub type WaivedLocations = (
166+
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
167+
Equals<RelayTreasuryLocation>,
168+
);
180169

181170
pub type TrustedTeleporter = ConcreteAssetFromSystem<RelayLocation>;
182171

polkadot/runtime/rococo/constants/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ sp-weights = { path = "../../../../substrate/primitives/weights", default-featur
1717
sp-core = { path = "../../../../substrate/primitives/core", default-features = false }
1818

1919
xcm = { package = "staging-xcm", path = "../../../xcm", default-features = false }
20+
xcm-builder = { package = "staging-xcm-builder", path = "../../../xcm/xcm-builder", default-features = false }
2021

2122
[features]
2223
default = ["std"]
@@ -27,6 +28,7 @@ std = [
2728
"sp-core/std",
2829
"sp-runtime/std",
2930
"sp-weights/std",
31+
"xcm-builder/std",
3032
"xcm/std",
3133
]
3234

polkadot/runtime/rococo/constants/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ pub mod fee {
103103

104104
/// System Parachains.
105105
pub mod system_parachain {
106-
use xcm::latest::prelude::*;
106+
use primitives::Id;
107+
use xcm_builder::IsChildSystemParachain;
107108

108109
/// Network's Asset Hub parachain ID.
109110
pub const ASSET_HUB_ID: u32 = 1000;
@@ -114,11 +115,8 @@ pub mod system_parachain {
114115
/// BridgeHub parachain ID.
115116
pub const BRIDGE_HUB_ID: u32 = 1013;
116117

117-
frame_support::match_types! {
118-
pub type SystemParachains: impl Contains<MultiLocation> = {
119-
MultiLocation { parents: 0, interior: X1(Parachain(ASSET_HUB_ID | CONTRACTS_ID | ENCOINTER_ID | BRIDGE_HUB_ID)) }
120-
};
121-
}
118+
/// All system parachains of Rococo.
119+
pub type SystemParachains = IsChildSystemParachain<Id>;
122120
}
123121

124122
/// Rococo Treasury pallet instance.

0 commit comments

Comments
 (0)