From 185e301fdd45cc20a696ae2792a3573583ab775e Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 11 Jan 2022 01:09:34 -0800 Subject: [PATCH] Move XCM runtime configurations into their own files (#4644) * Move XCM runtime configurations into their own files * Update copyright year * Fix compilation errors * Import XCM types in westend runtime unit tests --- polkadot/runtime/kusama/src/lib.rs | 178 ++----------------- polkadot/runtime/kusama/src/xcm_config.rs | 187 ++++++++++++++++++++ polkadot/runtime/polkadot/src/lib.rs | 171 +----------------- polkadot/runtime/polkadot/src/xcm_config.rs | 184 +++++++++++++++++++ polkadot/runtime/rococo/src/lib.rs | 152 +--------------- polkadot/runtime/rococo/src/xcm_config.rs | 170 ++++++++++++++++++ polkadot/runtime/westend/src/lib.rs | 145 ++------------- polkadot/runtime/westend/src/tests.rs | 1 + polkadot/runtime/westend/src/xcm_config.rs | 143 +++++++++++++++ 9 files changed, 725 insertions(+), 606 deletions(-) create mode 100644 polkadot/runtime/kusama/src/xcm_config.rs create mode 100644 polkadot/runtime/polkadot/src/xcm_config.rs create mode 100644 polkadot/runtime/rococo/src/xcm_config.rs create mode 100644 polkadot/runtime/westend/src/xcm_config.rs diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index f9fdef9923..5ad2da1586 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -33,9 +33,9 @@ use primitives::{ v2::SessionInfo, }; use runtime_common::{ - auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, xcm_sender, - BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit, - OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, ToAuthor, + auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, BlockHashCount, + BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit, + OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, }; use sp_core::u32_trait::{_1, _2, _3, _5}; use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*}; @@ -52,10 +52,10 @@ use runtime_parachains::{ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::crypto::AuthorityId as BeefyId; use frame_support::{ - construct_runtime, match_type, parameter_types, + construct_runtime, parameter_types, traits::{ - Contains, EnsureOneOf, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, - Nothing, OnRuntimeUpgrade, PrivilegeCmp, + Contains, EnsureOneOf, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, + OnRuntimeUpgrade, PrivilegeCmp, }, weights::Weight, PalletId, RuntimeDebug, @@ -82,16 +82,6 @@ use sp_staking::SessionIndex; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, BackingToPlurality, - ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, - CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete, - LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, - TakeWeightCredit, UsingComponents, -}; -use xcm_executor::XcmExecutor; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; @@ -110,6 +100,9 @@ mod weights; // Voter bag threshold definitions. mod bag_thresholds; +// XCM configurations. +mod xcm_config; + #[cfg(test)] mod tests; @@ -1210,7 +1203,8 @@ parameter_types! { impl parachains_ump::Config for Runtime { type Event = Event; - type UmpSink = crate::parachains_ump::XcmSink, Runtime>; + type UmpSink = + crate::parachains_ump::XcmSink, Runtime>; type FirstMessageFactorPercent = FirstMessageFactorPercent; type ExecuteOverweightOrigin = EnsureRoot; } @@ -1316,156 +1310,6 @@ impl auctions::Config for Runtime { type WeightInfo = weights::runtime_common_auctions::WeightInfo; } -parameter_types! { - /// The location of the KSM token, from the context of this chain. Since this token is native to this - /// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to - /// the context". - pub const KsmLocation: MultiLocation = Here.into(); - /// The Kusama network ID. This is named. - pub const KusamaNetwork: NetworkId = NetworkId::Kusama; - /// Our XCM location ancestry - i.e. what, if anything, `Parent` means evaluated in our context. Since - /// Kusama is a top-level relay-chain, there is no ancestry. - pub const Ancestry: MultiLocation = Here.into(); - /// The check account, which holds any native assets that have been teleported out and not back in (yet). - pub CheckAccount: AccountId = XcmPallet::check_account(); -} - -/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine -/// the sovereign account controlled by a location. -pub type SovereignAccountOf = ( - // We can convert a child parachain using the standard `AccountId` conversion. - ChildParachainConvertsVia, - // We can directly alias an `AccountId32` into a local account. - AccountId32Aliases, -); - -/// Our asset transactor. This is what allows us to interest with the runtime facilities from the point of -/// view of XCM-only concepts like `MultiLocation` and `MultiAsset`. -/// -/// Ours is only aware of the Balances pallet, which is mapped to `KsmLocation`. -pub type LocalAssetTransactor = XcmCurrencyAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // We can convert the MultiLocations with our converter above: - SovereignAccountOf, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // We track our teleports in/out to keep total issuance correct. - CheckAccount, ->; - -/// The means that we convert an the XCM message origin location into a local dispatch origin. -type LocalOriginConverter = ( - // A `Signed` origin of the sovereign account that the original location controls. - SovereignSignedViaLocation, - // A child parachain, natively expressed, has the `Parachain` origin. - ChildParachainAsNative, - // The AccountId32 location type can be expressed natively as a `Signed` origin. - SignedAccountId32AsNative, - // A system child parachain, expressed as a Superuser, converts to the `Root` origin. - ChildSystemParachainAsSuperuser, -); - -parameter_types! { - /// The amount of weight an XCM operation takes. This is a safe overestimate. - pub const BaseXcmWeight: Weight = 1_000_000_000; - /// Maximum number of instructions in a single XCM fragment. A sanity check against weight - /// calculations getting too crazy. - pub const MaxInstructions: u32 = 100; -} - -/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our -/// individual routers. -pub type XcmRouter = ( - // Only one router so far - use DMP to communicate with child parachains. - xcm_sender::ChildParachainRouter, -); - -parameter_types! { - pub const Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(KsmLocation::get()) }); - pub const KusamaForStatemine: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Parachain(1000).into()); - pub const KusamaForEncointer: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Parachain(1001).into()); -} -pub type TrustedTeleporters = - (xcm_builder::Case, xcm_builder::Case); - -match_type! { - pub type OnlyParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(_)) } - }; -} - -/// The barriers one of which must be passed for an XCM message to be executed. -pub type Barrier = ( - // Weight that is paid for may be consumed. - TakeWeightCredit, - // If the message is one that immediately attemps to pay for execution, then allow it. - AllowTopLevelPaidExecutionFrom, - // Messages coming from system parachains need not pay for execution. - AllowUnpaidExecutionFrom>, - // Expected responses are OK. - AllowKnownQueryResponses, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, -); - -pub struct XcmConfig; -impl xcm_executor::Config for XcmConfig { - type Call = Call; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = LocalOriginConverter; - type IsReserve = (); - type IsTeleporter = TrustedTeleporters; - type LocationInverter = LocationInverter; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - // The weight trader piggybacks on the existing transaction-fee conversion logic. - type Trader = UsingComponents>; - type ResponseHandler = XcmPallet; - type AssetTrap = XcmPallet; - type AssetClaims = XcmPallet; - type SubscriptionService = XcmPallet; -} - -parameter_types! { - pub const CouncilBodyId: BodyId = BodyId::Executive; -} - -/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location -/// of this chain. -pub type LocalOriginToLocation = ( - // We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality of the - // `Unit` body. - BackingToPlurality< - Origin, - pallet_collective::Origin, - CouncilBodyId, - >, - // And a usual Signed origin to be used in XCM as a corresponding AccountId32 - SignedToAccountId32, -); -impl pallet_xcm::Config for Runtime { - type Event = Event; - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmRouter = XcmRouter; - // Anyone can execute XCM messages locally... - type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; - // ...but they must match our filter, which rejects all. - type XcmExecuteFilter = Nothing; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Everything; - type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; - type LocationInverter = LocationInverter; - type Origin = Origin; - type Call = Call; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; -} - parameter_types! { pub IgnoredIssuance: Balance = Treasury::pot(); pub const QueueCount: u32 = 300; diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs new file mode 100644 index 0000000000..d01044359e --- /dev/null +++ b/polkadot/runtime/kusama/src/xcm_config.rs @@ -0,0 +1,187 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! XCM configurations for the Kusama runtime. + +use super::{ + parachains_origin, AccountId, Balances, Call, CouncilCollective, Event, Origin, ParaId, + Runtime, WeightToFee, XcmPallet, +}; +use frame_support::{ + match_type, parameter_types, + traits::{Everything, Nothing}, + weights::Weight, +}; +use runtime_common::{xcm_sender, ToAuthor}; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, BackingToPlurality, + ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, + CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete, + LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, + TakeWeightCredit, UsingComponents, +}; + +parameter_types! { + /// The location of the KSM token, from the context of this chain. Since this token is native to this + /// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to + /// the context". + pub const KsmLocation: MultiLocation = Here.into(); + /// The Kusama network ID. This is named. + pub const KusamaNetwork: NetworkId = NetworkId::Kusama; + /// Our XCM location ancestry - i.e. what, if anything, `Parent` means evaluated in our context. Since + /// Kusama is a top-level relay-chain, there is no ancestry. + pub const Ancestry: MultiLocation = Here.into(); + /// The check account, which holds any native assets that have been teleported out and not back in (yet). + pub CheckAccount: AccountId = XcmPallet::check_account(); +} + +/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine +/// the sovereign account controlled by a location. +pub type SovereignAccountOf = ( + // We can convert a child parachain using the standard `AccountId` conversion. + ChildParachainConvertsVia, + // We can directly alias an `AccountId32` into a local account. + AccountId32Aliases, +); + +/// Our asset transactor. This is what allows us to interest with the runtime facilities from the point of +/// view of XCM-only concepts like `MultiLocation` and `MultiAsset`. +/// +/// Ours is only aware of the Balances pallet, which is mapped to `KsmLocation`. +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // We can convert the MultiLocations with our converter above: + SovereignAccountOf, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We track our teleports in/out to keep total issuance correct. + CheckAccount, +>; + +/// The means that we convert an the XCM message origin location into a local dispatch origin. +type LocalOriginConverter = ( + // A `Signed` origin of the sovereign account that the original location controls. + SovereignSignedViaLocation, + // A child parachain, natively expressed, has the `Parachain` origin. + ChildParachainAsNative, + // The AccountId32 location type can be expressed natively as a `Signed` origin. + SignedAccountId32AsNative, + // A system child parachain, expressed as a Superuser, converts to the `Root` origin. + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + /// The amount of weight an XCM operation takes. This is a safe overestimate. + pub const BaseXcmWeight: Weight = 1_000_000_000; + /// Maximum number of instructions in a single XCM fragment. A sanity check against weight + /// calculations getting too crazy. + pub const MaxInstructions: u32 = 100; +} + +/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our +/// individual routers. +pub type XcmRouter = ( + // Only one router so far - use DMP to communicate with child parachains. + xcm_sender::ChildParachainRouter, +); + +parameter_types! { + pub const Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(KsmLocation::get()) }); + pub const KusamaForStatemine: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Parachain(1000).into()); + pub const KusamaForEncointer: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Parachain(1001).into()); +} +pub type TrustedTeleporters = + (xcm_builder::Case, xcm_builder::Case); + +match_type! { + pub type OnlyParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(_)) } + }; +} + +/// The barriers one of which must be passed for an XCM message to be executed. +pub type Barrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Messages coming from system parachains need not pay for execution. + AllowUnpaidExecutionFrom>, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, +); + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type Call = Call; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + // The weight trader piggybacks on the existing transaction-fee conversion logic. + type Trader = UsingComponents>; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; +} + +parameter_types! { + pub const CouncilBodyId: BodyId = BodyId::Executive; +} + +/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location +/// of this chain. +pub type LocalOriginToLocation = ( + // We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality of the + // `Unit` body. + BackingToPlurality< + Origin, + pallet_collective::Origin, + CouncilBodyId, + >, + // And a usual Signed origin to be used in XCM as a corresponding AccountId32 + SignedToAccountId32, +); +impl pallet_xcm::Config for Runtime { + type Event = Event; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + // ...but they must match our filter, which rejects all. + type XcmExecuteFilter = Nothing; + type XcmExecutor = xcm_executor::XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type LocationInverter = LocationInverter; + type Origin = Origin; + type Call = Call; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +} diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index c2ffc56252..6a296df0df 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -22,9 +22,9 @@ use pallet_transaction_payment::CurrencyAdapter; use runtime_common::{ - auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, xcm_sender, - BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit, - OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, ToAuthor, + auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, BlockHashCount, + BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit, + OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, }; use runtime_parachains::{ @@ -39,10 +39,10 @@ use runtime_parachains::{ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::crypto::AuthorityId as BeefyId; use frame_support::{ - construct_runtime, match_type, parameter_types, + construct_runtime, parameter_types, traits::{ - Contains, EnsureOneOf, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, - Nothing, OnRuntimeUpgrade, PrivilegeCmp, + Contains, EnsureOneOf, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, + OnRuntimeUpgrade, PrivilegeCmp, }, weights::Weight, PalletId, RuntimeDebug, @@ -85,15 +85,6 @@ use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*}; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, BackingToPlurality, ChildParachainAsNative, - ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, - IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, -}; -use xcm_executor::XcmExecutor; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; @@ -111,6 +102,8 @@ mod weights; mod bag_thresholds; +mod xcm_config; + // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -1310,154 +1303,6 @@ impl auctions::Config for Runtime { type WeightInfo = weights::runtime_common_auctions::WeightInfo; } -parameter_types! { - /// The location of the DOT token, from the context of this chain. Since this token is native to this - /// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to - /// the context". - pub const DotLocation: MultiLocation = Here.into(); - /// The Polkadot network ID. This is named. - pub const PolkadotNetwork: NetworkId = NetworkId::Polkadot; - /// Our XCM location ancestry - i.e. what, if anything, `Parent` means evaluated in our context. Since - /// Polkadot is a top-level relay-chain, there is no ancestry. - pub const Ancestry: MultiLocation = Here.into(); - /// The check account, which holds any native assets that have been teleported out and not back in (yet). - pub CheckAccount: AccountId = XcmPallet::check_account(); -} - -/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine -/// the sovereign account controlled by a location. -pub type SovereignAccountOf = ( - // We can convert a child parachain using the standard `AccountId` conversion. - ChildParachainConvertsVia, - // We can directly alias an `AccountId32` into a local account. - AccountId32Aliases, -); - -/// Our asset transactor. This is what allows us to interest with the runtime facilities from the point of -/// view of XCM-only concepts like `MultiLocation` and `MultiAsset`. -/// -/// Ours is only aware of the Balances pallet, which is mapped to `DotLocation`. -pub type LocalAssetTransactor = XcmCurrencyAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // We can convert the MultiLocations with our converter above: - SovereignAccountOf, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // We track our teleports in/out to keep total issuance correct. - CheckAccount, ->; - -/// The means that we convert an the XCM message origin location into a local dispatch origin. -type LocalOriginConverter = ( - // A `Signed` origin of the sovereign account that the original location controls. - SovereignSignedViaLocation, - // A child parachain, natively expressed, has the `Parachain` origin. - ChildParachainAsNative, - // The AccountId32 location type can be expressed natively as a `Signed` origin. - SignedAccountId32AsNative, -); - -parameter_types! { - /// The amount of weight an XCM operation takes. This is a safe overestimate. - pub const BaseXcmWeight: Weight = 1_000_000_000; - /// Maximum number of instructions in a single XCM fragment. A sanity check against weight - /// calculations getting too crazy. - pub const MaxInstructions: u32 = 100; -} - -/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our -/// individual routers. -pub type XcmRouter = ( - // Only one router so far - use DMP to communicate with child parachains. - xcm_sender::ChildParachainRouter, -); - -parameter_types! { - pub const Polkadot: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(DotLocation::get()) }); - pub const PolkadotForStatemint: (MultiAssetFilter, MultiLocation) = (Polkadot::get(), Parachain(1000).into()); -} - -pub type TrustedTeleporters = (xcm_builder::Case,); - -match_type! { - pub type OnlyParachains: impl Contains = { - MultiLocation { parents: 0, interior: X1(Parachain(_)) } - }; -} - -/// The barriers one of which must be passed for an XCM message to be executed. -pub type Barrier = ( - // Weight that is paid for may be consumed. - TakeWeightCredit, - // If the message is one that immediately attemps to pay for execution, then allow it. - AllowTopLevelPaidExecutionFrom, - // Expected responses are OK. - AllowKnownQueryResponses, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, -); - -pub struct XcmConfig; -impl xcm_executor::Config for XcmConfig { - type Call = Call; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = LocalOriginConverter; - type IsReserve = (); - type IsTeleporter = TrustedTeleporters; - type LocationInverter = LocationInverter; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - // The weight trader piggybacks on the existing transaction-fee conversion logic. - type Trader = UsingComponents>; - type ResponseHandler = XcmPallet; - type AssetTrap = XcmPallet; - type AssetClaims = XcmPallet; - type SubscriptionService = XcmPallet; -} - -parameter_types! { - pub const CouncilBodyId: BodyId = BodyId::Executive; - // We are conservative with the XCM version we advertize. - pub const AdvertisedXcmVersion: u32 = 2; -} - -/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location -/// of this chain. -pub type LocalOriginToLocation = ( - // We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality of the - // `Unit` body. - BackingToPlurality< - Origin, - pallet_collective::Origin, - CouncilBodyId, - >, - // And a usual Signed origin to be used in XCM as a corresponding AccountId32 - SignedToAccountId32, -); - -impl pallet_xcm::Config for Runtime { - type Event = Event; - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmRouter = XcmRouter; - // Anyone can execute XCM messages locally... - type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; - // ...but they must match our filter, which rejects all. - type XcmExecuteFilter = Nothing; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Nothing; - type XcmReserveTransferFilter = Nothing; - type Weigher = FixedWeightBounds; - type LocationInverter = LocationInverter; - type Origin = Origin; - type Call = Call; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = AdvertisedXcmVersion; -} - construct_runtime! { pub enum Runtime where Block = Block, diff --git a/polkadot/runtime/polkadot/src/xcm_config.rs b/polkadot/runtime/polkadot/src/xcm_config.rs new file mode 100644 index 0000000000..e3816ab977 --- /dev/null +++ b/polkadot/runtime/polkadot/src/xcm_config.rs @@ -0,0 +1,184 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! XCM configuration for Polkadot. + +use super::{ + parachains_origin, AccountId, Balances, Call, CouncilCollective, Event, Origin, ParaId, + Runtime, WeightToFee, XcmPallet, +}; +use frame_support::{ + match_type, parameter_types, + traits::{Everything, Nothing}, + weights::Weight, +}; +use runtime_common::{xcm_sender, ToAuthor}; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, BackingToPlurality, ChildParachainAsNative, + ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, + IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, +}; + +parameter_types! { + /// The location of the DOT token, from the context of this chain. Since this token is native to this + /// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to + /// the context". + pub const DotLocation: MultiLocation = Here.into(); + /// The Polkadot network ID. This is named. + pub const PolkadotNetwork: NetworkId = NetworkId::Polkadot; + /// Our XCM location ancestry - i.e. what, if anything, `Parent` means evaluated in our context. Since + /// Polkadot is a top-level relay-chain, there is no ancestry. + pub const Ancestry: MultiLocation = Here.into(); + /// The check account, which holds any native assets that have been teleported out and not back in (yet). + pub CheckAccount: AccountId = XcmPallet::check_account(); +} + +/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine +/// the sovereign account controlled by a location. +pub type SovereignAccountOf = ( + // We can convert a child parachain using the standard `AccountId` conversion. + ChildParachainConvertsVia, + // We can directly alias an `AccountId32` into a local account. + AccountId32Aliases, +); + +/// Our asset transactor. This is what allows us to interest with the runtime facilities from the point of +/// view of XCM-only concepts like `MultiLocation` and `MultiAsset`. +/// +/// Ours is only aware of the Balances pallet, which is mapped to `DotLocation`. +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // We can convert the MultiLocations with our converter above: + SovereignAccountOf, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We track our teleports in/out to keep total issuance correct. + CheckAccount, +>; + +/// The means that we convert an the XCM message origin location into a local dispatch origin. +type LocalOriginConverter = ( + // A `Signed` origin of the sovereign account that the original location controls. + SovereignSignedViaLocation, + // A child parachain, natively expressed, has the `Parachain` origin. + ChildParachainAsNative, + // The AccountId32 location type can be expressed natively as a `Signed` origin. + SignedAccountId32AsNative, +); + +parameter_types! { + /// The amount of weight an XCM operation takes. This is a safe overestimate. + pub const BaseXcmWeight: Weight = 1_000_000_000; + /// Maximum number of instructions in a single XCM fragment. A sanity check against weight + /// calculations getting too crazy. + pub const MaxInstructions: u32 = 100; +} + +/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our +/// individual routers. +pub type XcmRouter = ( + // Only one router so far - use DMP to communicate with child parachains. + xcm_sender::ChildParachainRouter, +); + +parameter_types! { + pub const Polkadot: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(DotLocation::get()) }); + pub const PolkadotForStatemint: (MultiAssetFilter, MultiLocation) = (Polkadot::get(), Parachain(1000).into()); +} + +pub type TrustedTeleporters = (xcm_builder::Case,); + +match_type! { + pub type OnlyParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(_)) } + }; +} + +/// The barriers one of which must be passed for an XCM message to be executed. +pub type Barrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, +); + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type Call = Call; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + // The weight trader piggybacks on the existing transaction-fee conversion logic. + type Trader = UsingComponents>; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; +} + +parameter_types! { + pub const CouncilBodyId: BodyId = BodyId::Executive; + // We are conservative with the XCM version we advertize. + pub const AdvertisedXcmVersion: u32 = 2; +} + +/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location +/// of this chain. +pub type LocalOriginToLocation = ( + // We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality of the + // `Unit` body. + BackingToPlurality< + Origin, + pallet_collective::Origin, + CouncilBodyId, + >, + // And a usual Signed origin to be used in XCM as a corresponding AccountId32 + SignedToAccountId32, +); + +impl pallet_xcm::Config for Runtime { + type Event = Event; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + // ...but they must match our filter, which rejects all. + type XcmExecuteFilter = Nothing; + type XcmExecutor = xcm_executor::XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Nothing; + type Weigher = FixedWeightBounds; + type LocationInverter = LocationInverter; + type Origin = Origin; + type Call = Call; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = AdvertisedXcmVersion; +} diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 502060a11d..8208fa548e 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -24,8 +24,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion}; use frame_support::{ construct_runtime, parameter_types, - traits::{Contains, Everything, IsInVec, KeyOwnerProofSystem, Nothing, Randomness}, - weights::Weight, + traits::{Contains, KeyOwnerProofSystem, Randomness}, PalletId, }; use frame_system::EnsureRoot; @@ -46,8 +45,7 @@ use primitives::{ }; use runtime_common::{ assigned_slots, auctions, crowdloan, impls::ToAuthor, paras_registrar, paras_sudo_wrapper, - slots, xcm_sender, BlockHashCount, BlockLength, BlockWeights, RocksDbWeight, - SlowAdjustingFeeUpdate, + slots, BlockHashCount, BlockLength, BlockWeights, RocksDbWeight, SlowAdjustingFeeUpdate, }; use runtime_parachains::{self, runtime_api_impl::v1 as runtime_api_impl}; use scale_info::TypeInfo; @@ -87,18 +85,11 @@ use polkadot_parachain::primitives::Id as ParaId; use rococo_runtime_constants::{currency::*, fee::*, time::*}; use frame_support::traits::{InstanceFilter, OnRuntimeUpgrade}; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, BackingToPlurality, - ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, - CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, -}; -use xcm_executor::XcmExecutor; mod bridge_messages; mod validator_manager; mod weights; +mod xcm_config; // Make the WASM binary available. #[cfg(feature = "std")] @@ -634,140 +625,6 @@ impl parachains_paras::Config for Runtime { type NextSessionRotation = Babe; } -parameter_types! { - pub const RocLocation: MultiLocation = Here.into(); - pub const RococoNetwork: NetworkId = NetworkId::Polkadot; - pub const Ancestry: MultiLocation = Here.into(); - pub CheckAccount: AccountId = XcmPallet::check_account(); -} - -pub type SovereignAccountOf = - (ChildParachainConvertsVia, AccountId32Aliases); - -pub type LocalAssetTransactor = XcmCurrencyAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // We can convert the MultiLocations with our converter above: - SovereignAccountOf, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // It's a native asset so we keep track of the teleports to maintain total issuance. - CheckAccount, ->; - -type LocalOriginConverter = ( - SovereignSignedViaLocation, - ChildParachainAsNative, - SignedAccountId32AsNative, - ChildSystemParachainAsSuperuser, -); - -parameter_types! { - pub const BaseXcmWeight: Weight = 1_000_000_000; -} - -/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our -/// individual routers. -pub type XcmRouter = ( - // Only one router so far - use DMP to communicate with child parachains. - xcm_sender::ChildParachainRouter, -); - -parameter_types! { - pub const Rococo: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) }); - pub const RococoForTick: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(100).into()); - pub const RococoForTrick: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(110).into()); - pub const RococoForTrack: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(120).into()); - pub const RococoForStatemine: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(1000).into()); - pub const RococoForCanvas: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(1002).into()); - pub const RococoForEncointer: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(1003).into()); - pub const MaxInstructions: u32 = 100; -} -pub type TrustedTeleporters = ( - xcm_builder::Case, - xcm_builder::Case, - xcm_builder::Case, - xcm_builder::Case, - xcm_builder::Case, - xcm_builder::Case, -); - -parameter_types! { - pub AllowUnpaidFrom: Vec = - vec![ - Parachain(100).into(), - Parachain(110).into(), - Parachain(120).into(), - Parachain(1000).into(), - Parachain(1002).into(), - Parachain(1003).into(), - ]; -} - -use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit}; -pub type Barrier = ( - TakeWeightCredit, - AllowTopLevelPaidExecutionFrom, - AllowUnpaidExecutionFrom>, // <- Trusted parachains get free execution - // Expected responses are OK. - AllowKnownQueryResponses, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, -); - -pub struct XcmConfig; -impl xcm_executor::Config for XcmConfig { - type Call = Call; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = LocalOriginConverter; - type IsReserve = (); - type IsTeleporter = TrustedTeleporters; - type LocationInverter = LocationInverter; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = UsingComponents>; - type ResponseHandler = XcmPallet; - type AssetTrap = XcmPallet; - type AssetClaims = XcmPallet; - type SubscriptionService = XcmPallet; -} - -parameter_types! { - pub const CollectiveBodyId: BodyId = BodyId::Unit; -} - -/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location -/// of this chain. -pub type LocalOriginToLocation = ( - // We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality of the - // `Unit` body. - BackingToPlurality, CollectiveBodyId>, - // And a usual Signed origin to be used in XCM as a corresponding AccountId32 - SignedToAccountId32, -); - -impl pallet_xcm::Config for Runtime { - type Event = Event; - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmRouter = XcmRouter; - // Anyone can execute XCM messages locally... - type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; - // ...but they must match our filter, which right now rejects everything. - type XcmExecuteFilter = Nothing; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Everything; - type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; - type LocationInverter = LocationInverter; - type Origin = Origin; - type Call = Call; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; -} - impl parachains_session_info::Config for Runtime {} parameter_types! { @@ -776,7 +633,8 @@ parameter_types! { impl parachains_ump::Config for Runtime { type Event = Event; - type UmpSink = crate::parachains_ump::XcmSink, Runtime>; + type UmpSink = + crate::parachains_ump::XcmSink, Runtime>; type FirstMessageFactorPercent = FirstMessageFactorPercent; type ExecuteOverweightOrigin = EnsureRoot; } diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs new file mode 100644 index 0000000000..1512ef9e6c --- /dev/null +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -0,0 +1,170 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! XCM configuration for Rococo. + +use super::{ + parachains_origin, AccountId, Balances, Call, Event, Origin, ParaId, Runtime, WeightToFee, + XcmPallet, +}; +use frame_support::{ + parameter_types, + traits::{Everything, IsInVec, Nothing}, + weights::Weight, +}; +use runtime_common::{xcm_sender, ToAuthor}; +use sp_std::prelude::*; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, BackingToPlurality, + ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, + CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, +}; + +parameter_types! { + pub const RocLocation: MultiLocation = Here.into(); + pub const RococoNetwork: NetworkId = NetworkId::Polkadot; + pub const Ancestry: MultiLocation = Here.into(); + pub CheckAccount: AccountId = XcmPallet::check_account(); +} + +pub type SovereignAccountOf = + (ChildParachainConvertsVia, AccountId32Aliases); + +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // We can convert the MultiLocations with our converter above: + SovereignAccountOf, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // It's a native asset so we keep track of the teleports to maintain total issuance. + CheckAccount, +>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = 1_000_000_000; +} + +/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our +/// individual routers. +pub type XcmRouter = ( + // Only one router so far - use DMP to communicate with child parachains. + xcm_sender::ChildParachainRouter, +); + +parameter_types! { + pub const Rococo: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) }); + pub const RococoForTick: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(100).into()); + pub const RococoForTrick: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(110).into()); + pub const RococoForTrack: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(120).into()); + pub const RococoForStatemine: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(1000).into()); + pub const RococoForCanvas: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(1002).into()); + pub const RococoForEncointer: (MultiAssetFilter, MultiLocation) = (Rococo::get(), Parachain(1003).into()); + pub const MaxInstructions: u32 = 100; +} +pub type TrustedTeleporters = ( + xcm_builder::Case, + xcm_builder::Case, + xcm_builder::Case, + xcm_builder::Case, + xcm_builder::Case, + xcm_builder::Case, +); + +parameter_types! { + pub AllowUnpaidFrom: Vec = + vec![ + Parachain(100).into(), + Parachain(110).into(), + Parachain(120).into(), + Parachain(1000).into(), + Parachain(1002).into(), + Parachain(1003).into(), + ]; +} + +use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit}; +pub type Barrier = ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + AllowUnpaidExecutionFrom>, // <- Trusted parachains get free execution + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, +); + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type Call = Call; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = UsingComponents>; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; +} + +parameter_types! { + pub const CollectiveBodyId: BodyId = BodyId::Unit; +} + +/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location +/// of this chain. +pub type LocalOriginToLocation = ( + // We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality of the + // `Unit` body. + BackingToPlurality, CollectiveBodyId>, + // And a usual Signed origin to be used in XCM as a corresponding AccountId32 + SignedToAccountId32, +); + +impl pallet_xcm::Config for Runtime { + type Event = Event; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + // ...but they must match our filter, which right now rejects everything. + type XcmExecuteFilter = Nothing; + type XcmExecutor = xcm_executor::XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type LocationInverter = LocationInverter; + type Origin = Origin; + type Call = Call; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +} diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 6d4fe4d615..f7d1cb7d1f 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -34,9 +34,8 @@ use primitives::{ }; use runtime_common::{ assigned_slots, auctions, crowdloan, impls::ToAuthor, paras_registrar, paras_sudo_wrapper, - slots, xcm_sender, BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, - OffchainSolutionLengthLimit, OffchainSolutionWeightLimit, RocksDbWeight, - SlowAdjustingFeeUpdate, + slots, BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit, + OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, }; use sp_std::{collections::btree_map::BTreeMap, prelude::*}; @@ -49,24 +48,11 @@ use runtime_parachains::{ session_info as parachains_session_info, shared as parachains_shared, ump as parachains_ump, }; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ChildParachainAsNative, - ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, - CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, LocationInverter, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - UsingComponents, WeightInfoBounds, -}; -use xcm_executor::XcmExecutor; - use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::crypto::AuthorityId as BeefyId; use frame_support::{ construct_runtime, parameter_types, - traits::{ - Contains, Everything, InstanceFilter, KeyOwnerProofSystem, Nothing, OnRuntimeUpgrade, - }, + traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade}, weights::Weight, PalletId, RuntimeDebug, }; @@ -110,6 +96,9 @@ mod weights; // Voter bag threshold definitions. mod bag_thresholds; +// XCM configurations. +mod xcm_config; + #[cfg(test)] mod tests; @@ -864,7 +853,8 @@ parameter_types! { impl parachains_ump::Config for Runtime { type Event = Event; - type UmpSink = crate::parachains_ump::XcmSink, Runtime>; + type UmpSink = + crate::parachains_ump::XcmSink, Runtime>; type FirstMessageFactorPercent = FirstMessageFactorPercent; type ExecuteOverweightOrigin = EnsureRoot; } @@ -979,113 +969,6 @@ impl auctions::Config for Runtime { type WeightInfo = weights::runtime_common_auctions::WeightInfo; } -parameter_types! { - pub const WndLocation: MultiLocation = Here.into(); - pub const Ancestry: MultiLocation = Here.into(); - pub WestendNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec()); - pub CheckAccount: AccountId = XcmPallet::check_account(); -} - -pub type LocationConverter = - (ChildParachainConvertsVia, AccountId32Aliases); - -pub type LocalAssetTransactor = XcmCurrencyAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // We can convert the MultiLocations with our converter above: - LocationConverter, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // It's a native asset so we keep track of the teleports to maintain total issuance. - CheckAccount, ->; - -type LocalOriginConverter = ( - SovereignSignedViaLocation, - ChildParachainAsNative, - SignedAccountId32AsNative, - ChildSystemParachainAsSuperuser, -); - -/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our -/// individual routers. -pub type XcmRouter = ( - // Only one router so far - use DMP to communicate with child parachains. - xcm_sender::ChildParachainRouter, -); - -parameter_types! { - pub const Westmint: MultiLocation = Parachain(1000).into(); - pub const Encointer: MultiLocation = Parachain(1001).into(); - pub const WestendForWestmint: (MultiAssetFilter, MultiLocation) = - (Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Westmint::get()); - pub const WestendForEncointer: (MultiAssetFilter, MultiLocation) = - (Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Encointer::get()); - pub const MaxInstructions: u32 = 100; -} -pub type TrustedTeleporters = - (xcm_builder::Case, xcm_builder::Case); - -/// The barriers one of which must be passed for an XCM message to be executed. -pub type Barrier = ( - // Weight that is paid for may be consumed. - TakeWeightCredit, - // If the message is one that immediately attemps to pay for execution, then allow it. - AllowTopLevelPaidExecutionFrom, - // Messages coming from system parachains need not pay for execution. - AllowUnpaidExecutionFrom>, - // Expected responses are OK. - AllowKnownQueryResponses, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, -); - -pub struct XcmConfig; -impl xcm_executor::Config for XcmConfig { - type Call = Call; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = LocalOriginConverter; - type IsReserve = (); - type IsTeleporter = TrustedTeleporters; - type LocationInverter = LocationInverter; - type Barrier = Barrier; - type Weigher = WeightInfoBounds, Call, MaxInstructions>; - type Trader = UsingComponents>; - type ResponseHandler = XcmPallet; - type AssetTrap = XcmPallet; - type AssetClaims = XcmPallet; - type SubscriptionService = XcmPallet; -} - -/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location -/// of this chain. -pub type LocalOriginToLocation = ( - // And a usual Signed origin to be used in XCM as a corresponding AccountId32 - SignedToAccountId32, -); - -impl pallet_xcm::Config for Runtime { - type Event = Event; - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmRouter = XcmRouter; - // Anyone can execute XCM messages locally... - type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; - // ...but they must match our filter, which rejects everything. - type XcmExecuteFilter = Nothing; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Everything; - type XcmReserveTransferFilter = Everything; - type Weigher = WeightInfoBounds, Call, MaxInstructions>; - type LocationInverter = LocationInverter; - type Origin = Origin; - type Call = Call; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; -} - construct_runtime! { pub enum Runtime where Block = Block, @@ -1653,11 +1536,15 @@ sp_api::impl_runtime_apis! { impl pallet_offences_benchmarking::Config for Runtime {} impl frame_system_benchmarking::Config for Runtime {} - use xcm::latest::MultiAsset; + use xcm::latest::{ + AssetId::*, Fungibility::*, Junctions::*, MultiAsset, MultiAssets, MultiLocation, + Response, + }; + use xcm_config::{Westmint, WndLocation}; impl pallet_xcm_benchmarks::Config for Runtime { - type XcmConfig = XcmConfig; - type AccountIdConverter = LocationConverter; + type XcmConfig = xcm_config::XcmConfig; + type AccountIdConverter = xcm_config::LocationConverter; fn valid_destination() -> Result { Ok(Westmint::get()) } @@ -1680,7 +1567,7 @@ sp_api::impl_runtime_apis! { impl pallet_xcm_benchmarks::fungible::Config for Runtime { type TransactAsset = Balances; - type CheckedAccount = CheckAccount; + type CheckedAccount = xcm_config::CheckAccount; type TrustedTeleporter = TrustedTeleporter; fn get_multi_asset() -> MultiAsset { diff --git a/polkadot/runtime/westend/src/tests.rs b/polkadot/runtime/westend/src/tests.rs index 841089f93e..f0ab4f44e6 100644 --- a/polkadot/runtime/westend/src/tests.rs +++ b/polkadot/runtime/westend/src/tests.rs @@ -17,6 +17,7 @@ //! Tests for the Westend Runtime Configuration use crate::*; +use xcm::latest::{AssetId::*, Fungibility::*, MultiLocation}; #[test] fn remove_keys_weight_is_sensible() { diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs new file mode 100644 index 0000000000..cbe0ed31f5 --- /dev/null +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -0,0 +1,143 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! XCM configurations for Westend. + +use super::{ + parachains_origin, weights, AccountId, Balances, Call, Event, Origin, ParaId, Runtime, + WeightToFee, XcmPallet, +}; +use frame_support::{ + parameter_types, + traits::{Everything, Nothing}, +}; +use runtime_common::{xcm_sender, ToAuthor}; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ChildParachainAsNative, + ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, + CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, LocationInverter, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + UsingComponents, WeightInfoBounds, +}; + +parameter_types! { + pub const WndLocation: MultiLocation = Here.into(); + pub const Ancestry: MultiLocation = Here.into(); + pub WestendNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec()); + pub CheckAccount: AccountId = XcmPallet::check_account(); +} + +pub type LocationConverter = + (ChildParachainConvertsVia, AccountId32Aliases); + +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // We can convert the MultiLocations with our converter above: + LocationConverter, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // It's a native asset so we keep track of the teleports to maintain total issuance. + CheckAccount, +>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our +/// individual routers. +pub type XcmRouter = ( + // Only one router so far - use DMP to communicate with child parachains. + xcm_sender::ChildParachainRouter, +); + +parameter_types! { + pub const Westmint: MultiLocation = Parachain(1000).into(); + pub const Encointer: MultiLocation = Parachain(1001).into(); + pub const WestendForWestmint: (MultiAssetFilter, MultiLocation) = + (Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Westmint::get()); + pub const WestendForEncointer: (MultiAssetFilter, MultiLocation) = + (Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Encointer::get()); + pub const MaxInstructions: u32 = 100; +} +pub type TrustedTeleporters = + (xcm_builder::Case, xcm_builder::Case); + +/// The barriers one of which must be passed for an XCM message to be executed. +pub type Barrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Messages coming from system parachains need not pay for execution. + AllowUnpaidExecutionFrom>, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, +); + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type Call = Call; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = WeightInfoBounds, Call, MaxInstructions>; + type Trader = UsingComponents>; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; +} + +/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location +/// of this chain. +pub type LocalOriginToLocation = ( + // And a usual Signed origin to be used in XCM as a corresponding AccountId32 + SignedToAccountId32, +); + +impl pallet_xcm::Config for Runtime { + type Event = Event; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + // ...but they must match our filter, which rejects everything. + type XcmExecuteFilter = Nothing; + type XcmExecutor = xcm_executor::XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = WeightInfoBounds, Call, MaxInstructions>; + type LocationInverter = LocationInverter; + type Origin = Origin; + type Call = Call; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +}