xcm_simulator_example/relay_chain/
mod.rs
1mod xcm_config;
20pub use xcm_config::*;
21
22use frame_support::{
23 construct_runtime, derive_impl, parameter_types,
24 traits::{
25 AsEnsureOriginWithArg, ConstU128, Disabled, Everything, Nothing, ProcessMessage,
26 ProcessMessageError,
27 },
28 weights::{Weight, WeightMeter},
29};
30
31use frame_system::EnsureRoot;
32use sp_core::ConstU32;
33use sp_runtime::{traits::IdentityLookup, AccountId32};
34
35use polkadot_runtime_parachains::{
36 configuration,
37 inclusion::{AggregateMessageOrigin, UmpQueueId},
38 origin, shared,
39};
40use xcm::latest::prelude::*;
41use xcm_builder::{IsConcrete, SignedToAccountId32};
42use xcm_executor::XcmExecutor;
43
44pub type AccountId = AccountId32;
45pub type Balance = u128;
46
47parameter_types! {
48 pub const BlockHashCount: u64 = 250;
49}
50
51#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
52impl frame_system::Config for Runtime {
53 type AccountId = AccountId;
54 type Lookup = IdentityLookup<Self::AccountId>;
55 type Block = Block;
56 type AccountData = pallet_balances::AccountData<Balance>;
57}
58
59#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
60impl pallet_balances::Config for Runtime {
61 type Balance = Balance;
62 type ExistentialDeposit = ConstU128<1>;
63 type AccountStore = System;
64}
65
66impl pallet_uniques::Config for Runtime {
67 type RuntimeEvent = RuntimeEvent;
68 type CollectionId = u32;
69 type ItemId = u32;
70 type Currency = Balances;
71 type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<AccountId>>;
72 type ForceOrigin = frame_system::EnsureRoot<AccountId>;
73 type CollectionDeposit = frame_support::traits::ConstU128<1_000>;
74 type ItemDeposit = frame_support::traits::ConstU128<1_000>;
75 type MetadataDepositBase = frame_support::traits::ConstU128<1_000>;
76 type AttributeDepositBase = frame_support::traits::ConstU128<1_000>;
77 type DepositPerByte = frame_support::traits::ConstU128<1>;
78 type StringLimit = ConstU32<64>;
79 type KeyLimit = ConstU32<64>;
80 type ValueLimit = ConstU32<128>;
81 type Locker = ();
82 type WeightInfo = ();
83 #[cfg(feature = "runtime-benchmarks")]
84 type Helper = ();
85}
86
87impl shared::Config for Runtime {
88 type DisabledValidators = ();
89}
90
91impl configuration::Config for Runtime {
92 type WeightInfo = configuration::TestWeightInfo;
93}
94
95pub type LocalOriginToLocation =
96 SignedToAccountId32<RuntimeOrigin, AccountId, constants::RelayNetwork>;
97
98impl pallet_xcm::Config for Runtime {
99 type RuntimeEvent = RuntimeEvent;
100 type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
101 type XcmRouter = XcmRouter;
102 type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
104 type XcmExecuteFilter = Nothing;
105 type XcmExecutor = XcmExecutor<XcmConfig>;
106 type XcmTeleportFilter = Everything;
107 type XcmReserveTransferFilter = Everything;
108 type Weigher = weigher::Weigher;
109 type UniversalLocation = constants::UniversalLocation;
110 type RuntimeOrigin = RuntimeOrigin;
111 type RuntimeCall = RuntimeCall;
112 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
113 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
114 type Currency = Balances;
115 type CurrencyMatcher = IsConcrete<constants::TokenLocation>;
116 type TrustedLockers = ();
117 type SovereignAccountOf = location_converter::LocationConverter;
118 type MaxLockers = ConstU32<8>;
119 type MaxRemoteLockConsumers = ConstU32<0>;
120 type RemoteLockConsumerIdentifier = ();
121 type WeightInfo = pallet_xcm::TestWeightInfo;
122 type AdminOrigin = EnsureRoot<AccountId>;
123 type AuthorizedAliasConsideration = Disabled;
124}
125
126impl origin::Config for Runtime {}
127
128type Block = frame_system::mocking::MockBlock<Runtime>;
129
130parameter_types! {
131 pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000);
133 pub const MessageQueueHeapSize: u32 = 65_536;
134 pub const MessageQueueMaxStale: u32 = 16;
135}
136
137pub struct MessageProcessor;
139impl ProcessMessage for MessageProcessor {
140 type Origin = AggregateMessageOrigin;
141
142 fn process_message(
143 message: &[u8],
144 origin: Self::Origin,
145 meter: &mut WeightMeter,
146 id: &mut [u8; 32],
147 ) -> Result<bool, ProcessMessageError> {
148 let para = match origin {
149 AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
150 };
151 xcm_builder::ProcessXcmMessage::<
152 Junction,
153 xcm_executor::XcmExecutor<XcmConfig>,
154 RuntimeCall,
155 >::process_message(message, Junction::Parachain(para.into()), meter, id)
156 }
157}
158
159impl pallet_message_queue::Config for Runtime {
160 type RuntimeEvent = RuntimeEvent;
161 type Size = u32;
162 type HeapSize = MessageQueueHeapSize;
163 type MaxStale = MessageQueueMaxStale;
164 type ServiceWeight = MessageQueueServiceWeight;
165 type IdleMaxServiceWeight = ();
166 type MessageProcessor = MessageProcessor;
167 type QueueChangeHandler = ();
168 type QueuePausedQuery = ();
169 type WeightInfo = ();
170}
171
172construct_runtime!(
173 pub enum Runtime
174 {
175 System: frame_system,
176 Balances: pallet_balances,
177 ParasOrigin: origin,
178 XcmPallet: pallet_xcm,
179 Uniques: pallet_uniques,
180 MessageQueue: pallet_message_queue,
181 }
182);