1#![cfg_attr(not(feature = "std"), no_std)]
18#![recursion_limit = "256"]
20
21#[cfg(feature = "std")]
23include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
24
25pub mod wasm_spec_version_incremented {
26 #[cfg(feature = "std")]
27 include!(concat!(env!("OUT_DIR"), "/wasm_binary_spec_version_incremented.rs"));
28}
29
30pub mod relay_parent_offset {
31 #[cfg(feature = "std")]
32 include!(concat!(env!("OUT_DIR"), "/wasm_binary_relay_parent_offset.rs"));
33}
34
35pub mod elastic_scaling_500ms {
36 #[cfg(feature = "std")]
37 include!(concat!(env!("OUT_DIR"), "/wasm_binary_elastic_scaling_500ms.rs"));
38}
39pub mod elastic_scaling_mvp {
40 #[cfg(feature = "std")]
41 include!(concat!(env!("OUT_DIR"), "/wasm_binary_elastic_scaling_mvp.rs"));
42}
43
44pub mod elastic_scaling {
45 #[cfg(feature = "std")]
46 include!(concat!(env!("OUT_DIR"), "/wasm_binary_elastic_scaling.rs"));
47}
48
49pub mod elastic_scaling_multi_block_slot {
50 #[cfg(feature = "std")]
51 include!(concat!(env!("OUT_DIR"), "/wasm_binary_elastic_scaling_multi_block_slot.rs"));
52}
53
54pub mod sync_backing {
55 #[cfg(feature = "std")]
56 include!(concat!(env!("OUT_DIR"), "/wasm_binary_sync_backing.rs"));
57}
58
59mod genesis_config_presets;
60mod test_pallet;
61
62extern crate alloc;
63
64use alloc::{vec, vec::Vec};
65use frame_support::{derive_impl, traits::OnRuntimeUpgrade, PalletId};
66use sp_api::{decl_runtime_apis, impl_runtime_apis};
67pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
68use sp_core::{ConstBool, ConstU32, ConstU64, OpaqueMetadata};
69
70use sp_runtime::{
71 generic, impl_opaque_keys,
72 traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, Verify},
73 transaction_validity::{TransactionSource, TransactionValidity},
74 ApplyExtrinsicResult, MultiAddress, MultiSignature,
75};
76#[cfg(feature = "std")]
77use sp_version::NativeVersion;
78use sp_version::RuntimeVersion;
79
80use cumulus_primitives_core::ParaId;
81
82pub use frame_support::{
84 construct_runtime,
85 dispatch::DispatchClass,
86 genesis_builder_helper::{build_state, get_preset},
87 parameter_types,
88 traits::{ConstU8, Randomness},
89 weights::{
90 constants::{
91 BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
92 },
93 ConstantMultiplier, IdentityFee, Weight,
94 },
95 StorageValue,
96};
97use frame_system::{
98 limits::{BlockLength, BlockWeights},
99 EnsureRoot,
100};
101pub use pallet_balances::Call as BalancesCall;
102pub use pallet_glutton::Call as GluttonCall;
103pub use pallet_sudo::Call as SudoCall;
104pub use pallet_timestamp::{Call as TimestampCall, Now};
105#[cfg(any(feature = "std", test))]
106pub use sp_runtime::BuildStorage;
107pub use sp_runtime::{Perbill, Permill};
108pub use test_pallet::Call as TestPalletCall;
109
110pub type SessionHandlers = ();
111
112impl_opaque_keys! {
113 pub struct SessionKeys {
114 pub aura: Aura,
115 }
116}
117
118pub const PARACHAIN_ID: u32 = 100;
120
121#[cfg(all(
122 feature = "elastic-scaling-multi-block-slot",
123 not(any(
124 feature = "elastic-scaling",
125 feature = "elastic-scaling-500ms",
126 feature = "relay-parent-offset"
127 ))
128))]
129pub const BLOCK_PROCESSING_VELOCITY: u32 = 6;
130
131#[cfg(all(
132 feature = "elastic-scaling-500ms",
133 not(any(
134 feature = "elastic-scaling",
135 feature = "elastic-scaling-multi-block-slot",
136 feature = "relay-parent-offset"
137 ))
138))]
139pub const BLOCK_PROCESSING_VELOCITY: u32 = 12;
140
141#[cfg(any(feature = "elastic-scaling", feature = "relay-parent-offset"))]
142pub const BLOCK_PROCESSING_VELOCITY: u32 = 3;
143
144#[cfg(not(any(
145 feature = "elastic-scaling",
146 feature = "elastic-scaling-500ms",
147 feature = "elastic-scaling-multi-block-slot",
148 feature = "relay-parent-offset"
149)))]
150pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
151
152#[cfg(feature = "sync-backing")]
153const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
154
155#[cfg(not(feature = "sync-backing"))]
157const UNINCLUDED_SEGMENT_CAPACITY: u32 = BLOCK_PROCESSING_VELOCITY * (2 + RELAY_PARENT_OFFSET) + 2;
158
159#[cfg(feature = "sync-backing")]
160pub const SLOT_DURATION: u64 = 12000;
161#[cfg(not(feature = "sync-backing"))]
162pub const SLOT_DURATION: u64 = 6000;
163
164const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
165
166#[cfg(not(feature = "increment-spec-version"))]
178#[sp_version::runtime_version]
179pub const VERSION: RuntimeVersion = RuntimeVersion {
180 spec_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
181 impl_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
182 authoring_version: 1,
183 spec_version: 2,
185 impl_version: 1,
186 apis: RUNTIME_API_VERSIONS,
187 transaction_version: 1,
188 system_version: 1,
189};
190
191#[cfg(feature = "increment-spec-version")]
192#[sp_version::runtime_version]
193pub const VERSION: RuntimeVersion = RuntimeVersion {
194 spec_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
195 impl_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
196 authoring_version: 1,
197 spec_version: 3,
199 impl_version: 1,
200 apis: RUNTIME_API_VERSIONS,
201 transaction_version: 1,
202 system_version: 1,
203};
204
205pub const EPOCH_DURATION_IN_BLOCKS: u32 = 10 * MINUTES;
206
207pub const MINUTES: BlockNumber = 60_000 / (SLOT_DURATION as BlockNumber);
209pub const HOURS: BlockNumber = MINUTES * 60;
210pub const DAYS: BlockNumber = HOURS * 24;
211
212pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
214
215#[cfg(feature = "std")]
217pub fn native_version() -> NativeVersion {
218 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
219}
220
221const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
224const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
227const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
229 WEIGHT_REF_TIME_PER_SECOND,
230 cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
231);
232
233parameter_types! {
234 pub const BlockHashCount: BlockNumber = 250;
235 pub const Version: RuntimeVersion = VERSION;
236 pub RuntimeBlockLength: BlockLength =
237 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
238 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
239 .base_block(BlockExecutionWeight::get())
240 .for_class(DispatchClass::all(), |weights| {
241 weights.base_extrinsic = ExtrinsicBaseWeight::get();
242 })
243 .for_class(DispatchClass::Normal, |weights| {
244 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
245 })
246 .for_class(DispatchClass::Operational, |weights| {
247 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
248 weights.reserved = Some(
251 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
252 );
253 })
254 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
255 .build_or_panic();
256 pub const SS58Prefix: u8 = 42;
257}
258
259#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig)]
260impl frame_system::Config for Runtime {
261 type AccountId = AccountId;
263 type Nonce = Nonce;
265 type Hash = Hash;
267 type Block = Block;
269 type BlockHashCount = BlockHashCount;
271 type Version = Version;
273 type AccountData = pallet_balances::AccountData<Balance>;
274 type BlockWeights = RuntimeBlockWeights;
275 type BlockLength = RuntimeBlockLength;
276 type SS58Prefix = SS58Prefix;
277 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
278 type MaxConsumers = frame_support::traits::ConstU32<16>;
279 type SingleBlockMigrations = TestOnRuntimeUpgrade;
280}
281
282impl cumulus_pallet_weight_reclaim::Config for Runtime {
283 type WeightInfo = ();
284}
285
286parameter_types! {
287 pub const MinimumPeriod: u64 = 0;
288}
289
290parameter_types! {
291 pub const PotId: PalletId = PalletId(*b"PotStake");
292 pub const SessionLength: BlockNumber = 10 * MINUTES;
293 pub const Offset: u32 = 0;
294}
295
296impl cumulus_pallet_aura_ext::Config for Runtime {}
297
298impl pallet_timestamp::Config for Runtime {
299 type Moment = u64;
301 type OnTimestampSet = Aura;
302 type MinimumPeriod = MinimumPeriod;
303 type WeightInfo = ();
304}
305
306parameter_types! {
307 pub const ExistentialDeposit: u128 = 500;
308 pub const TransferFee: u128 = 0;
309 pub const CreationFee: u128 = 0;
310 pub const TransactionByteFee: u128 = 1;
311 pub const MaxReserves: u32 = 50;
312}
313
314impl pallet_balances::Config for Runtime {
315 type Balance = Balance;
317 type RuntimeEvent = RuntimeEvent;
319 type DustRemoval = ();
320 type ExistentialDeposit = ExistentialDeposit;
321 type AccountStore = System;
322 type WeightInfo = ();
323 type MaxLocks = ();
324 type MaxReserves = MaxReserves;
325 type ReserveIdentifier = [u8; 8];
326 type RuntimeHoldReason = RuntimeHoldReason;
327 type RuntimeFreezeReason = RuntimeFreezeReason;
328 type FreezeIdentifier = ();
329 type MaxFreezes = ConstU32<0>;
330 type DoneSlashHandler = ();
331}
332
333impl pallet_transaction_payment::Config for Runtime {
334 type RuntimeEvent = RuntimeEvent;
335 type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
336 type WeightToFee = IdentityFee<Balance>;
337 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
338 type FeeMultiplierUpdate = ();
339 type OperationalFeeMultiplier = ConstU8<5>;
340 type WeightInfo = pallet_transaction_payment::weights::SubstrateWeight<Runtime>;
341}
342
343impl pallet_sudo::Config for Runtime {
344 type RuntimeCall = RuntimeCall;
345 type RuntimeEvent = RuntimeEvent;
346 type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
347}
348
349impl pallet_glutton::Config for Runtime {
350 type RuntimeEvent = RuntimeEvent;
351 type AdminOrigin = EnsureRoot<AccountId>;
352 type WeightInfo = pallet_glutton::weights::SubstrateWeight<Runtime>;
353}
354
355#[cfg(feature = "relay-parent-offset")]
356const RELAY_PARENT_OFFSET: u32 = 2;
357
358#[cfg(not(feature = "relay-parent-offset"))]
359const RELAY_PARENT_OFFSET: u32 = 0;
360
361type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
362 Runtime,
363 RELAY_CHAIN_SLOT_DURATION_MILLIS,
364 BLOCK_PROCESSING_VELOCITY,
365 UNINCLUDED_SEGMENT_CAPACITY,
366>;
367impl cumulus_pallet_parachain_system::Config for Runtime {
368 type WeightInfo = ();
369 type SelfParaId = parachain_info::Pallet<Runtime>;
370 type RuntimeEvent = RuntimeEvent;
371 type OnSystemEvent = ();
372 type OutboundXcmpMessageSource = ();
373 type DmpQueue = frame_support::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>;
375 type ReservedDmpWeight = ();
376 type XcmpMessageHandler = ();
377 type ReservedXcmpWeight = ();
378 type CheckAssociatedRelayNumber =
379 cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
380 type ConsensusHook = ConsensusHook;
381 type RelayParentOffset = ConstU32<RELAY_PARENT_OFFSET>;
382}
383
384impl parachain_info::Config for Runtime {}
385
386impl pallet_aura::Config for Runtime {
387 type AuthorityId = AuraId;
388 type DisabledValidators = ();
389 type MaxAuthorities = ConstU32<32>;
390 #[cfg(feature = "sync-backing")]
391 type AllowMultipleBlocksPerSlot = ConstBool<false>;
392 #[cfg(not(feature = "sync-backing"))]
393 type AllowMultipleBlocksPerSlot = ConstBool<true>;
394 type SlotDuration = ConstU64<SLOT_DURATION>;
395}
396
397impl test_pallet::Config for Runtime {}
398
399construct_runtime! {
400 pub enum Runtime
401 {
402 System: frame_system,
403 ParachainSystem: cumulus_pallet_parachain_system,
404 Timestamp: pallet_timestamp,
405 ParachainInfo: parachain_info,
406 Balances: pallet_balances,
407 Sudo: pallet_sudo,
408 TransactionPayment: pallet_transaction_payment,
409 TestPallet: test_pallet,
410 Glutton: pallet_glutton,
411 Aura: pallet_aura,
412 AuraExt: cumulus_pallet_aura_ext,
413 WeightReclaim: cumulus_pallet_weight_reclaim,
414 }
415}
416
417pub type Nonce = u32;
419pub type Hash = sp_core::H256;
421pub type Balance = u128;
423pub type Signature = MultiSignature;
425pub type BlockNumber = u32;
427pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
430pub type NodeBlock = generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
432
433pub type Address = MultiAddress<AccountId, ()>;
435pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
437pub type Block = generic::Block<Header, UncheckedExtrinsic>;
439pub type SignedBlock = generic::SignedBlock<Block>;
441pub type BlockId = generic::BlockId<Block>;
443pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim<
445 Runtime,
446 (
447 frame_system::AuthorizeCall<Runtime>,
448 frame_system::CheckNonZeroSender<Runtime>,
449 frame_system::CheckSpecVersion<Runtime>,
450 frame_system::CheckGenesis<Runtime>,
451 frame_system::CheckEra<Runtime>,
452 frame_system::CheckNonce<Runtime>,
453 frame_system::CheckWeight<Runtime>,
454 pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
455 ),
456>;
457pub type UncheckedExtrinsic =
459 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
460pub type Executive = frame_executive::Executive<
462 Runtime,
463 Block,
464 frame_system::ChainContext<Runtime>,
465 Runtime,
466 AllPalletsWithSystem,
467>;
468pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>;
470
471pub struct TestOnRuntimeUpgrade;
472
473impl OnRuntimeUpgrade for TestOnRuntimeUpgrade {
474 fn on_runtime_upgrade() -> frame_support::weights::Weight {
475 assert_eq!(
476 sp_io::storage::get(test_pallet::TEST_RUNTIME_UPGRADE_KEY),
477 Some(vec![1, 2, 3, 4].into())
478 );
479 Weight::from_parts(1, 0)
480 }
481}
482
483decl_runtime_apis! {
484 pub trait GetLastTimestamp {
485 fn get_last_timestamp() -> u64;
487 }
488}
489
490impl_runtime_apis! {
491 impl sp_api::Core<Block> for Runtime {
492 fn version() -> RuntimeVersion {
493 VERSION
494 }
495
496 fn execute_block(block: Block) {
497 Executive::execute_block(block)
498 }
499
500 fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
501 Executive::initialize_block(header)
502 }
503 }
504
505
506 impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
507 fn can_build_upon(
508 included_hash: <Block as BlockT>::Hash,
509 slot: cumulus_primitives_aura::Slot,
510 ) -> bool {
511 ConsensusHook::can_build_upon(included_hash, slot)
512 }
513 }
514
515 impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
516 fn relay_parent_offset() -> u32 {
517 RELAY_PARENT_OFFSET
518 }
519 }
520
521 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
522 fn slot_duration() -> sp_consensus_aura::SlotDuration {
523 sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
524 }
525
526 fn authorities() -> Vec<AuraId> {
527 pallet_aura::Authorities::<Runtime>::get().into_inner()
528 }
529 }
530
531 impl sp_api::Metadata<Block> for Runtime {
532 fn metadata() -> OpaqueMetadata {
533 OpaqueMetadata::new(Runtime::metadata().into())
534 }
535
536 fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
537 Runtime::metadata_at_version(version)
538 }
539
540 fn metadata_versions() -> Vec<u32> {
541 Runtime::metadata_versions()
542 }
543 }
544
545 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
546 fn account_nonce(account: AccountId) -> Nonce {
547 System::account_nonce(account)
548 }
549 }
550
551 impl sp_block_builder::BlockBuilder<Block> for Runtime {
552 fn apply_extrinsic(
553 extrinsic: <Block as BlockT>::Extrinsic,
554 ) -> ApplyExtrinsicResult {
555 Executive::apply_extrinsic(extrinsic)
556 }
557
558 fn finalize_block() -> <Block as BlockT>::Header {
559 Executive::finalize_block()
560 }
561
562 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
563 data.create_extrinsics()
564 }
565
566 fn check_inherents(block: Block, data: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
567 data.check_extrinsics(&block)
568 }
569 }
570
571 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
572 fn validate_transaction(
573 source: TransactionSource,
574 tx: <Block as BlockT>::Extrinsic,
575 block_hash: <Block as BlockT>::Hash,
576 ) -> TransactionValidity {
577 Executive::validate_transaction(source, tx, block_hash)
578 }
579 }
580
581 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
582 fn offchain_worker(header: &<Block as BlockT>::Header) {
583 Executive::offchain_worker(header)
584 }
585 }
586
587 impl sp_session::SessionKeys<Block> for Runtime {
588 fn decode_session_keys(
589 encoded: Vec<u8>,
590 ) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
591 SessionKeys::decode_into_raw_public_keys(&encoded)
592 }
593
594 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
595 SessionKeys::generate(seed)
596 }
597 }
598
599 impl crate::GetLastTimestamp<Block> for Runtime {
600 fn get_last_timestamp() -> u64 {
601 Now::<Runtime>::get()
602 }
603 }
604
605 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
606 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
607 ParachainSystem::collect_collation_info(header)
608 }
609 }
610
611 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
612 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
613 build_state::<RuntimeGenesisConfig>(config)
614 }
615
616 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
617 get_preset::<RuntimeGenesisConfig>(id, genesis_config_presets::get_preset)
618 }
619
620 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
621 genesis_config_presets::preset_names()
622 }
623 }
624
625 impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
626 fn parachain_id() -> ParaId {
627 ParachainInfo::parachain_id()
628 }
629
630 }
631}
632
633cumulus_pallet_parachain_system::register_validate_block! {
634 Runtime = Runtime,
635 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
636}