git.delta.rocks / unique-network / refs/commits / 15ea50e38a6d

difftreelog

source

runtime/common/config/xcm.rs10.8 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};18use frame_support::{19	parameter_types,20	traits::{21		ConstU32, EnqueueWithOrigin, Everything, Get, Nothing, ProcessMessageError, TransformOrigin,22	},23};24use frame_system::EnsureRoot;25use orml_traits::location::AbsoluteReserveProvider;26use orml_xcm_support::MultiNativeAsset;27use pallet_foreign_assets::FreeForAll;28use pallet_xcm::XcmPassthrough;29use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};30use polkadot_parachain_primitives::primitives::Sibling;31use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;32use sp_std::marker::PhantomData;33use staging_xcm::latest::prelude::*;34use staging_xcm_builder::{35	AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor,36	ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,37	SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,38};39use staging_xcm_executor::{40	traits::{Properties, ShouldExecute},41	XcmExecutor,42};43use up_common::{constants::MAXIMUM_BLOCK_WEIGHT, types::AccountId};4445#[cfg(feature = "governance")]46use crate::runtime_common::config::governance;47use crate::{48	runtime_common::config::parachain::RelayMsgOrigin, xcm_barrier::Barrier, AllPalletsWithSystem,49	Balances, ForeignAssets, MessageQueue, ParachainInfo, ParachainSystem, PolkadotXcm,50	RelayNetwork, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue,51};5253parameter_types! {54	pub const RelayLocation: Location = Location::parent();55	pub RelayOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();56	pub UniversalLocation: InteriorLocation = (57		GlobalConsensus(crate::RelayNetwork::get()),58		Parachain(ParachainInfo::get().into()),59	).into();60	pub SelfLocation: Location = Location::new(1, Parachain(ParachainInfo::get().into()));6162	// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.63	pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1000); // ?64	pub const MaxInstructions: u32 = 100;65	pub const MessageQueueServiceWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); // TODO66}6768/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used69/// when determining ownership of accounts for asset transacting and when attempting to use XCM70/// `Transact` in order to determine the dispatch Origin.71pub type LocationToAccountId = (72	// The parent (Relay-chain) origin converts to the default `AccountId`.73	ParentIsPreset<AccountId>,74	// Sibling parachain origins convert to AccountId via the `ParaId::into`.75	SiblingParachainConvertsVia<Sibling, AccountId>,76	// Straight up local `AccountId32` origins just alias directly to `AccountId`.77	AccountId32Aliases<RelayNetwork, AccountId>,78);7980/// No local origins on this chain are allowed to dispatch XCM sends/executions.81pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);8283/// The means for routing XCM messages which are not for local execution into the right message84/// queues.85pub type XcmRouter = (86	// Two routers - use UMP to communicate with the relay chain:87	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,88	// ..and XCMP to communicate with the sibling chains.89	XcmpQueue,90);9192/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,93/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can94/// biases the kind of local `Origin` it will become.95pub type XcmOriginToTransactDispatchOrigin = (96	// Sovereign account converter; this attempts to derive an `AccountId` from the origin location97	// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for98	// foreign chains who want to have a local sovereign account on this chain which they control.99	SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,100	// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when101	// recognised.102	RelayChainAsNative<RelayOrigin, RuntimeOrigin>,103	// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when104	// recognised.105	SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,106	// Native signed account converter; this just converts an `AccountId32` origin into a normal107	// `Origin::Signed` origin of the same 32-byte value.108	SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,109	// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.110	XcmPassthrough<RuntimeOrigin>,111);112113pub trait TryPass {114	fn try_pass<Call>(115		origin: &Location,116		message: &mut [Instruction<Call>],117	) -> Result<(), ProcessMessageError>;118}119120#[impl_trait_for_tuples::impl_for_tuples(30)]121impl TryPass for Tuple {122	fn try_pass<Call>(123		origin: &Location,124		message: &mut [Instruction<Call>],125	) -> Result<(), ProcessMessageError> {126		for_tuples!( #(127			Tuple::try_pass(origin, message)?;128		)* );129130		Ok(())131	}132}133134/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.135/// If it passes the Deny, and matches one of the Allow cases then it is let through.136pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)137where138	Deny: TryPass,139	Allow: ShouldExecute;140141impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>142where143	Deny: TryPass,144	Allow: ShouldExecute,145{146	fn should_execute<Call>(147		origin: &Location,148		message: &mut [Instruction<Call>],149		max_weight: Weight,150		properties: &mut Properties,151	) -> Result<(), ProcessMessageError> {152		Deny::try_pass(origin, message)?;153		Allow::should_execute(origin, message, max_weight, properties)154	}155}156157pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;158159pub type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;160161pub type Trader = FreeForAll;162163pub struct XcmExecutorConfig<T>(PhantomData<T>);164impl<T> staging_xcm_executor::Config for XcmExecutorConfig<T>165where166	T: pallet_configuration::Config,167{168	type RuntimeCall = RuntimeCall;169	type XcmSender = XcmRouter;170	// How to withdraw and deposit an asset.171	type AssetTransactor = ForeignAssets;172	type OriginConverter = XcmOriginToTransactDispatchOrigin;173	type IsReserve = IsReserve;174	type IsTeleporter = (); // Teleportation is disabled175	type UniversalLocation = UniversalLocation;176	type Barrier = Barrier;177	type Weigher = Weigher;178	type Trader = Trader;179	type ResponseHandler = PolkadotXcm;180	type SubscriptionService = PolkadotXcm;181	type PalletInstancesInfo = AllPalletsWithSystem;182	type MaxAssetsIntoHolding = ConstU32<8>;183184	type AssetTrap = PolkadotXcm;185	type AssetClaims = PolkadotXcm;186	type AssetLocker = ();187	type AssetExchanger = ();188	type FeeManager = ();189	type MessageExporter = ();190	type UniversalAliases = Nothing;191	type CallDispatcher = RuntimeCall;192	type SafeCallFilter = Nothing;193	type Aliasers = Nothing;194	type TransactionalProcessor = FrameTransactionalProcessor;195}196197impl pallet_xcm::Config for Runtime {198	type RuntimeEvent = RuntimeEvent;199	type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;200	type XcmRouter = XcmRouter;201	type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;202	type XcmExecuteFilter = Everything;203	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;204	type XcmTeleportFilter = Everything;205	type XcmReserveTransferFilter = Everything;206	type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;207	type RuntimeOrigin = RuntimeOrigin;208	type RuntimeCall = RuntimeCall;209	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;210	type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;211	type UniversalLocation = UniversalLocation;212	type Currency = Balances;213	type CurrencyMatcher = ();214	type TrustedLockers = ();215	type SovereignAccountOf = LocationToAccountId;216	type MaxLockers = ConstU32<8>;217	type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;218	type AdminOrigin = EnsureRoot<AccountId>;219	type MaxRemoteLockConsumers = ConstU32<0>;220	type RemoteLockConsumerIdentifier = ();221}222223#[cfg(feature = "runtime-benchmarks")]224impl pallet_xcm::benchmarking::Config for Runtime {225	type DeliveryHelper = ();226227	fn reachable_dest() -> Option<Location> {228		Some(Parent.into())229	}230231	fn get_asset() -> Asset {232		(Location::here(), 1_000_000_000_000_000_000u128).into()233	}234}235236impl cumulus_pallet_xcm::Config for Runtime {237	type RuntimeEvent = RuntimeEvent;238	type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;239}240241impl pallet_message_queue::Config for Runtime {242	type RuntimeEvent = RuntimeEvent;243	type WeightInfo = pallet_message_queue::weights::SubstrateWeight<Self>;244245	#[cfg(not(feature = "runtime-benchmarks"))]246	type MessageProcessor = staging_xcm_builder::ProcessXcmMessage<247		AggregateMessageOrigin,248		XcmExecutor<XcmExecutorConfig<Self>>,249		RuntimeCall,250	>;251252	#[cfg(feature = "runtime-benchmarks")]253	type MessageProcessor =254		pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;255256	type Size = u32;257	// The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin:258	type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;259	type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;260	type HeapSize = ConstU32<{ 64 * 1024 }>;261	type MaxStale = ConstU32<8>;262	type ServiceWeight = MessageQueueServiceWeight;263}264265impl cumulus_pallet_xcmp_queue::Config for Runtime {266	type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Self>;267	type RuntimeEvent = RuntimeEvent;268	type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;269	type MaxInboundSuspended = ConstU32<1000>;270271	type ChannelInfo = ParachainSystem;272	type VersionWrapper = PolkadotXcm;273274	#[cfg(feature = "governance")]275	type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;276277	#[cfg(not(feature = "governance"))]278	type ControllerOrigin = frame_system::EnsureRoot<AccountId>;279280	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;281	type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;282}283284impl cumulus_pallet_dmp_queue::Config for Runtime {285	type RuntimeEvent = RuntimeEvent;286	type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight<Self>;287	type DmpSink = EnqueueWithOrigin<MessageQueue, RelayMsgOrigin>;288}