Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AllSiblingSystemParachains matcher to be used at a parachain level #2422

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

42 changes: 39 additions & 3 deletions cumulus/parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ impl<SystemParachainMatcher: Contains<MultiLocation>, Runtime: parachain_info::C
}
}

/// Contains all sibling system parachains, including the one where this matcher is used.
///
/// This structure can only be used at a parachain level. In the Relay Chain, please use
/// the `xcm_builder::IsChildSystemParachain` matcher.
pub struct AllSiblingSystemParachains;

impl Contains<MultiLocation> for AllSiblingSystemParachains {
fn contains(l: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "AllSiblingSystemParachains location: {:?}", l);
match *l {
// System parachain
MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
ParaId::from(id).is_system(),
// Everything else
_ => false,
}
}
}

/// Accepts an asset if it is a concrete asset from the system (Relay Chain or system parachain).
pub struct ConcreteAssetFromSystem<AssetLocation>(PhantomData<AssetLocation>);
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
Expand All @@ -122,12 +141,14 @@ impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>

#[cfg(test)]
mod tests {
use frame_support::parameter_types;
use frame_support::{parameter_types, traits::Contains};

use super::{
ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here, MultiAsset, MultiLocation,
PalletInstance, Parachain, Parent,
AllSiblingSystemParachains, ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here,
MultiAsset, MultiLocation, PalletInstance, Parachain, Parent,
};
use polkadot_primitives::LOWEST_PUBLIC_ID;
use xcm::latest::prelude::*;

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Expand Down Expand Up @@ -180,4 +201,19 @@ mod tests {
);
}
}

#[test]
fn all_sibling_system_parachains_works() {
// system parachain
assert!(AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(Parachain(1)))));
// non-system parachain
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(
1,
X1(Parachain(LOWEST_PUBLIC_ID.into()))
)));
// when used at relay chain
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(0, X1(Parachain(1)))));
// when used with non-parachain
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(OnlyChild))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{
AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem,
RelayOrOtherSystemParachains,
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
},
TREASURY_PALLET_ID,
};
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -513,25 +512,13 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
ForeignAssetsInstance,
>;

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

/// 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<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
pub type WaivedLocations = (
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);

/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{
AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem,
RelayOrOtherSystemParachains,
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
},
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_constants::system_parachain;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand Down Expand Up @@ -520,24 +519,13 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
ForeignAssetsInstance,
>;

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

/// 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<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
pub type WaivedLocations = (
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);

/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
xcm_config::{
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
},
TREASURY_PALLET_ID,
};
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain;
use sp_core::Get;
use sp_runtime::traits::AccountIdConversion;
use sp_std::marker::PhantomData;
Expand Down Expand Up @@ -220,25 +221,13 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

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

/// 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<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
pub type WaivedLocations = (
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);

/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
/// - NativeToken with the parent Relay Chain and sibling parachains.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
xcm_config::{
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
},
TREASURY_PALLET_ID,
};
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use sp_runtime::traits::AccountIdConversion;
use westend_runtime_constants::system_parachain;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand Down Expand Up @@ -209,24 +210,13 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

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

/// 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<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
pub type WaivedLocations = (
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);

/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
/// - NativeToken with the parent Relay Chain and sibling parachains.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
xcm_config::{
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
},
};
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use westend_runtime_constants::system_parachain;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand Down Expand Up @@ -250,24 +251,13 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

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

/// 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<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
pub type WaivedLocations = (
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);

/// Cases where a remote origin is accepted as trusted Teleporter for a given asset:
/// - DOT with the parent Relay Chain and sibling parachains.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ use frame_support::{
use frame_system::EnsureRoot;
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use parachains_common::{
xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains},
xcm_config::{
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
},
TREASURY_PALLET_ID,
};
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -158,25 +159,13 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

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

/// 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<SystemParachains, Runtime>, Equals<RelayTreasuryLocation>);
pub type WaivedLocations = (
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);

pub type TrustedTeleporter = ConcreteAssetFromSystem<RelayLocation>;

Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/rococo/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sp-weights = { path = "../../../../substrate/primitives/weights", default-featur
sp-core = { path = "../../../../substrate/primitives/core", default-features = false }

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

[features]
default = [ "std" ]
Expand All @@ -27,6 +28,7 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-weights/std",
"xcm-builder/std",
"xcm/std",
]

Expand Down
10 changes: 4 additions & 6 deletions polkadot/runtime/rococo/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ pub mod fee {

/// System Parachains.
pub mod system_parachain {
use xcm::latest::prelude::*;
use primitives::Id;
use xcm_builder::IsChildSystemParachain;

/// Network's Asset Hub parachain ID.
pub const ASSET_HUB_ID: u32 = 1000;
Expand All @@ -114,11 +115,8 @@ pub mod system_parachain {
/// 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)) }
};
}
/// All system parachains of Rococo.
pub type SystemParachains = IsChildSystemParachain<Id>;
}

/// Rococo Treasury pallet instance.
Expand Down
Loading