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