1#![cfg_attr(not(feature = "std"), no_std)]
23#![recursion_limit = "256"]
25
26#[cfg(feature = "std")]
28include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
29
30extern crate alloc;
31
32use alloc::{vec, vec::Vec};
33use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
34use sp_api::impl_runtime_apis;
35pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
36use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
37use sp_runtime::{
38 create_runtime_str, generic, impl_opaque_keys,
39 traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
40 transaction_validity::{TransactionSource, TransactionValidity},
41 ApplyExtrinsicResult,
42};
43#[cfg(feature = "std")]
44use sp_version::NativeVersion;
45use sp_version::RuntimeVersion;
46
47pub use frame_support::{
49 construct_runtime, derive_impl,
50 dispatch::DispatchClass,
51 genesis_builder_helper::{build_state, get_preset},
52 parameter_types,
53 traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness},
54 weights::{
55 constants::{
56 BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
57 },
58 IdentityFee, Weight,
59 },
60 StorageValue,
61};
62use frame_system::limits::{BlockLength, BlockWeights};
63use parachains_common::{AccountId, Signature};
64#[cfg(any(feature = "std", test))]
65pub use sp_runtime::BuildStorage;
66pub use sp_runtime::{Perbill, Permill};
67
68impl_opaque_keys! {
69 pub struct SessionKeys {
70 pub aura: Aura,
71 }
72}
73
74#[sp_version::runtime_version]
76pub const VERSION: RuntimeVersion = RuntimeVersion {
77 spec_name: create_runtime_str!("seedling"),
78 impl_name: create_runtime_str!("seedling"),
79 authoring_version: 1,
80 spec_version: 1,
81 impl_version: 0,
82 apis: RUNTIME_API_VERSIONS,
83 transaction_version: 2,
84 state_version: 0,
85};
86
87#[cfg(feature = "std")]
89pub fn native_version() -> NativeVersion {
90 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
91}
92
93const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
96const BLOCK_PROCESSING_VELOCITY: u32 = 1;
99const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
101
102const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
105const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
108const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
110 WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
111 cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
112);
113
114parameter_types! {
115 pub const BlockHashCount: BlockNumber = 250;
116 pub const Version: RuntimeVersion = VERSION;
117 pub RuntimeBlockLength: BlockLength =
118 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
119 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
120 .base_block(BlockExecutionWeight::get())
121 .for_class(DispatchClass::all(), |weights| {
122 weights.base_extrinsic = ExtrinsicBaseWeight::get();
123 })
124 .for_class(DispatchClass::Normal, |weights| {
125 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
126 })
127 .for_class(DispatchClass::Operational, |weights| {
128 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
129 weights.reserved = Some(
132 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
133 );
134 })
135 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
136 .build_or_panic();
137 pub const SS58Prefix: u8 = 42;
138}
139
140#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
141impl frame_system::Config for Runtime {
142 type AccountId = AccountId;
144 type RuntimeCall = RuntimeCall;
146 type Lookup = AccountIdLookup<AccountId, ()>;
148 type Nonce = Nonce;
150 type Hash = Hash;
152 type Hashing = BlakeTwo256;
154 type Block = Block;
156 type RuntimeEvent = RuntimeEvent;
158 type RuntimeOrigin = RuntimeOrigin;
160 type BlockHashCount = BlockHashCount;
162 type Version = Version;
164 type PalletInfo = PalletInfo;
166 type AccountData = pallet_balances::AccountData<u128>;
167 type OnNewAccount = ();
168 type OnKilledAccount = ();
169 type DbWeight = ();
170 type BaseCallFilter = frame_support::traits::Everything;
171 type SystemWeightInfo = ();
172 type BlockWeights = RuntimeBlockWeights;
173 type BlockLength = RuntimeBlockLength;
174 type SS58Prefix = SS58Prefix;
175 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
176 type MaxConsumers = frame_support::traits::ConstU32<16>;
177}
178
179impl pallet_sudo::Config for Runtime {
180 type RuntimeCall = RuntimeCall;
181 type RuntimeEvent = RuntimeEvent;
182 type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
183}
184
185impl cumulus_pallet_solo_to_para::Config for Runtime {
186 type RuntimeEvent = RuntimeEvent;
187}
188
189impl cumulus_pallet_parachain_system::Config for Runtime {
190 type WeightInfo = ();
191 type RuntimeEvent = RuntimeEvent;
192 type OnSystemEvent = cumulus_pallet_solo_to_para::Pallet<Runtime>;
193 type SelfParaId = parachain_info::Pallet<Runtime>;
194 type OutboundXcmpMessageSource = ();
195 type DmpQueue = frame_support::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>;
197 type ReservedDmpWeight = ();
198 type XcmpMessageHandler = ();
199 type ReservedXcmpWeight = ();
200 type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
201 type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
202 Runtime,
203 RELAY_CHAIN_SLOT_DURATION_MILLIS,
204 BLOCK_PROCESSING_VELOCITY,
205 UNINCLUDED_SEGMENT_CAPACITY,
206 >;
207}
208
209impl parachain_info::Config for Runtime {}
210
211impl cumulus_pallet_aura_ext::Config for Runtime {}
212
213impl pallet_aura::Config for Runtime {
214 type AuthorityId = AuraId;
215 type DisabledValidators = ();
216 type MaxAuthorities = ConstU32<100_000>;
217 type AllowMultipleBlocksPerSlot = ConstBool<false>;
218 type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>;
219}
220
221impl pallet_timestamp::Config for Runtime {
222 type Moment = u64;
223 type OnTimestampSet = Aura;
224 type MinimumPeriod = ConstU64<0>;
225 type WeightInfo = ();
226}
227
228construct_runtime! {
229 pub enum Runtime
230 {
231 System: frame_system,
232 Sudo: pallet_sudo,
233 Timestamp: pallet_timestamp,
234
235 ParachainSystem: cumulus_pallet_parachain_system,
236 ParachainInfo: parachain_info,
237 SoloToPara: cumulus_pallet_solo_to_para,
238 Aura: pallet_aura,
239 AuraExt: cumulus_pallet_aura_ext,
240 }
241}
242
243pub type Nonce = u32;
245pub type Hash = sp_core::H256;
247pub type BlockNumber = u32;
249pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
251pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
253pub type Block = generic::Block<Header, UncheckedExtrinsic>;
255pub type SignedBlock = generic::SignedBlock<Block>;
257pub type BlockId = generic::BlockId<Block>;
259pub type SignedExtra = (
261 frame_system::CheckSpecVersion<Runtime>,
262 frame_system::CheckTxVersion<Runtime>,
263 frame_system::CheckGenesis<Runtime>,
264 frame_system::CheckEra<Runtime>,
265 frame_system::CheckNonce<Runtime>,
266 pallet_sudo::CheckOnlySudoAccount<Runtime>,
267);
268pub type UncheckedExtrinsic =
270 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
271
272pub type Executive = frame_executive::Executive<
274 Runtime,
275 Block,
276 frame_system::ChainContext<Runtime>,
277 Runtime,
278 AllPalletsWithSystem,
279>;
280
281impl_runtime_apis! {
282 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
283 fn slot_duration() -> sp_consensus_aura::SlotDuration {
284 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
285 }
286
287 fn authorities() -> Vec<AuraId> {
288 pallet_aura::Authorities::<Runtime>::get().into_inner()
289 }
290 }
291
292 impl sp_api::Core<Block> for Runtime {
293 fn version() -> RuntimeVersion {
294 VERSION
295 }
296
297 fn execute_block(block: Block) {
298 Executive::execute_block(block)
299 }
300
301 fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
302 Executive::initialize_block(header)
303 }
304 }
305
306 impl sp_api::Metadata<Block> for Runtime {
307 fn metadata() -> OpaqueMetadata {
308 OpaqueMetadata::new(Runtime::metadata().into())
309 }
310
311 fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
312 Runtime::metadata_at_version(version)
313 }
314
315 fn metadata_versions() -> alloc::vec::Vec<u32> {
316 Runtime::metadata_versions()
317 }
318 }
319
320 impl sp_block_builder::BlockBuilder<Block> for Runtime {
321 fn apply_extrinsic(
322 extrinsic: <Block as BlockT>::Extrinsic,
323 ) -> ApplyExtrinsicResult {
324 Executive::apply_extrinsic(extrinsic)
325 }
326
327 fn finalize_block() -> <Block as BlockT>::Header {
328 Executive::finalize_block()
329 }
330
331 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
332 data.create_extrinsics()
333 }
334
335 fn check_inherents(block: Block, data: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
336 data.check_extrinsics(&block)
337 }
338 }
339
340 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
341 fn validate_transaction(
342 source: TransactionSource,
343 tx: <Block as BlockT>::Extrinsic,
344 block_hash: <Block as BlockT>::Hash,
345 ) -> TransactionValidity {
346 Executive::validate_transaction(source, tx, block_hash)
347 }
348 }
349
350 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
351 fn offchain_worker(header: &<Block as BlockT>::Header) {
352 Executive::offchain_worker(header)
353 }
354 }
355
356 impl sp_session::SessionKeys<Block> for Runtime {
357 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
358 SessionKeys::generate(seed)
359 }
360
361 fn decode_session_keys(
362 encoded: Vec<u8>,
363 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
364 SessionKeys::decode_into_raw_public_keys(&encoded)
365 }
366 }
367
368 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
369 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
370 ParachainSystem::collect_collation_info(header)
371 }
372 }
373
374 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
375 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
376 build_state::<RuntimeGenesisConfig>(config)
377 }
378
379 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
380 get_preset::<RuntimeGenesisConfig>(id, |_| None)
381 }
382
383 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
384 vec![]
385 }
386 }
387}
388
389cumulus_pallet_parachain_system::register_validate_block! {
390 Runtime = Runtime,
391 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
392}