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::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*};
80use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
81use xcm::{prelude::*, Version as XcmVersion};
82use xcm_config::{
83 FellowshipLocation, GovernanceLocation, RocRelayLocation, 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>;
149
150impl_opaque_keys! {
151 pub struct SessionKeys {
152 pub aura: Aura,
153 }
154}
155
156#[sp_version::runtime_version]
157pub const VERSION: RuntimeVersion = RuntimeVersion {
158 spec_name: alloc::borrow::Cow::Borrowed("coretime-rococo"),
159 impl_name: alloc::borrow::Cow::Borrowed("coretime-rococo"),
160 authoring_version: 1,
161 spec_version: 1_019_004,
162 impl_version: 0,
163 apis: RUNTIME_API_VERSIONS,
164 transaction_version: 2,
165 system_version: 1,
166};
167
168#[cfg(feature = "std")]
170pub fn native_version() -> NativeVersion {
171 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
172}
173
174parameter_types! {
175 pub const Version: RuntimeVersion = VERSION;
176 pub RuntimeBlockLength: BlockLength =
177 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
178 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
179 .base_block(BlockExecutionWeight::get())
180 .for_class(DispatchClass::all(), |weights| {
181 weights.base_extrinsic = ExtrinsicBaseWeight::get();
182 })
183 .for_class(DispatchClass::Normal, |weights| {
184 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
185 })
186 .for_class(DispatchClass::Operational, |weights| {
187 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
188 weights.reserved = Some(
191 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
192 );
193 })
194 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
195 .build_or_panic();
196 pub const SS58Prefix: u8 = 42;
197}
198
199#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig)]
201impl frame_system::Config for Runtime {
202 type AccountId = AccountId;
204 type Nonce = Nonce;
206 type Hash = Hash;
208 type Block = Block;
210 type BlockHashCount = BlockHashCount;
212 type Version = Version;
214 type AccountData = pallet_balances::AccountData<Balance>;
216 type DbWeight = RocksDbWeight;
218 type SystemWeightInfo = weights::frame_system::WeightInfo<Runtime>;
220 type ExtensionsWeightInfo = weights::frame_system_extensions::WeightInfo<Runtime>;
222 type BlockWeights = RuntimeBlockWeights;
224 type BlockLength = RuntimeBlockLength;
226 type SS58Prefix = SS58Prefix;
227 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
229 type MaxConsumers = ConstU32<16>;
230 type SingleBlockMigrations = Migrations;
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(RocRelayLocation::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::RocRelayLocation::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 cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
902 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
903 ParachainSystem::collect_collation_info(header)
904 }
905 }
906
907 #[cfg(feature = "try-runtime")]
908 impl frame_try_runtime::TryRuntime<Block> for Runtime {
909 fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
910 let weight = Executive::try_runtime_upgrade(checks).unwrap();
911 (weight, RuntimeBlockWeights::get().max_block)
912 }
913
914 fn execute_block(
915 block: Block,
916 state_root_check: bool,
917 signature_check: bool,
918 select: frame_try_runtime::TryStateSelect,
919 ) -> Weight {
920 Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
923 }
924 }
925
926 #[cfg(feature = "runtime-benchmarks")]
927 impl frame_benchmarking::Benchmark<Block> for Runtime {
928 fn benchmark_metadata(extra: bool) -> (
929 Vec<frame_benchmarking::BenchmarkList>,
930 Vec<frame_support::traits::StorageInfo>,
931 ) {
932 use frame_benchmarking::BenchmarkList;
933 use frame_support::traits::StorageInfoTrait;
934 use frame_system_benchmarking::Pallet as SystemBench;
935 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
936 use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
937
938 type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
942 type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;
943
944 let mut list = Vec::<BenchmarkList>::new();
945 list_benchmarks!(list, extra);
946
947 let storage_info = AllPalletsWithSystem::storage_info();
948 (list, storage_info)
949 }
950
951 #[allow(non_local_definitions)]
952 fn dispatch_benchmark(
953 config: frame_benchmarking::BenchmarkConfig
954 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
955 use frame_benchmarking::{BenchmarkBatch, BenchmarkError};
956 use sp_storage::TrackedStorageKey;
957
958 use frame_system_benchmarking::Pallet as SystemBench;
959 impl frame_system_benchmarking::Config for Runtime {
960 fn setup_set_code_requirements(code: &alloc::vec::Vec<u8>) -> Result<(), BenchmarkError> {
961 ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
962 Ok(())
963 }
964
965 fn verify_set_code() {
966 System::assert_last_event(cumulus_pallet_parachain_system::Event::<Runtime>::ValidationFunctionStored.into());
967 }
968 }
969
970 use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
971 impl cumulus_pallet_session_benchmarking::Config for Runtime {}
972
973 use xcm::latest::prelude::*;
974 use xcm_config::RocRelayLocation;
975
976 use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
977 use testnet_parachains_constants::rococo::locations::{AssetHubParaId, AssetHubLocation};
978
979 parameter_types! {
980 pub ExistentialDepositAsset: Option<Asset> = Some((
981 RocRelayLocation::get(),
982 ExistentialDeposit::get()
983 ).into());
984 }
985
986 impl pallet_xcm::benchmarking::Config for Runtime {
987 type DeliveryHelper =
988 polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
989 xcm_config::XcmConfig,
990 ExistentialDepositAsset,
991 PriceForSiblingParachainDelivery,
992 AssetHubParaId,
993 ParachainSystem,
994 >;
995
996 fn reachable_dest() -> Option<Location> {
997 Some(AssetHubLocation::get())
998 }
999
1000 fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
1001 Some((
1003 Asset {
1004 fun: Fungible(ExistentialDeposit::get()),
1005 id: AssetId(RocRelayLocation::get())
1006 },
1007 AssetHubLocation::get(),
1008 ))
1009 }
1010
1011 fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
1012 let core = 0;
1016 let begin = 0;
1017 let end = 42;
1018
1019 let region_id = pallet_broker::Pallet::<Runtime>::issue(core, begin, pallet_broker::CoreMask::complete(), end, None, None);
1020 Some((
1021 Asset {
1022 fun: NonFungible(Index(region_id.into())),
1023 id: AssetId(xcm_config::BrokerPalletLocation::get())
1024 },
1025 AssetHubLocation::get(),
1026 ))
1027 }
1028
1029 fn set_up_complex_asset_transfer() -> Option<(Assets, u32, Location, alloc::boxed::Box<dyn FnOnce()>)> {
1030 let native_location = Parent.into();
1031 let dest = AssetHubLocation::get();
1032
1033 pallet_xcm::benchmarking::helpers::native_teleport_as_asset_transfer::<Runtime>(
1034 native_location,
1035 dest,
1036 )
1037 }
1038
1039 fn get_asset() -> Asset {
1040 Asset {
1041 id: AssetId(RocRelayLocation::get()),
1042 fun: Fungible(ExistentialDeposit::get()),
1043 }
1044 }
1045 }
1046
1047 impl pallet_xcm_benchmarks::Config for Runtime {
1048 type XcmConfig = xcm_config::XcmConfig;
1049 type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
1050 xcm_config::XcmConfig,
1051 ExistentialDepositAsset,
1052 PriceForSiblingParachainDelivery,
1053 AssetHubParaId,
1054 ParachainSystem,
1055 >;
1056 type AccountIdConverter = xcm_config::LocationToAccountId;
1057 fn valid_destination() -> Result<Location, BenchmarkError> {
1058 Ok(AssetHubLocation::get())
1059 }
1060 fn worst_case_holding(_depositable_count: u32) -> Assets {
1061 let assets: Vec<Asset> = vec![
1063 Asset {
1064 id: AssetId(RocRelayLocation::get()),
1065 fun: Fungible(1_000_000 * UNITS),
1066 }
1067 ];
1068 assets.into()
1069 }
1070 }
1071
1072 parameter_types! {
1073 pub TrustedTeleporter: Option<(Location, Asset)> = Some((
1074 AssetHubLocation::get(),
1075 Asset { fun: Fungible(UNITS), id: AssetId(RocRelayLocation::get()) },
1076 ));
1077 pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
1078 pub const TrustedReserve: Option<(Location, Asset)> = None;
1079 }
1080
1081 impl pallet_xcm_benchmarks::fungible::Config for Runtime {
1082 type TransactAsset = Balances;
1083
1084 type CheckedAccount = CheckedAccount;
1085 type TrustedTeleporter = TrustedTeleporter;
1086 type TrustedReserve = TrustedReserve;
1087
1088 fn get_asset() -> Asset {
1089 Asset {
1090 id: AssetId(RocRelayLocation::get()),
1091 fun: Fungible(UNITS),
1092 }
1093 }
1094 }
1095
1096 impl pallet_xcm_benchmarks::generic::Config for Runtime {
1097 type RuntimeCall = RuntimeCall;
1098 type TransactAsset = Balances;
1099
1100 fn worst_case_response() -> (u64, Response) {
1101 (0u64, Response::Version(Default::default()))
1102 }
1103
1104 fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
1105 Err(BenchmarkError::Skip)
1106 }
1107
1108 fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
1109 Err(BenchmarkError::Skip)
1110 }
1111
1112 fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
1113 Ok((AssetHubLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
1114 }
1115
1116 fn subscribe_origin() -> Result<Location, BenchmarkError> {
1117 Ok(AssetHubLocation::get())
1118 }
1119
1120 fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
1121 let origin = AssetHubLocation::get();
1122 let assets: Assets = (AssetId(RocRelayLocation::get()), 1_000 * UNITS).into();
1123 let ticket = Location { parents: 0, interior: Here };
1124 Ok((origin, ticket, assets))
1125 }
1126
1127 fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1128 Ok((Asset {
1129 id: AssetId(RocRelayLocation::get()),
1130 fun: Fungible(1_000_000 * UNITS),
1131 }, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
1132 }
1133
1134 fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
1135 Err(BenchmarkError::Skip)
1136 }
1137
1138 fn export_message_origin_and_destination(
1139 ) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
1140 Err(BenchmarkError::Skip)
1141 }
1142
1143 fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
1144 Err(BenchmarkError::Skip)
1145 }
1146 }
1147
1148 type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
1149 type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;
1150
1151 use frame_support::traits::WhitelistedStorageKeys;
1152 let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
1153
1154 let mut batches = Vec::<BenchmarkBatch>::new();
1155 let params = (&config, &whitelist);
1156 add_benchmarks!(params, batches);
1157
1158 Ok(batches)
1159 }
1160 }
1161
1162 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1163 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1164 build_state::<RuntimeGenesisConfig>(config)
1165 }
1166
1167 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1168 get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
1169 }
1170
1171 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1172 genesis_config_presets::preset_names()
1173 }
1174 }
1175
1176 impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
1177 fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1178 PolkadotXcm::is_trusted_reserve(asset, location)
1179 }
1180 fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1181 PolkadotXcm::is_trusted_teleporter(asset, location)
1182 }
1183 }
1184
1185 impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
1186 fn parachain_id() -> ParaId {
1187 ParachainInfo::parachain_id()
1188 }
1189 }
1190}
1191
1192cumulus_pallet_parachain_system::register_validate_block! {
1193 Runtime = Runtime,
1194 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
1195}