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