referrerpolicy=no-referrer-when-downgrade

cumulus_test_runtime/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3
4// Cumulus is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Cumulus is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
16
17#![cfg_attr(not(feature = "std"), no_std)]
18// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
19#![recursion_limit = "256"]
20
21// Make the WASM binaries available.
22#[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_12s_slot {
50	#[cfg(feature = "std")]
51	include!(concat!(env!("OUT_DIR"), "/wasm_binary_elastic_scaling_12s_slot.rs"));
52}
53
54pub mod block_bundling {
55	#[cfg(feature = "std")]
56	include!(concat!(env!("OUT_DIR"), "/wasm_binary_block_bundling.rs"));
57}
58
59pub mod sync_backing {
60	#[cfg(feature = "std")]
61	include!(concat!(env!("OUT_DIR"), "/wasm_binary_sync_backing.rs"));
62}
63
64pub mod async_backing {
65	#[cfg(feature = "std")]
66	include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
67}
68
69pub mod slot_duration_18s {
70	#[cfg(feature = "std")]
71	include!(concat!(env!("OUT_DIR"), "/wasm_binary_slot_duration_18s.rs"));
72}
73
74mod genesis_config_presets;
75pub mod test_pallet;
76
77extern crate alloc;
78
79use alloc::{vec, vec::Vec};
80use frame_support::{derive_impl, traits::OnRuntimeUpgrade, PalletId};
81use sp_api::{decl_runtime_apis, impl_runtime_apis};
82pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
83use sp_core::{ConstBool, ConstU32, ConstU64, Get, OpaqueMetadata};
84
85use sp_runtime::{
86	generic, impl_opaque_keys,
87	traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, Verify},
88	transaction_validity::{TransactionSource, TransactionValidity},
89	ApplyExtrinsicResult, MultiAddress, MultiSignature,
90};
91#[cfg(feature = "std")]
92use sp_version::NativeVersion;
93use sp_version::RuntimeVersion;
94
95use cumulus_primitives_core::{ParaId, RelayProofRequest};
96
97// A few exports that help ease life for downstream crates.
98pub use frame_support::{
99	construct_runtime,
100	dispatch::DispatchClass,
101	genesis_builder_helper::{build_state, get_preset},
102	parameter_types,
103	traits::{ConstU8, Randomness},
104	weights::{
105		constants::{
106			BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
107		},
108		ConstantMultiplier, IdentityFee, Weight,
109	},
110	StorageValue,
111};
112pub use frame_system::Call as SystemCall;
113use frame_system::{
114	limits::{BlockLength, BlockWeights},
115	EnsureRoot,
116};
117pub use pallet_balances::Call as BalancesCall;
118pub use pallet_glutton::Call as GluttonCall;
119pub use pallet_sudo::Call as SudoCall;
120pub use pallet_timestamp::{Call as TimestampCall, Now};
121#[cfg(any(feature = "std", test))]
122pub use sp_runtime::BuildStorage;
123pub use sp_runtime::{Perbill, Permill};
124pub use test_pallet::{Call as TestPalletCall, TestTransactionExtension};
125
126pub type SessionHandlers = ();
127
128impl_opaque_keys! {
129	pub struct SessionKeys {
130		pub aura: Aura,
131	}
132}
133
134/// The para-id used in this runtime.
135pub const PARACHAIN_ID: u32 = 100;
136
137#[cfg(any(feature = "elastic-scaling-500ms", feature = "block-bundling"))]
138pub const BLOCK_PROCESSING_VELOCITY: u32 = 12;
139
140#[cfg(all(feature = "elastic-scaling-multi-block-slot", not(feature = "elastic-scaling-500ms")))]
141pub const BLOCK_PROCESSING_VELOCITY: u32 = 6;
142
143#[cfg(all(
144	any(feature = "elastic-scaling", feature = "relay-parent-offset"),
145	not(feature = "elastic-scaling-500ms"),
146	not(feature = "elastic-scaling-multi-block-slot")
147))]
148pub const BLOCK_PROCESSING_VELOCITY: u32 = 3;
149
150#[cfg(not(any(
151	feature = "elastic-scaling",
152	feature = "elastic-scaling-500ms",
153	feature = "elastic-scaling-multi-block-slot",
154	feature = "relay-parent-offset",
155	feature = "block-bundling",
156)))]
157pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
158
159#[cfg(feature = "async-backing")]
160const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
161
162#[cfg(all(feature = "sync-backing", not(feature = "async-backing")))]
163const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
164
165/// We need `VELOCITY * 3`, because the block flow is the following:
166///
167/// - Collator produces the block(s) on relay chain block `X`
168/// - In the mean time the relay chain is building block `X + 1`
169/// - The collator sends the collation to the relay chain and it gets backed on chain in relay block
170///   `X + 2`
171/// - The collation then gets included on chain in relay block `X + 3`
172/// - As we are building on `RELAY_PARENT_OFFSET` old relay parents, the included block from the
173///   parachain is also `RELAY_PARENT_OFFSET` relay blocks older (one relay block may contains
174///   multiple parachain blocks).
175#[cfg(all(not(feature = "sync-backing"), not(feature = "async-backing")))]
176const UNINCLUDED_SEGMENT_CAPACITY: u32 = BLOCK_PROCESSING_VELOCITY * (3 + RELAY_PARENT_OFFSET);
177
178#[cfg(feature = "slot-duration-18s")]
179pub const SLOT_DURATION: u64 = 18000;
180#[cfg(all(
181	any(feature = "sync-backing", feature = "elastic-scaling-12s-slot"),
182	not(feature = "slot-duration-18s")
183))]
184pub const SLOT_DURATION: u64 = 12000;
185#[cfg(not(any(
186	feature = "sync-backing",
187	feature = "elastic-scaling-12s-slot",
188	feature = "slot-duration-18s"
189)))]
190pub const SLOT_DURATION: u64 = 6000;
191
192const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
193
194// The only difference between the two declarations below is the `spec_version`. With the
195// `increment-spec-version` feature enabled `spec_version` should be greater than the one of without
196// the `increment-spec-version` feature.
197//
198// The duplication here is unfortunate necessity.
199//
200// runtime_version macro is dumb. It accepts a const item declaration, passes it through and
201// also emits runtime version custom section. It parses the expressions to extract the version
202// details. Since macro kicks in early, it operates on AST. Thus you cannot use constants.
203// Macros are expanded top to bottom, meaning we also cannot use `cfg` here.
204
205#[cfg(all(not(feature = "increment-spec-version"), not(feature = "elastic-scaling")))]
206#[sp_version::runtime_version]
207pub const VERSION: RuntimeVersion = RuntimeVersion {
208	spec_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
209	impl_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
210	authoring_version: 1,
211	// Read the note above.
212	spec_version: 2,
213	impl_version: 1,
214	apis: RUNTIME_API_VERSIONS,
215	transaction_version: 1,
216	system_version: 3,
217};
218
219#[cfg(any(feature = "increment-spec-version", feature = "elastic-scaling"))]
220#[sp_version::runtime_version]
221pub const VERSION: RuntimeVersion = RuntimeVersion {
222	spec_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
223	impl_name: alloc::borrow::Cow::Borrowed("cumulus-test-parachain"),
224	authoring_version: 1,
225	// Read the note above.
226	spec_version: 3,
227	impl_version: 1,
228	apis: RUNTIME_API_VERSIONS,
229	transaction_version: 1,
230	system_version: 3,
231};
232
233pub const EPOCH_DURATION_IN_BLOCKS: u32 = 10 * MINUTES;
234
235// These time units are defined in number of blocks.
236pub const MINUTES: BlockNumber = 60_000 / (SLOT_DURATION as BlockNumber);
237pub const HOURS: BlockNumber = MINUTES * 60;
238pub const DAYS: BlockNumber = HOURS * 24;
239
240// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
241pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
242
243/// The version information used to identify this runtime when compiled natively.
244#[cfg(feature = "std")]
245pub fn native_version() -> NativeVersion {
246	NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
247}
248
249/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers.
250/// This is used to limit the maximal weight of a single extrinsic.
251const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
252/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
253/// by  Operational  extrinsics.
254const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
255
256type MaximumBlockWeight = cumulus_pallet_parachain_system::block_weight::MaxParachainBlockWeight<
257	Runtime,
258	ConstU32<BLOCK_PROCESSING_VELOCITY>,
259>;
260
261parameter_types! {
262	/// Target number of blocks per relay chain slot.
263	pub const NumberOfBlocksPerRelaySlot: u32 = 12;
264	pub const BlockHashCount: BlockNumber = 250;
265	pub const Version: RuntimeVersion = VERSION;
266	/// We allow for 1 second of compute with a 6 second average block time.
267	pub RuntimeBlockLength: BlockLength =
268		BlockLength::builder().max_length(10 * 1024 * 1024).max_header_size(5 * 1024 * 1024).build();
269	pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
270		.base_block(BlockExecutionWeight::get())
271		.for_class(DispatchClass::all(), |weights| {
272			weights.base_extrinsic = ExtrinsicBaseWeight::get();
273		})
274		.for_class(DispatchClass::Normal, |weights| {
275			weights.max_total = Some(NORMAL_DISPATCH_RATIO * MaximumBlockWeight::get());
276		})
277		.for_class(DispatchClass::Operational, |weights| {
278			weights.max_total = Some(MaximumBlockWeight::get());
279			// Operational transactions have some extra reserved space, so that they
280			// are included even if block reached `MaximumBlockWeight`.
281			weights.reserved = Some(
282				MaximumBlockWeight::get() - NORMAL_DISPATCH_RATIO * MaximumBlockWeight::get()
283			);
284		})
285		.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
286		.build_or_panic();
287	pub const SS58Prefix: u8 = 42;
288}
289
290#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig)]
291impl frame_system::Config for Runtime {
292	/// The identifier used to distinguish between accounts.
293	type AccountId = AccountId;
294	/// The index type for storing how many extrinsics an account has signed.
295	type Nonce = Nonce;
296	/// The type for hashing blocks and tries.
297	type Hash = Hash;
298	/// The block type.
299	type Block = Block;
300	/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
301	type BlockHashCount = BlockHashCount;
302	/// Runtime version.
303	type Version = Version;
304	type AccountData = pallet_balances::AccountData<Balance>;
305	type BlockWeights = RuntimeBlockWeights;
306	type BlockLength = RuntimeBlockLength;
307	type SS58Prefix = SS58Prefix;
308	type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
309	type MaxConsumers = frame_support::traits::ConstU32<16>;
310	type PreInherents = cumulus_pallet_parachain_system::block_weight::DynamicMaxBlockWeightHooks<
311		Runtime,
312		ConstU32<BLOCK_PROCESSING_VELOCITY>,
313	>;
314	type SingleBlockMigrations = SingleBlockMigrations;
315}
316
317impl cumulus_pallet_weight_reclaim::Config for Runtime {
318	type WeightInfo = ();
319}
320
321parameter_types! {
322	pub const MinimumPeriod: u64 = 0;
323}
324
325parameter_types! {
326	pub const PotId: PalletId = PalletId(*b"PotStake");
327	pub const SessionLength: BlockNumber = 10 * MINUTES;
328	pub const Offset: u32 = 0;
329}
330
331impl cumulus_pallet_aura_ext::Config for Runtime {}
332
333impl pallet_timestamp::Config for Runtime {
334	/// A timestamp: milliseconds since the unix epoch.
335	type Moment = u64;
336	type OnTimestampSet = Aura;
337	type MinimumPeriod = MinimumPeriod;
338	type WeightInfo = ();
339}
340
341parameter_types! {
342	pub const ExistentialDeposit: u128 = 500;
343	pub const TransferFee: u128 = 0;
344	pub const CreationFee: u128 = 0;
345	pub const TransactionByteFee: u128 = 1;
346	pub const MaxReserves: u32 = 50;
347}
348
349impl pallet_balances::Config for Runtime {
350	/// The type for recording an account's balance.
351	type Balance = Balance;
352	/// The ubiquitous event type.
353	type RuntimeEvent = RuntimeEvent;
354	type DustRemoval = ();
355	type ExistentialDeposit = ExistentialDeposit;
356	type AccountStore = System;
357	type WeightInfo = ();
358	type MaxLocks = ();
359	type MaxReserves = MaxReserves;
360	type ReserveIdentifier = [u8; 8];
361	type RuntimeHoldReason = RuntimeHoldReason;
362	type RuntimeFreezeReason = RuntimeFreezeReason;
363	type FreezeIdentifier = ();
364	type MaxFreezes = ConstU32<0>;
365	type DoneSlashHandler = ();
366}
367
368impl pallet_transaction_payment::Config for Runtime {
369	type RuntimeEvent = RuntimeEvent;
370	type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
371	type WeightToFee = IdentityFee<Balance>;
372	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
373	type FeeMultiplierUpdate = ();
374	type OperationalFeeMultiplier = ConstU8<5>;
375	type WeightInfo = pallet_transaction_payment::weights::SubstrateWeight<Runtime>;
376}
377
378impl pallet_sudo::Config for Runtime {
379	type RuntimeCall = RuntimeCall;
380	type RuntimeEvent = RuntimeEvent;
381	type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
382}
383
384impl pallet_utility::Config for Runtime {
385	type RuntimeCall = RuntimeCall;
386	type RuntimeEvent = RuntimeEvent;
387	type PalletsOrigin = OriginCaller;
388	type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
389}
390
391impl pallet_glutton::Config for Runtime {
392	type RuntimeEvent = RuntimeEvent;
393	type AdminOrigin = EnsureRoot<AccountId>;
394	type WeightInfo = pallet_glutton::weights::SubstrateWeight<Runtime>;
395}
396
397#[cfg(feature = "relay-parent-offset")]
398const RELAY_PARENT_OFFSET: u32 = 2;
399
400#[cfg(not(feature = "relay-parent-offset"))]
401const RELAY_PARENT_OFFSET: u32 = 0;
402
403type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
404	Runtime,
405	RELAY_CHAIN_SLOT_DURATION_MILLIS,
406	BLOCK_PROCESSING_VELOCITY,
407	UNINCLUDED_SEGMENT_CAPACITY,
408>;
409impl cumulus_pallet_parachain_system::Config for Runtime {
410	type WeightInfo = ();
411	type SelfParaId = parachain_info::Pallet<Runtime>;
412	type RuntimeEvent = RuntimeEvent;
413	type OnSystemEvent = TestPallet;
414	type OutboundXcmpMessageSource = TestPallet;
415	// Ignore all DMP messages by enqueueing them into `()`:
416	type DmpQueue = frame_support::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>;
417	type ReservedDmpWeight = ();
418	type XcmpMessageHandler = ();
419	type ReservedXcmpWeight = ();
420	type CheckAssociatedRelayNumber =
421		cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
422	type ConsensusHook = ConsensusHook;
423	type RelayParentOffset = ConstU32<RELAY_PARENT_OFFSET>;
424}
425
426impl parachain_info::Config for Runtime {}
427
428impl pallet_aura::Config for Runtime {
429	type AuthorityId = AuraId;
430	type DisabledValidators = ();
431	type MaxAuthorities = ConstU32<32>;
432	#[cfg(feature = "sync-backing")]
433	type AllowMultipleBlocksPerSlot = ConstBool<false>;
434	#[cfg(not(feature = "sync-backing"))]
435	type AllowMultipleBlocksPerSlot = ConstBool<true>;
436	type SlotDuration = ConstU64<SLOT_DURATION>;
437}
438
439impl test_pallet::Config for Runtime {}
440
441construct_runtime! {
442	pub enum Runtime
443	{
444		System: frame_system,
445		ParachainSystem: cumulus_pallet_parachain_system,
446		Timestamp: pallet_timestamp,
447		ParachainInfo: parachain_info,
448		Balances: pallet_balances,
449		Sudo: pallet_sudo,
450		Utility: pallet_utility,
451		TransactionPayment: pallet_transaction_payment,
452		TestPallet: test_pallet,
453		Glutton: pallet_glutton,
454		Aura: pallet_aura,
455		AuraExt: cumulus_pallet_aura_ext,
456		WeightReclaim: cumulus_pallet_weight_reclaim,
457	}
458}
459
460/// Index of a transaction in the chain.
461pub type Nonce = u32;
462/// A hash of some data used by the chain.
463pub type Hash = sp_core::H256;
464/// Balance of an account.
465pub type Balance = u128;
466/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
467pub type Signature = MultiSignature;
468/// An index to a block.
469pub type BlockNumber = u32;
470/// Some way of identifying an account on the chain. We intentionally make it equivalent
471/// to the public key of our transaction signing scheme.
472pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
473/// Opaque block type.
474pub type NodeBlock = generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
475
476/// The address format for describing accounts.
477pub type Address = MultiAddress<AccountId, ()>;
478/// Block header type as expected by this runtime.
479pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
480/// Block type as expected by this runtime.
481pub type Block = generic::Block<Header, UncheckedExtrinsic>;
482/// A Block signed with a Justification
483pub type SignedBlock = generic::SignedBlock<Block>;
484/// BlockId type as expected by this runtime.
485pub type BlockId = generic::BlockId<Block>;
486/// The extension to the basic transaction logic.
487pub type TxExtension = cumulus_pallet_parachain_system::block_weight::DynamicMaxBlockWeight<
488	Runtime,
489	cumulus_pallet_weight_reclaim::StorageWeightReclaim<
490		Runtime,
491		(
492			frame_system::AuthorizeCall<Runtime>,
493			frame_system::CheckNonZeroSender<Runtime>,
494			frame_system::CheckSpecVersion<Runtime>,
495			frame_system::CheckGenesis<Runtime>,
496			frame_system::CheckEra<Runtime>,
497			frame_system::CheckNonce<Runtime>,
498			frame_system::CheckWeight<Runtime>,
499			pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
500			test_pallet::TestTransactionExtension<Runtime>,
501		),
502	>,
503	ConstU32<BLOCK_PROCESSING_VELOCITY>,
504>;
505
506/// Unchecked extrinsic type as expected by this runtime.
507pub type UncheckedExtrinsic =
508	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
509/// Executive: handles dispatch to the various modules.
510pub type Executive = frame_executive::Executive<
511	Runtime,
512	Block,
513	frame_system::ChainContext<Runtime>,
514	Runtime,
515	AllPalletsWithSystem,
516>;
517
518/// The payload being signed in transactions.
519pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>;
520
521/// Migration to verify that runtime upgrade hooks are working correctly.
522///
523/// This checks that the test_pallet runtime upgrade key was set in genesis.
524pub struct VerifyRuntimeUpgrade;
525
526impl OnRuntimeUpgrade for VerifyRuntimeUpgrade {
527	fn on_runtime_upgrade() -> Weight {
528		assert_eq!(
529			sp_io::storage::get(test_pallet::TEST_RUNTIME_UPGRADE_KEY),
530			Some(vec![1, 2, 3, 4].into())
531		);
532		Weight::from_parts(1, 0)
533	}
534}
535
536/// Single-block migrations for the test runtime.
537///
538/// These migrations execute immediately and entirely at the beginning of the block following
539/// a runtime upgrade. They must be lightweight enough to complete within a single block.
540pub type SingleBlockMigrations = (
541	// Verify that runtime upgrade hooks are working correctly.
542	VerifyRuntimeUpgrade,
543);
544
545decl_runtime_apis! {
546	pub trait GetLastTimestamp {
547		/// Returns the last timestamp of a runtime.
548		fn get_last_timestamp() -> u64;
549	}
550}
551
552impl_runtime_apis! {
553	impl sp_api::Core<Block> for Runtime {
554		fn version() -> RuntimeVersion {
555			VERSION
556		}
557
558		fn execute_block(block: <Block as BlockT>::LazyBlock) {
559			Executive::execute_block(block)
560		}
561
562		fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
563			Executive::initialize_block(header)
564		}
565	}
566
567
568	impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
569		fn can_build_upon(
570			included_hash: <Block as BlockT>::Hash,
571			slot: cumulus_primitives_aura::Slot,
572		) -> bool {
573			ConsensusHook::can_build_upon(included_hash, slot)
574		}
575	}
576
577	impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
578		fn relay_parent_offset() -> u32 {
579			RELAY_PARENT_OFFSET
580		}
581	}
582
583	impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
584		fn slot_duration() -> sp_consensus_aura::SlotDuration {
585			sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
586		}
587
588		fn authorities() -> Vec<AuraId> {
589			pallet_aura::Authorities::<Runtime>::get().into_inner()
590		}
591	}
592
593	impl sp_api::Metadata<Block> for Runtime {
594		fn metadata() -> OpaqueMetadata {
595			OpaqueMetadata::new(Runtime::metadata().into())
596		}
597
598		fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
599			Runtime::metadata_at_version(version)
600		}
601
602		fn metadata_versions() -> Vec<u32> {
603			Runtime::metadata_versions()
604		}
605	}
606
607	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
608		fn account_nonce(account: AccountId) -> Nonce {
609			System::account_nonce(account)
610		}
611	}
612
613	impl sp_block_builder::BlockBuilder<Block> for Runtime {
614		fn apply_extrinsic(
615			extrinsic: <Block as BlockT>::Extrinsic,
616		) -> ApplyExtrinsicResult {
617			Executive::apply_extrinsic(extrinsic)
618		}
619
620		fn finalize_block() -> <Block as BlockT>::Header {
621			Executive::finalize_block()
622		}
623
624		fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
625			data.create_extrinsics()
626		}
627
628		fn check_inherents(block: <Block as BlockT>::LazyBlock, data: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
629			data.check_extrinsics(&block)
630		}
631
632	}
633
634	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
635		fn validate_transaction(
636			source: TransactionSource,
637			tx: <Block as BlockT>::Extrinsic,
638			block_hash: <Block as BlockT>::Hash,
639		) -> TransactionValidity {
640			Executive::validate_transaction(source, tx, block_hash)
641		}
642	}
643
644	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
645		fn offchain_worker(header: &<Block as BlockT>::Header) {
646			Executive::offchain_worker(header)
647		}
648	}
649
650	impl sp_session::SessionKeys<Block> for Runtime {
651		fn decode_session_keys(
652			encoded: Vec<u8>,
653		) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
654			SessionKeys::decode_into_raw_public_keys(&encoded)
655		}
656
657		fn generate_session_keys(owner: Vec<u8>, seed: Option<Vec<u8>>) -> sp_session::OpaqueGeneratedSessionKeys {
658			SessionKeys::generate(&owner, seed).into()
659		}
660	}
661
662	impl crate::GetLastTimestamp<Block> for Runtime {
663		fn get_last_timestamp() -> u64 {
664			Now::<Runtime>::get()
665		}
666	}
667
668	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
669		fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
670			ParachainSystem::collect_collation_info(header)
671		}
672	}
673
674	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
675		fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
676			build_state::<RuntimeGenesisConfig>(config)
677		}
678
679		fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
680			get_preset::<RuntimeGenesisConfig>(id, genesis_config_presets::get_preset)
681		}
682
683		fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
684			genesis_config_presets::preset_names()
685		}
686	}
687
688	impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
689		fn parachain_id() -> ParaId {
690			ParachainInfo::parachain_id()
691		}
692	}
693
694	// "Elastic scaling" should run with the fallback method.
695	#[cfg(any(not(feature = "elastic-scaling"), feature = "std"))]
696	impl cumulus_primitives_core::TargetBlockRate<Block> for Runtime {
697		fn target_block_rate() -> u32 {
698			BLOCK_PROCESSING_VELOCITY
699		}
700	}
701
702	impl cumulus_primitives_core::KeyToIncludeInRelayProof<Block> for Runtime {
703		fn keys_to_prove() -> cumulus_primitives_core::RelayProofRequest {
704			use cumulus_primitives_core::RelayStorageKey;
705			RelayProofRequest {
706				keys: vec![
707					// Request a key to verify its inclusion in the proof.
708					RelayStorageKey::Top(test_pallet::relay_alice_account_key()),
709				],
710			}
711		}
712	}
713}
714
715cumulus_pallet_parachain_system::register_validate_block! {
716	Runtime = Runtime,
717	BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
718}