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