1#![cfg_attr(not(feature = "std"), no_std)]
17#![recursion_limit = "256"]
19
20#[cfg(feature = "std")]
22include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
23
24#[cfg(feature = "std")]
28pub mod fast_runtime_binary {
29 include!(concat!(env!("OUT_DIR"), "/fast_runtime_binary.rs"));
30}
31
32mod coretime;
33mod genesis_config_presets;
34mod weights;
35pub mod xcm_config;
36
37extern crate alloc;
38
39use alloc::{vec, vec::Vec};
40use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
41use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
42use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
43use frame_support::{
44 construct_runtime, derive_impl,
45 dispatch::DispatchClass,
46 genesis_builder_helper::{build_state, get_preset},
47 parameter_types,
48 traits::{
49 ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter, TransformOrigin,
50 },
51 weights::{ConstantMultiplier, Weight},
52 PalletId,
53};
54use frame_system::{
55 limits::{BlockLength, BlockWeights},
56 EnsureRoot,
57};
58use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
59use parachains_common::{
60 impls::DealWithFees,
61 message_queue::{NarrowOriginToSibling, ParaIdToSibling},
62 AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature,
63 AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO,
64};
65use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
66use sp_api::impl_runtime_apis;
67use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
68#[cfg(any(feature = "std", test))]
69pub use sp_runtime::BuildStorage;
70use sp_runtime::{
71 generic, impl_opaque_keys,
72 traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider},
73 transaction_validity::{TransactionSource, TransactionValidity},
74 ApplyExtrinsicResult, DispatchError, MultiAddress, Perbill, RuntimeDebug,
75};
76#[cfg(feature = "std")]
77use sp_version::NativeVersion;
78use sp_version::RuntimeVersion;
79use testnet_parachains_constants::westend::{consensus::*, currency::*, fee::WeightToFee, time::*};
80use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
81use xcm::{prelude::*, Version as XcmVersion};
82use xcm_config::{
83 FellowshipLocation, GovernanceLocation, TokenRelayLocation, XcmOriginToTransactDispatchOrigin,
84};
85use xcm_runtime_apis::{
86 dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
87 fees::Error as XcmPaymentApiError,
88};
89
90pub type Address = MultiAddress<AccountId, ()>;
92
93pub type Block = generic::Block<Header, UncheckedExtrinsic>;
95
96pub type SignedBlock = generic::SignedBlock<Block>;
98
99pub type BlockId = generic::BlockId<Block>;
101
102pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim<
104 Runtime,
105 (
106 frame_system::AuthorizeCall<Runtime>,
107 frame_system::CheckNonZeroSender<Runtime>,
108 frame_system::CheckSpecVersion<Runtime>,
109 frame_system::CheckTxVersion<Runtime>,
110 frame_system::CheckGenesis<Runtime>,
111 frame_system::CheckEra<Runtime>,
112 frame_system::CheckNonce<Runtime>,
113 frame_system::CheckWeight<Runtime>,
114 pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
115 frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
116 ),
117>;
118
119pub type UncheckedExtrinsic =
121 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
122
123pub type Migrations = (
125 pallet_collator_selection::migration::v2::MigrationToV2<Runtime>,
126 cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
127 cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5<Runtime>,
128 cumulus_pallet_xcmp_queue::migration::v6::MigrateV5ToV6<Runtime>,
129 cumulus_pallet_xcmp_queue::migration::v7::MigrateV6ToV7<Runtime>,
130 pallet_broker::migration::MigrateV0ToV1<Runtime>,
131 pallet_broker::migration::MigrateV1ToV2<Runtime>,
132 pallet_broker::migration::MigrateV2ToV3<Runtime>,
133 pallet_broker::migration::MigrateV3ToV4<Runtime, BrokerMigrationV4BlockConversion>,
134 pallet_session::migrations::v1::MigrateV0ToV1<
135 Runtime,
136 pallet_session::migrations::v1::InitOffenceSeverity<Runtime>,
137 >,
138 pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
140 cumulus_pallet_aura_ext::migration::MigrateV0ToV1<Runtime>,
141);
142
143pub type Executive = frame_executive::Executive<
145 Runtime,
146 Block,
147 frame_system::ChainContext<Runtime>,
148 Runtime,
149 AllPalletsWithSystem,
150 Migrations,
151>;
152
153impl_opaque_keys! {
154 pub struct SessionKeys {
155 pub aura: Aura,
156 }
157}
158
159#[sp_version::runtime_version]
160pub const VERSION: RuntimeVersion = RuntimeVersion {
161 spec_name: alloc::borrow::Cow::Borrowed("coretime-westend"),
162 impl_name: alloc::borrow::Cow::Borrowed("coretime-westend"),
163 authoring_version: 1,
164 spec_version: 1_019_004,
165 impl_version: 0,
166 apis: RUNTIME_API_VERSIONS,
167 transaction_version: 2,
168 system_version: 1,
169};
170
171#[cfg(feature = "std")]
173pub fn native_version() -> NativeVersion {
174 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
175}
176
177parameter_types! {
178 pub const Version: RuntimeVersion = VERSION;
179 pub RuntimeBlockLength: BlockLength =
180 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
181 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
182 .base_block(BlockExecutionWeight::get())
183 .for_class(DispatchClass::all(), |weights| {
184 weights.base_extrinsic = ExtrinsicBaseWeight::get();
185 })
186 .for_class(DispatchClass::Normal, |weights| {
187 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
188 })
189 .for_class(DispatchClass::Operational, |weights| {
190 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
191 weights.reserved = Some(
194 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
195 );
196 })
197 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
198 .build_or_panic();
199 pub const SS58Prefix: u8 = 42;
200}
201
202#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig)]
204impl frame_system::Config for Runtime {
205 type AccountId = AccountId;
207 type Nonce = Nonce;
209 type Hash = Hash;
211 type Block = Block;
213 type BlockHashCount = BlockHashCount;
215 type Version = Version;
217 type AccountData = pallet_balances::AccountData<Balance>;
219 type DbWeight = RocksDbWeight;
221 type SystemWeightInfo = weights::frame_system::WeightInfo<Runtime>;
223 type ExtensionsWeightInfo = weights::frame_system_extensions::WeightInfo<Runtime>;
225 type BlockWeights = RuntimeBlockWeights;
227 type BlockLength = RuntimeBlockLength;
229 type SS58Prefix = SS58Prefix;
230 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
232 type MaxConsumers = ConstU32<16>;
233}
234
235impl cumulus_pallet_weight_reclaim::Config for Runtime {
236 type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo<Runtime>;
237}
238
239impl pallet_timestamp::Config for Runtime {
240 type Moment = u64;
242 type OnTimestampSet = Aura;
243 type MinimumPeriod = ConstU64<0>;
244 type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
245}
246
247impl pallet_authorship::Config for Runtime {
248 type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
249 type EventHandler = (CollatorSelection,);
250}
251
252parameter_types! {
253 pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
254 pub const RandomParaId: ParaId = ParaId::new(43211234);
255}
256
257impl pallet_balances::Config for Runtime {
258 type Balance = Balance;
259 type DustRemoval = ();
260 type RuntimeEvent = RuntimeEvent;
261 type ExistentialDeposit = ExistentialDeposit;
262 type AccountStore = System;
263 type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
264 type MaxLocks = ConstU32<50>;
265 type MaxReserves = ConstU32<50>;
266 type ReserveIdentifier = [u8; 8];
267 type RuntimeHoldReason = RuntimeHoldReason;
268 type RuntimeFreezeReason = RuntimeFreezeReason;
269 type FreezeIdentifier = ();
270 type MaxFreezes = ConstU32<0>;
271 type DoneSlashHandler = ();
272}
273
274parameter_types! {
275 pub const TransactionByteFee: Balance = MILLICENTS;
277}
278
279impl pallet_transaction_payment::Config for Runtime {
280 type RuntimeEvent = RuntimeEvent;
281 type OnChargeTransaction =
282 pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>;
283 type OperationalFeeMultiplier = ConstU8<5>;
284 type WeightToFee = WeightToFee;
285 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
286 type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
287 type WeightInfo = weights::pallet_transaction_payment::WeightInfo<Runtime>;
288}
289
290parameter_types! {
291 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
292 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
293 pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
294}
295
296impl cumulus_pallet_parachain_system::Config for Runtime {
297 type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
298 type RuntimeEvent = RuntimeEvent;
299 type OnSystemEvent = ();
300 type SelfParaId = parachain_info::Pallet<Runtime>;
301 type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
302 type OutboundXcmpMessageSource = XcmpQueue;
303 type ReservedDmpWeight = ReservedDmpWeight;
304 type XcmpMessageHandler = XcmpQueue;
305 type ReservedXcmpWeight = ReservedXcmpWeight;
306 type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
307 type ConsensusHook = ConsensusHook;
308 type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
309 type RelayParentOffset = ConstU32<0>;
310}
311
312type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
313 Runtime,
314 RELAY_CHAIN_SLOT_DURATION_MILLIS,
315 BLOCK_PROCESSING_VELOCITY,
316 UNINCLUDED_SEGMENT_CAPACITY,
317>;
318
319parameter_types! {
320 pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
321}
322
323impl pallet_message_queue::Config for Runtime {
324 type RuntimeEvent = RuntimeEvent;
325 type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
326 #[cfg(feature = "runtime-benchmarks")]
327 type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor<
328 cumulus_primitives_core::AggregateMessageOrigin,
329 >;
330 #[cfg(not(feature = "runtime-benchmarks"))]
331 type MessageProcessor = xcm_builder::ProcessXcmMessage<
332 AggregateMessageOrigin,
333 xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
334 RuntimeCall,
335 >;
336 type Size = u32;
337 type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
339 type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
340 type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
341 type MaxStale = sp_core::ConstU32<8>;
342 type ServiceWeight = MessageQueueServiceWeight;
343 type IdleMaxServiceWeight = MessageQueueServiceWeight;
344}
345
346impl parachain_info::Config for Runtime {}
347
348impl cumulus_pallet_aura_ext::Config for Runtime {}
349
350parameter_types! {
351 pub const FellowsBodyId: BodyId = BodyId::Technical;
353}
354
355pub type RootOrFellows = EitherOfDiverse<
357 EnsureRoot<AccountId>,
358 EnsureXcm<IsVoiceOfBody<FellowshipLocation, FellowsBodyId>>,
359>;
360
361parameter_types! {
362 pub FeeAssetId: AssetId = AssetId(TokenRelayLocation::get());
364 pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
366}
367
368pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
369 FeeAssetId,
370 BaseDeliveryFee,
371 TransactionByteFee,
372 XcmpQueue,
373>;
374
375impl cumulus_pallet_xcmp_queue::Config for Runtime {
376 type RuntimeEvent = RuntimeEvent;
377 type ChannelInfo = ParachainSystem;
378 type VersionWrapper = PolkadotXcm;
379 type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
380 type MaxInboundSuspended = ConstU32<1_000>;
381 type MaxActiveOutboundChannels = ConstU32<128>;
382 type MaxPageSize = ConstU32<{ 103 * 1024 }>;
385 type ControllerOrigin = RootOrFellows;
386 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
387 type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo<Runtime>;
388 type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
389}
390
391impl cumulus_pallet_xcmp_queue::migration::v5::V5Config for Runtime {
392 type ChannelList = ParachainSystem;
394}
395
396pub const PERIOD: u32 = 6 * HOURS;
397pub const OFFSET: u32 = 0;
398
399impl pallet_session::Config for Runtime {
400 type RuntimeEvent = RuntimeEvent;
401 type ValidatorId = <Self as frame_system::Config>::AccountId;
402 type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
404 type ShouldEndSession = pallet_session::PeriodicSessions<ConstU32<PERIOD>, ConstU32<OFFSET>>;
405 type NextSessionRotation = pallet_session::PeriodicSessions<ConstU32<PERIOD>, ConstU32<OFFSET>>;
406 type SessionManager = CollatorSelection;
407 type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
409 type Keys = SessionKeys;
410 type DisablingStrategy = ();
411 type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
412}
413
414impl pallet_aura::Config for Runtime {
415 type AuthorityId = AuraId;
416 type DisabledValidators = ();
417 type MaxAuthorities = ConstU32<100_000>;
418 type AllowMultipleBlocksPerSlot = ConstBool<true>;
419 type SlotDuration = ConstU64<SLOT_DURATION>;
420}
421
422parameter_types! {
423 pub const PotId: PalletId = PalletId(*b"PotStake");
424 pub const SessionLength: BlockNumber = 6 * HOURS;
425 pub const StakingAdminBodyId: BodyId = BodyId::Defense;
427}
428
429pub type CollatorSelectionUpdateOrigin = EitherOfDiverse<
431 EnsureRoot<AccountId>,
432 EnsureXcm<IsVoiceOfBody<GovernanceLocation, StakingAdminBodyId>>,
433>;
434
435impl pallet_collator_selection::Config for Runtime {
436 type RuntimeEvent = RuntimeEvent;
437 type Currency = Balances;
438 type UpdateOrigin = CollatorSelectionUpdateOrigin;
439 type PotId = PotId;
440 type MaxCandidates = ConstU32<100>;
441 type MinEligibleCollators = ConstU32<4>;
442 type MaxInvulnerables = ConstU32<20>;
443 type KickThreshold = ConstU32<PERIOD>;
445 type ValidatorId = <Self as frame_system::Config>::AccountId;
446 type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
447 type ValidatorRegistration = Session;
448 type WeightInfo = weights::pallet_collator_selection::WeightInfo<Runtime>;
449}
450
451parameter_types! {
452 pub const DepositBase: Balance = deposit(1, 88);
454 pub const DepositFactor: Balance = deposit(0, 32);
456}
457
458impl pallet_multisig::Config for Runtime {
459 type RuntimeEvent = RuntimeEvent;
460 type RuntimeCall = RuntimeCall;
461 type Currency = Balances;
462 type DepositBase = DepositBase;
463 type DepositFactor = DepositFactor;
464 type MaxSignatories = ConstU32<100>;
465 type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
466 type BlockNumberProvider = frame_system::Pallet<Runtime>;
467}
468
469#[derive(
471 Copy,
472 Clone,
473 Eq,
474 PartialEq,
475 Ord,
476 PartialOrd,
477 Encode,
478 Decode,
479 DecodeWithMemTracking,
480 RuntimeDebug,
481 MaxEncodedLen,
482 scale_info::TypeInfo,
483)]
484pub enum ProxyType {
485 Any,
487 NonTransfer,
489 CancelProxy,
491 Broker,
493 CoretimeRenewer,
495 OnDemandPurchaser,
497 Collator,
499}
500impl Default for ProxyType {
501 fn default() -> Self {
502 Self::Any
503 }
504}
505
506impl InstanceFilter<RuntimeCall> for ProxyType {
507 fn filter(&self, c: &RuntimeCall) -> bool {
508 match self {
509 ProxyType::Any => true,
510 ProxyType::NonTransfer => !matches!(
511 c,
512 RuntimeCall::Balances { .. } |
513 RuntimeCall::Broker(pallet_broker::Call::purchase { .. }) |
515 RuntimeCall::Broker(pallet_broker::Call::renew { .. }) |
516 RuntimeCall::Broker(pallet_broker::Call::transfer { .. }) |
517 RuntimeCall::Broker(pallet_broker::Call::purchase_credit { .. }) |
518 RuntimeCall::Broker(pallet_broker::Call::pool { .. }) |
520 RuntimeCall::Broker(pallet_broker::Call::assign { .. })
522 ),
523 ProxyType::CancelProxy => matches!(
524 c,
525 RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) |
526 RuntimeCall::Utility { .. } |
527 RuntimeCall::Multisig { .. }
528 ),
529 ProxyType::Broker => {
530 matches!(
531 c,
532 RuntimeCall::Broker { .. } |
533 RuntimeCall::Utility { .. } |
534 RuntimeCall::Multisig { .. }
535 )
536 },
537 ProxyType::CoretimeRenewer => {
538 matches!(
539 c,
540 RuntimeCall::Broker(pallet_broker::Call::renew { .. }) |
541 RuntimeCall::Utility { .. } |
542 RuntimeCall::Multisig { .. }
543 )
544 },
545 ProxyType::OnDemandPurchaser => {
546 matches!(
547 c,
548 RuntimeCall::Broker(pallet_broker::Call::purchase_credit { .. }) |
549 RuntimeCall::Utility { .. } |
550 RuntimeCall::Multisig { .. }
551 )
552 },
553 ProxyType::Collator => matches!(
554 c,
555 RuntimeCall::CollatorSelection { .. } |
556 RuntimeCall::Utility { .. } |
557 RuntimeCall::Multisig { .. }
558 ),
559 }
560 }
561
562 fn is_superset(&self, o: &Self) -> bool {
563 match (self, o) {
564 (x, y) if x == y => true,
565 (ProxyType::Any, _) => true,
566 (_, ProxyType::Any) => false,
567 (ProxyType::Broker, ProxyType::CoretimeRenewer) => true,
568 (ProxyType::Broker, ProxyType::OnDemandPurchaser) => true,
569 (ProxyType::NonTransfer, ProxyType::Collator) => true,
570 _ => false,
571 }
572 }
573}
574
575parameter_types! {
576 pub const ProxyDepositBase: Balance = deposit(1, 40);
578 pub const ProxyDepositFactor: Balance = deposit(0, 33);
580 pub const MaxProxies: u16 = 32;
581 pub const AnnouncementDepositBase: Balance = deposit(1, 48);
583 pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
584 pub const MaxPending: u16 = 32;
585}
586
587impl pallet_proxy::Config for Runtime {
588 type RuntimeEvent = RuntimeEvent;
589 type RuntimeCall = RuntimeCall;
590 type Currency = Balances;
591 type ProxyType = ProxyType;
592 type ProxyDepositBase = ProxyDepositBase;
593 type ProxyDepositFactor = ProxyDepositFactor;
594 type MaxProxies = MaxProxies;
595 type WeightInfo = weights::pallet_proxy::WeightInfo<Runtime>;
596 type MaxPending = MaxPending;
597 type CallHasher = BlakeTwo256;
598 type AnnouncementDepositBase = AnnouncementDepositBase;
599 type AnnouncementDepositFactor = AnnouncementDepositFactor;
600 type BlockNumberProvider = frame_system::Pallet<Runtime>;
601}
602
603impl pallet_utility::Config for Runtime {
604 type RuntimeEvent = RuntimeEvent;
605 type RuntimeCall = RuntimeCall;
606 type PalletsOrigin = OriginCaller;
607 type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
608}
609
610impl pallet_sudo::Config for Runtime {
611 type RuntimeCall = RuntimeCall;
612 type RuntimeEvent = RuntimeEvent;
613 type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
614}
615
616pub struct BrokerMigrationV4BlockConversion;
617
618impl pallet_broker::migration::v4::BlockToRelayHeightConversion<Runtime>
619 for BrokerMigrationV4BlockConversion
620{
621 fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 {
622 let relay_height = pallet_broker::RCBlockNumberProviderOf::<
623 <Runtime as pallet_broker::Config>::Coretime,
624 >::current_block_number();
625 let parachain_block_number = frame_system::Pallet::<Runtime>::block_number();
626 let offset = relay_height - parachain_block_number * 2;
627 offset + input_block_number * 2
628 }
629
630 fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 {
631 input_block_length * 2
632 }
633}
634
635construct_runtime!(
637 pub enum Runtime
638 {
639 System: frame_system = 0,
641 ParachainSystem: cumulus_pallet_parachain_system = 1,
642 Timestamp: pallet_timestamp = 3,
643 ParachainInfo: parachain_info = 4,
644 WeightReclaim: cumulus_pallet_weight_reclaim = 5,
645
646 Balances: pallet_balances = 10,
648 TransactionPayment: pallet_transaction_payment = 11,
649
650 Authorship: pallet_authorship = 20,
652 CollatorSelection: pallet_collator_selection = 21,
653 Session: pallet_session = 22,
654 Aura: pallet_aura = 23,
655 AuraExt: cumulus_pallet_aura_ext = 24,
656
657 XcmpQueue: cumulus_pallet_xcmp_queue = 30,
659 PolkadotXcm: pallet_xcm = 31,
660 CumulusXcm: cumulus_pallet_xcm = 32,
661 MessageQueue: pallet_message_queue = 34,
662
663 Utility: pallet_utility = 40,
665 Multisig: pallet_multisig = 41,
666 Proxy: pallet_proxy = 42,
667
668 Broker: pallet_broker = 50,
670
671 Sudo: pallet_sudo = 100,
673 }
674);
675
676#[cfg(feature = "runtime-benchmarks")]
677mod benches {
678 frame_benchmarking::define_benchmarks!(
679 [frame_system, SystemBench::<Runtime>]
680 [cumulus_pallet_parachain_system, ParachainSystem]
681 [pallet_timestamp, Timestamp]
682 [pallet_balances, Balances]
683 [pallet_broker, Broker]
684 [pallet_collator_selection, CollatorSelection]
685 [pallet_session, SessionBench::<Runtime>]
686 [cumulus_pallet_xcmp_queue, XcmpQueue]
687 [pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
688 [pallet_message_queue, MessageQueue]
689 [pallet_multisig, Multisig]
690 [pallet_proxy, Proxy]
691 [pallet_utility, Utility]
692 [pallet_xcm_benchmarks::fungible, XcmBalances]
694 [pallet_xcm_benchmarks::generic, XcmGeneric]
695 [cumulus_pallet_weight_reclaim, WeightReclaim]
696 );
697}
698
699impl_runtime_apis! {
700 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
701 fn slot_duration() -> sp_consensus_aura::SlotDuration {
702 sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
703 }
704
705 fn authorities() -> Vec<AuraId> {
706 pallet_aura::Authorities::<Runtime>::get().into_inner()
707 }
708 }
709
710 impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
711 fn relay_parent_offset() -> u32 {
712 0
713 }
714 }
715
716 impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
717 fn can_build_upon(
718 included_hash: <Block as BlockT>::Hash,
719 slot: cumulus_primitives_aura::Slot,
720 ) -> bool {
721 ConsensusHook::can_build_upon(included_hash, slot)
722 }
723 }
724
725 impl sp_api::Core<Block> for Runtime {
726 fn version() -> RuntimeVersion {
727 VERSION
728 }
729
730 fn execute_block(block: Block) {
731 Executive::execute_block(block)
732 }
733
734 fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
735 Executive::initialize_block(header)
736 }
737 }
738
739 impl sp_api::Metadata<Block> for Runtime {
740 fn metadata() -> OpaqueMetadata {
741 OpaqueMetadata::new(Runtime::metadata().into())
742 }
743
744 fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
745 Runtime::metadata_at_version(version)
746 }
747
748 fn metadata_versions() -> alloc::vec::Vec<u32> {
749 Runtime::metadata_versions()
750 }
751 }
752
753 impl sp_block_builder::BlockBuilder<Block> for Runtime {
754 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
755 Executive::apply_extrinsic(extrinsic)
756 }
757
758 fn finalize_block() -> <Block as BlockT>::Header {
759 Executive::finalize_block()
760 }
761
762 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
763 data.create_extrinsics()
764 }
765
766 fn check_inherents(
767 block: Block,
768 data: sp_inherents::InherentData,
769 ) -> sp_inherents::CheckInherentsResult {
770 data.check_extrinsics(&block)
771 }
772 }
773
774 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
775 fn validate_transaction(
776 source: TransactionSource,
777 tx: <Block as BlockT>::Extrinsic,
778 block_hash: <Block as BlockT>::Hash,
779 ) -> TransactionValidity {
780 Executive::validate_transaction(source, tx, block_hash)
781 }
782 }
783
784 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
785 fn offchain_worker(header: &<Block as BlockT>::Header) {
786 Executive::offchain_worker(header)
787 }
788 }
789
790 impl sp_session::SessionKeys<Block> for Runtime {
791 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
792 SessionKeys::generate(seed)
793 }
794
795 fn decode_session_keys(
796 encoded: Vec<u8>,
797 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
798 SessionKeys::decode_into_raw_public_keys(&encoded)
799 }
800 }
801
802 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
803 fn account_nonce(account: AccountId) -> Nonce {
804 System::account_nonce(account)
805 }
806 }
807
808 impl pallet_broker::runtime_api::BrokerApi<Block, Balance> for Runtime {
809 fn sale_price() -> Result<Balance, DispatchError> {
810 Broker::current_price()
811 }
812 }
813
814 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
815 fn query_info(
816 uxt: <Block as BlockT>::Extrinsic,
817 len: u32,
818 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
819 TransactionPayment::query_info(uxt, len)
820 }
821 fn query_fee_details(
822 uxt: <Block as BlockT>::Extrinsic,
823 len: u32,
824 ) -> pallet_transaction_payment::FeeDetails<Balance> {
825 TransactionPayment::query_fee_details(uxt, len)
826 }
827 fn query_weight_to_fee(weight: Weight) -> Balance {
828 TransactionPayment::weight_to_fee(weight)
829 }
830 fn query_length_to_fee(length: u32) -> Balance {
831 TransactionPayment::length_to_fee(length)
832 }
833 }
834
835 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
836 for Runtime
837 {
838 fn query_call_info(
839 call: RuntimeCall,
840 len: u32,
841 ) -> pallet_transaction_payment::RuntimeDispatchInfo<Balance> {
842 TransactionPayment::query_call_info(call, len)
843 }
844 fn query_call_fee_details(
845 call: RuntimeCall,
846 len: u32,
847 ) -> pallet_transaction_payment::FeeDetails<Balance> {
848 TransactionPayment::query_call_fee_details(call, len)
849 }
850 fn query_weight_to_fee(weight: Weight) -> Balance {
851 TransactionPayment::weight_to_fee(weight)
852 }
853 fn query_length_to_fee(length: u32) -> Balance {
854 TransactionPayment::length_to_fee(length)
855 }
856 }
857
858 impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
859 fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
860 let acceptable_assets = vec![AssetId(xcm_config::TokenRelayLocation::get())];
861 PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
862 }
863
864 fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
865 use crate::xcm_config::XcmConfig;
866
867 type Trader = <XcmConfig as xcm_executor::Config>::Trader;
868
869 PolkadotXcm::query_weight_to_asset_fee::<Trader>(weight, asset)
870 }
871
872 fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
873 PolkadotXcm::query_xcm_weight(message)
874 }
875
876 fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
877 PolkadotXcm::query_delivery_fees(destination, message)
878 }
879 }
880
881 impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
882 fn dry_run_call(origin: OriginCaller, call: RuntimeCall, result_xcms_version: XcmVersion) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
883 PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call, result_xcms_version)
884 }
885
886 fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
887 PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
888 }
889 }
890
891 impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
892 fn convert_location(location: VersionedLocation) -> Result<
893 AccountId,
894 xcm_runtime_apis::conversions::Error
895 > {
896 xcm_runtime_apis::conversions::LocationToAccountHelper::<
897 AccountId,
898 xcm_config::LocationToAccountId,
899 >::convert_location(location)
900 }
901 }
902
903 impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
904 fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
905 PolkadotXcm::is_trusted_reserve(asset, location)
906 }
907 fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
908 PolkadotXcm::is_trusted_teleporter(asset, location)
909 }
910 }
911
912 impl xcm_runtime_apis::authorized_aliases::AuthorizedAliasersApi<Block> for Runtime {
913 fn authorized_aliasers(target: VersionedLocation) -> Result<
914 Vec<xcm_runtime_apis::authorized_aliases::OriginAliaser>,
915 xcm_runtime_apis::authorized_aliases::Error
916 > {
917 PolkadotXcm::authorized_aliasers(target)
918 }
919 fn is_authorized_alias(origin: VersionedLocation, target: VersionedLocation) -> Result<
920 bool,
921 xcm_runtime_apis::authorized_aliases::Error
922 > {
923 PolkadotXcm::is_authorized_alias(origin, target)
924 }
925 }
926
927 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
928 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
929 ParachainSystem::collect_collation_info(header)
930 }
931 }
932
933 impl cumulus_primitives_core::GetCoreSelectorApi<Block> for Runtime {
934 fn core_selector() -> (CoreSelector, ClaimQueueOffset) {
935 ParachainSystem::core_selector()
936 }
937 }
938
939 #[cfg(feature = "try-runtime")]
940 impl frame_try_runtime::TryRuntime<Block> for Runtime {
941 fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
942 let weight = Executive::try_runtime_upgrade(checks).unwrap();
943 (weight, RuntimeBlockWeights::get().max_block)
944 }
945
946 fn execute_block(
947 block: Block,
948 state_root_check: bool,
949 signature_check: bool,
950 select: frame_try_runtime::TryStateSelect,
951 ) -> Weight {
952 Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
955 }
956 }
957
958 #[cfg(feature = "runtime-benchmarks")]
959 impl frame_benchmarking::Benchmark<Block> for Runtime {
960 fn benchmark_metadata(extra: bool) -> (
961 Vec<frame_benchmarking::BenchmarkList>,
962 Vec<frame_support::traits::StorageInfo>,
963 ) {
964 use frame_benchmarking::BenchmarkList;
965 use frame_support::traits::StorageInfoTrait;
966 use frame_system_benchmarking::Pallet as SystemBench;
967 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
968 use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
969
970 type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
974 type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;
975
976 let mut list = Vec::<BenchmarkList>::new();
977 list_benchmarks!(list, extra);
978
979 let storage_info = AllPalletsWithSystem::storage_info();
980 (list, storage_info)
981 }
982
983 #[allow(non_local_definitions)]
984 fn dispatch_benchmark(
985 config: frame_benchmarking::BenchmarkConfig
986 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
987 use frame_benchmarking::{BenchmarkBatch, BenchmarkError};
988 use sp_storage::TrackedStorageKey;
989
990 use frame_system_benchmarking::Pallet as SystemBench;
991 impl frame_system_benchmarking::Config for Runtime {
992 fn setup_set_code_requirements(code: &alloc::vec::Vec<u8>) -> Result<(), BenchmarkError> {
993 ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
994 Ok(())
995 }
996
997 fn verify_set_code() {
998 System::assert_last_event(cumulus_pallet_parachain_system::Event::<Runtime>::ValidationFunctionStored.into());
999 }
1000 }
1001
1002 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1003 impl cumulus_pallet_session_benchmarking::Config for Runtime {}
1004
1005 use xcm::latest::prelude::*;
1006 use xcm_config::TokenRelayLocation;
1007
1008 use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
1009 impl pallet_xcm::benchmarking::Config for Runtime {
1010 type DeliveryHelper = (
1011 cumulus_primitives_utility::ToParentDeliveryHelper<
1012 xcm_config::XcmConfig,
1013 ExistentialDepositAsset,
1014 xcm_config::PriceForParentDelivery,
1015 >,
1016 polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
1017 xcm_config::XcmConfig,
1018 ExistentialDepositAsset,
1019 PriceForSiblingParachainDelivery,
1020 RandomParaId,
1021 ParachainSystem,
1022 >
1023 );
1024
1025 fn reachable_dest() -> Option<Location> {
1026 Some(Parent.into())
1027 }
1028
1029 fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
1030 Some((
1032 Asset {
1033 fun: Fungible(ExistentialDeposit::get()),
1034 id: AssetId(Parent.into())
1035 },
1036 Parent.into(),
1037 ))
1038 }
1039
1040 fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
1041 let core = 0;
1045 let begin = 0;
1046 let end = 42;
1047
1048 let region_id = pallet_broker::Pallet::<Runtime>::issue(core, begin, pallet_broker::CoreMask::complete(), end, None, None);
1049 Some((
1050 Asset {
1051 fun: NonFungible(Index(region_id.into())),
1052 id: AssetId(xcm_config::BrokerPalletLocation::get())
1053 },
1054 ParentThen(Parachain(RandomParaId::get().into()).into()).into(),
1055 ))
1056 }
1057
1058 fn get_asset() -> Asset {
1059 Asset {
1060 id: AssetId(Location::parent()),
1061 fun: Fungible(ExistentialDeposit::get()),
1062 }
1063 }
1064 }
1065
1066 parameter_types! {
1067 pub ExistentialDepositAsset: Option<Asset> = Some((
1068 TokenRelayLocation::get(),
1069 ExistentialDeposit::get()
1070 ).into());
1071 }
1072
1073 impl pallet_xcm_benchmarks::Config for Runtime {
1074 type XcmConfig = xcm_config::XcmConfig;
1075
1076 type DeliveryHelper = (
1077 cumulus_primitives_utility::ToParentDeliveryHelper<
1078 xcm_config::XcmConfig,
1079 ExistentialDepositAsset,
1080 xcm_config::PriceForParentDelivery,
1081 >,
1082 polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
1083 xcm_config::XcmConfig,
1084 ExistentialDepositAsset,
1085 PriceForSiblingParachainDelivery,
1086 RandomParaId,
1087 ParachainSystem,
1088 >
1089 );
1090
1091 type AccountIdConverter = xcm_config::LocationToAccountId;
1092 fn valid_destination() -> Result<Location, BenchmarkError> {
1093 Ok(TokenRelayLocation::get())
1094 }
1095 fn worst_case_holding(_depositable_count: u32) -> Assets {
1096 let assets: Vec<Asset> = vec![
1098 Asset {
1099 id: AssetId(TokenRelayLocation::get()),
1100 fun: Fungible(1_000_000 * UNITS),
1101 }
1102 ];
1103 assets.into()
1104 }
1105 }
1106
1107 parameter_types! {
1108 pub const TrustedTeleporter: Option<(Location, Asset)> = Some((
1109 TokenRelayLocation::get(),
1110 Asset { fun: Fungible(UNITS), id: AssetId(TokenRelayLocation::get()) },
1111 ));
1112 pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
1113 pub const TrustedReserve: Option<(Location, Asset)> = None;
1114 }
1115
1116 impl pallet_xcm_benchmarks::fungible::Config for Runtime {
1117 type TransactAsset = Balances;
1118
1119 type CheckedAccount = CheckedAccount;
1120 type TrustedTeleporter = TrustedTeleporter;
1121 type TrustedReserve = TrustedReserve;
1122
1123 fn get_asset() -> Asset {
1124 Asset {
1125 id: AssetId(TokenRelayLocation::get()),
1126 fun: Fungible(UNITS),
1127 }
1128 }
1129 }
1130
1131 impl pallet_xcm_benchmarks::generic::Config for Runtime {
1132 type RuntimeCall = RuntimeCall;
1133 type TransactAsset = Balances;
1134
1135 fn worst_case_response() -> (u64, Response) {
1136 (0u64, Response::Version(Default::default()))
1137 }
1138
1139 fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
1140 Err(BenchmarkError::Skip)
1141 }
1142
1143 fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
1144 Err(BenchmarkError::Skip)
1145 }
1146
1147 fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
1148 Ok((TokenRelayLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
1149 }
1150
1151 fn subscribe_origin() -> Result<Location, BenchmarkError> {
1152 Ok(TokenRelayLocation::get())
1153 }
1154
1155 fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
1156 let origin = TokenRelayLocation::get();
1157 let assets: Assets = (AssetId(TokenRelayLocation::get()), 1_000 * UNITS).into();
1158 let ticket = Location { parents: 0, interior: Here };
1159 Ok((origin, ticket, assets))
1160 }
1161
1162 fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1163 Ok((Asset {
1164 id: AssetId(TokenRelayLocation::get()),
1165 fun: Fungible(1_000_000 * UNITS),
1166 }, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
1167 }
1168
1169 fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
1170 Err(BenchmarkError::Skip)
1171 }
1172
1173 fn export_message_origin_and_destination(
1174 ) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
1175 Err(BenchmarkError::Skip)
1176 }
1177
1178 fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
1179 let origin = Location::new(1, [Parachain(1000)]);
1180 let target = Location::new(1, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]);
1181 Ok((origin, target))
1182 }
1183 }
1184
1185 type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
1186 type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;
1187
1188 use frame_support::traits::WhitelistedStorageKeys;
1189 let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
1190
1191 let mut batches = Vec::<BenchmarkBatch>::new();
1192 let params = (&config, &whitelist);
1193 add_benchmarks!(params, batches);
1194
1195 Ok(batches)
1196 }
1197 }
1198
1199 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1200 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1201 build_state::<RuntimeGenesisConfig>(config)
1202 }
1203
1204 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1205 get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
1206 }
1207
1208 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1209 genesis_config_presets::preset_names()
1210 }
1211 }
1212}
1213
1214cumulus_pallet_parachain_system::register_validate_block! {
1215 Runtime = Runtime,
1216 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
1217}