1234567891011121314151617use 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 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); 66}6768697071pub type LocationToAccountId = (72 73 ParentIsPreset<AccountId>,74 75 SiblingParachainConvertsVia<Sibling, AccountId>,76 77 AccountId32Aliases<RelayNetwork, AccountId>,78);798081pub type LocalOriginToLocation = (SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>,);82838485pub type XcmRouter = (86 87 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,88 89 XcmpQueue,90);9192939495pub type XcmOriginToTransactDispatchOrigin = (96 97 98 99 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,100 101 102 RelayChainAsNative<RelayOrigin, RuntimeOrigin>,103 104 105 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,106 107 108 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,109 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}133134135136pub 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 171 type AssetTransactor = ForeignAssets;172 type OriginConverter = XcmOriginToTransactDispatchOrigin;173 type IsReserve = IsReserve;174 type IsTeleporter = (); 175 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}196197#[cfg(feature = "runtime-benchmarks")]198parameter_types! {199 pub ReachableDest: Option<Location> = Some(Parent.into());200}201202impl pallet_xcm::Config for Runtime {203 type RuntimeEvent = RuntimeEvent;204 type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, ()>;205 type XcmRouter = XcmRouter;206 type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;207 type XcmExecuteFilter = Everything;208 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;209 type XcmTeleportFilter = Everything;210 type XcmReserveTransferFilter = Everything;211 type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;212 type RuntimeOrigin = RuntimeOrigin;213 type RuntimeCall = RuntimeCall;214 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;215 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;216 type UniversalLocation = UniversalLocation;217 type Currency = Balances;218 type CurrencyMatcher = ();219 type TrustedLockers = ();220 type SovereignAccountOf = LocationToAccountId;221 type MaxLockers = ConstU32<8>;222 type WeightInfo = crate::weights::xcm::SubstrateWeight<Runtime>;223 type AdminOrigin = EnsureRoot<AccountId>;224 type MaxRemoteLockConsumers = ConstU32<0>;225 type RemoteLockConsumerIdentifier = ();226 #[cfg(feature = "runtime-benchmarks")]227 type ReachableDest = ReachableDest;228}229230impl cumulus_pallet_xcm::Config for Runtime {231 type RuntimeEvent = RuntimeEvent;232 type XcmExecutor = XcmExecutor<XcmExecutorConfig<Self>>;233}234235impl pallet_message_queue::Config for Runtime {236 type RuntimeEvent = RuntimeEvent;237 type WeightInfo = pallet_message_queue::weights::SubstrateWeight<Self>;238239 #[cfg(not(feature = "runtime-benchmarks"))]240 type MessageProcessor = staging_xcm_builder::ProcessXcmMessage<241 AggregateMessageOrigin,242 XcmExecutor<XcmExecutorConfig<Self>>,243 RuntimeCall,244 >;245246 #[cfg(feature = "runtime-benchmarks")]247 type MessageProcessor =248 pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;249250 type Size = u32;251 252 type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;253 type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;254 type HeapSize = ConstU32<{ 64 * 1024 }>;255 type MaxStale = ConstU32<8>;256 type ServiceWeight = MessageQueueServiceWeight;257}258259impl cumulus_pallet_xcmp_queue::Config for Runtime {260 type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Self>;261 type RuntimeEvent = RuntimeEvent;262 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;263 type MaxInboundSuspended = ConstU32<1000>;264265 type ChannelInfo = ParachainSystem;266 type VersionWrapper = PolkadotXcm;267268 #[cfg(feature = "governance")]269 type ControllerOrigin = governance::RootOrTechnicalCommitteeMember;270271 #[cfg(not(feature = "governance"))]272 type ControllerOrigin = frame_system::EnsureRoot<AccountId>;273274 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;275 type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;276}277278impl cumulus_pallet_dmp_queue::Config for Runtime {279 type RuntimeEvent = RuntimeEvent;280 type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight<Self>;281 type DmpSink = EnqueueWithOrigin<MessageQueue, RelayMsgOrigin>;282}