Skip to content

Commit

Permalink
Less error-prone specifying of system parachains
Browse files Browse the repository at this point in the history
  • Loading branch information
gilescope authored and KiChjang committed Aug 29, 2023
1 parent 898645c commit 53dfe45
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 105 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cumulus/parachains/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ xcm-executor = { path = "../../../polkadot/xcm/xcm-executor", default-features =
pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false }
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false }
parachain-info = { path = "../pallets/parachain-info", default-features = false }

[dev-dependencies]
pallet-authorship = { path = "../../../substrate/frame/authorship", default-features = false}
Expand Down
24 changes: 22 additions & 2 deletions cumulus/parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::impls::AccountIdOf;
use core::marker::PhantomData;
use frame_support::{
traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, ContainsPair},
traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, Contains, ContainsPair},
weights::Weight,
};
use log;
use sp_runtime::traits::Get;
use xcm::latest::prelude::*;

Expand Down Expand Up @@ -63,3 +62,24 @@ impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
}
}

pub struct RelayOrOtherSystemParachains<
SystemParachainMatcher: Contains<MultiLocation>,
Runtime: parachain_info::Config,
> {
_runtime: PhantomData<(SystemParachainMatcher, Runtime)>,
}
impl<SystemParachainMatcher: Contains<MultiLocation>, Runtime: parachain_info::Config>
Contains<MultiLocation> for RelayOrOtherSystemParachains<SystemParachainMatcher, Runtime>
{
fn contains(l: &MultiLocation) -> bool {
let self_para_id: u32 = parachain_info::Pallet::<Runtime>::get().into();
if let MultiLocation { parents: 0, interior: X1(Parachain(para_id)) } = l {
if *para_id == self_para_id {
return false
}
}
matches!(l, MultiLocation { parents: 1, interior: Here }) ||
SystemParachainMatcher::contains(l)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ use frame_support::{
traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess},
};
use frame_system::EnsureRoot;
use kusama_parachain::primitives::Sibling;
use kusama_runtime_constants::system_parachain::SystemParachains;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::AssetFeeAsExistentialDepositMultiplier,
xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use xcm::latest::prelude::*;
use xcm_builder::{
Expand All @@ -47,7 +48,7 @@ use xcm_builder::{
NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -475,15 +476,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia
TrustBackedAssetsInstance,
>;

match_types! {
pub type RelayOrOtherSystemParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(
kusama_runtime_constants::system_parachain::ENCOINTER_ID |
kusama_runtime_constants::system_parachain::BRIDGE_HUB_ID)) } |
MultiLocation { parents: 1, interior: Here }
};
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -530,8 +522,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager =
XcmFeesToAccount<Self, RelayOtherOrSystemParachains, AccountId, TreasuryAccount>;
type FeeManager = XcmFeesToAccount<
Self,
RelayOtherOrSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::AssetFeeAsExistentialDepositMultiplier,
xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_constants::system_parachain::SystemParachains;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -395,15 +396,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia
TrustBackedAssetsInstance,
>;

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

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -450,8 +442,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager =
XcmFeesToAccount<Self, RelayOrOtherSystemParachains, AccountId, TreasuryAccount>;
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::AssetFeeAsExistentialDepositMultiplier,
xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use westend_runtime_constants::system_parachain::SystemParachains;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand Down Expand Up @@ -478,15 +479,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia
TrustBackedAssetsInstance,
>;

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

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -533,8 +525,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager =
XcmFeesToAccount<Self, RelayOrOtherSystemParachains, AccountId, TreasuryAccount>;
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ use frame_support::{
traits::{ConstU32, Contains, Everything, Nothing},
};
use frame_system::EnsureRoot;
use kusama_runtime_constants::system_parachain::SystemParachains;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::ConcreteNativeAssetFrom,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
Expand Down Expand Up @@ -184,15 +185,6 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

match_types! {
pub type RelayOrOtherSystemParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(
kusama_runtime_constants::system_parachain::STATEMINE_ID |
kusama_runtime_constants::system_parachain::ENCOINTER_ID)) } |
MultiLocation { parents: 1, interior: Here }
};
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -221,8 +213,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager =
XcmFeesToAccount<Self, RelayOrOtherSystemParachains, AccountId, TreasuryAccount>;
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::ConcreteNativeAssetFrom,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_constants::system_parachain::SystemParachains;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -188,15 +189,6 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

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

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -225,8 +217,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager =
XcmFeesToAccount<Self, RelayOrOtherSystemParachains, AccountId, TreasuryAccount>;
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::ConcreteNativeAssetFrom,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use rococo_runtime_constants::system_parachain::SystemParachains;
use sp_core::Get;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
Expand Down Expand Up @@ -230,16 +231,6 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

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

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -268,8 +259,12 @@ impl xcm_executor::Config for XcmConfig {
type SubscriptionService = PolkadotXcm;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager =
XcmFeesToAccount<Self, RelayOrOtherSystemParachains, AccountId, TreasuryAccount>;
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = BridgeHubRococoOrBridgeHubWococoSwitchExporter;
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::ConcreteNativeAssetFrom,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_constants::system_parachain::SystemParachains;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -234,16 +235,6 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

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

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand All @@ -268,8 +259,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager =
XcmFeesToAccount<Self, RelayOrOtherSystemParachains, AccountId, TreasuryAccount>;
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Loading

0 comments on commit 53dfe45

Please sign in to comment.