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}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 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}