1#![cfg_attr(not(feature = "std"), no_std)]
41#![recursion_limit = "256"]
42
43#[cfg(feature = "std")]
45include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
46
47pub mod genesis_config_presets;
48pub mod weights;
49pub mod xcm_config;
50
51extern crate alloc;
52
53use alloc::{vec, vec::Vec};
54use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
55use sp_api::impl_runtime_apis;
56pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
57use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
58use sp_runtime::{
59 generic, impl_opaque_keys,
60 traits::{BlakeTwo256, Block as BlockT},
61 transaction_validity::{TransactionSource, TransactionValidity},
62 ApplyExtrinsicResult,
63};
64use sp_session::OpaqueGeneratedSessionKeys;
65#[cfg(feature = "std")]
66use sp_version::NativeVersion;
67use sp_version::RuntimeVersion;
68
69use cumulus_primitives_core::{AggregateMessageOrigin, ParaId, VerifySchedulingSignature};
70pub use frame_support::{
71 construct_runtime, derive_impl,
72 dispatch::DispatchClass,
73 genesis_builder_helper::{build_state, get_preset},
74 parameter_types,
75 traits::{
76 ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, IsInVec, Randomness,
77 },
78 weights::{
79 constants::{
80 BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
81 },
82 IdentityFee, Weight,
83 },
84 PalletId, StorageValue,
85};
86use frame_system::{
87 limits::{BlockLength, BlockWeights},
88 EnsureRoot,
89};
90use parachains_common::{AccountId, Signature};
91#[cfg(any(feature = "std", test))]
92pub use sp_runtime::BuildStorage;
93pub use sp_runtime::{Perbill, Permill};
94use testnet_parachains_constants::westend::consensus::*;
95
96impl_opaque_keys! {
97 pub struct SessionKeys {
98 pub aura: Aura,
99 }
100}
101
102#[sp_version::runtime_version]
103pub const VERSION: RuntimeVersion = RuntimeVersion {
104 spec_name: alloc::borrow::Cow::Borrowed("glutton-westend"),
105 impl_name: alloc::borrow::Cow::Borrowed("glutton-westend"),
106 authoring_version: 1,
107 spec_version: 1_024_001,
108 impl_version: 0,
109 apis: RUNTIME_API_VERSIONS,
110 transaction_version: 1,
111 system_version: 1,
112};
113
114#[cfg(feature = "std")]
116pub fn native_version() -> NativeVersion {
117 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
118}
119
120const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
123const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
126
127parameter_types! {
128 pub const BlockHashCount: BlockNumber = 4096;
129 pub const Version: RuntimeVersion = VERSION;
130 pub RuntimeBlockLength: BlockLength = BlockLength::builder()
131 .max_length(5 * 1024 * 1024)
132 .modify_max_length_for_class(DispatchClass::Normal, |m| {
133 *m = NORMAL_DISPATCH_RATIO * *m
134 })
135 .build();
136 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
137 .base_block(BlockExecutionWeight::get())
138 .for_class(DispatchClass::all(), |weights| {
139 weights.base_extrinsic = ExtrinsicBaseWeight::get();
140 })
141 .for_class(DispatchClass::Normal, |weights| {
142 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
143 })
144 .for_class(DispatchClass::Operational, |weights| {
145 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
146 weights.reserved = Some(
149 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
150 );
151 })
152 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
153 .build_or_panic();
154 pub const SS58Prefix: u8 = 42;
155}
156
157#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig)]
158impl frame_system::Config for Runtime {
159 type AccountId = AccountId;
160 type Nonce = Nonce;
161 type Hash = Hash;
162 type Block = Block;
163 type BlockHashCount = BlockHashCount;
164 type Version = Version;
165 type BlockWeights = RuntimeBlockWeights;
166 type BlockLength = RuntimeBlockLength;
167 type SS58Prefix = SS58Prefix;
168 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
169 type MaxConsumers = frame_support::traits::ConstU32<16>;
170}
171
172parameter_types! {
173 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(2);
175 pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
176}
177
178const RELAY_PARENT_OFFSET: u32 = 1;
180
181const BLOCK_PROCESSING_VELOCITY: u32 = 3;
186
187const UNINCLUDED_SEGMENT_CAPACITY: u32 = (3 + RELAY_PARENT_OFFSET) * BLOCK_PROCESSING_VELOCITY;
190
191type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
192 Runtime,
193 RELAY_CHAIN_SLOT_DURATION_MILLIS,
194 BLOCK_PROCESSING_VELOCITY,
195 UNINCLUDED_SEGMENT_CAPACITY,
196>;
197
198impl cumulus_pallet_parachain_system::Config for Runtime {
199 type RuntimeEvent = RuntimeEvent;
200 type OnSystemEvent = ();
201 type SelfParaId = parachain_info::Pallet<Runtime>;
202 type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
203 type OutboundXcmpMessageSource = ();
204 type ReservedDmpWeight = ReservedDmpWeight;
205 type XcmpMessageHandler = ();
206 type ReservedXcmpWeight = ();
207 type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
208 type ConsensusHook = ConsensusHook;
209 type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
210 type RelayParentOffset = ConstU32<RELAY_PARENT_OFFSET>;
211 type SchedulingSignatureVerifier = ();
212}
213
214parameter_types! {
215 pub MessageQueueServiceWeight: Weight = Perbill::from_percent(80) *
216 RuntimeBlockWeights::get().max_block;
217}
218
219impl pallet_message_queue::Config for Runtime {
220 type RuntimeEvent = RuntimeEvent;
221 type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
222 #[cfg(feature = "runtime-benchmarks")]
223 type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor<
224 cumulus_primitives_core::AggregateMessageOrigin,
225 >;
226 #[cfg(not(feature = "runtime-benchmarks"))]
227 type MessageProcessor = xcm_builder::ProcessXcmMessage<
228 AggregateMessageOrigin,
229 xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
230 RuntimeCall,
231 >;
232 type Size = u32;
233 type QueueChangeHandler = ();
234 type QueuePausedQuery = ();
236 type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
237 type MaxStale = sp_core::ConstU32<8>;
238 type ServiceWeight = MessageQueueServiceWeight;
239 type IdleMaxServiceWeight = MessageQueueServiceWeight;
240}
241
242impl parachain_info::Config for Runtime {}
243
244impl cumulus_pallet_aura_ext::Config for Runtime {}
245
246impl pallet_timestamp::Config for Runtime {
247 type Moment = u64;
248 type OnTimestampSet = Aura;
249 type MinimumPeriod = ConstU64<0>;
250 type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
251}
252
253impl pallet_aura::Config for Runtime {
254 type AuthorityId = AuraId;
255 type DisabledValidators = ();
256 type MaxAuthorities = ConstU32<100_000>;
257 type AllowMultipleBlocksPerSlot = ConstBool<true>;
258 type SlotDuration = ConstU64<SLOT_DURATION>;
259}
260
261impl pallet_glutton::Config for Runtime {
262 type RuntimeEvent = RuntimeEvent;
263 type WeightInfo = weights::pallet_glutton::WeightInfo<Runtime>;
264 type AdminOrigin = EnsureRoot<AccountId>;
265}
266
267impl pallet_sudo::Config for Runtime {
268 type RuntimeEvent = RuntimeEvent;
269 type RuntimeCall = RuntimeCall;
270 type WeightInfo = ();
271}
272
273construct_runtime! {
274 pub enum Runtime
275 {
276 System: frame_system = 0,
277 ParachainSystem: cumulus_pallet_parachain_system = 1,
278 ParachainInfo: parachain_info = 2,
279 Timestamp: pallet_timestamp = 3,
280
281 CumulusXcm: cumulus_pallet_xcm = 10,
283 MessageQueue: pallet_message_queue = 11,
284
285 Glutton: pallet_glutton = 20,
287
288 Aura: pallet_aura = 30,
290 AuraExt: cumulus_pallet_aura_ext = 31,
291
292 Sudo: pallet_sudo = 255,
294 }
295}
296
297pub type Nonce = u32;
299pub type Hash = sp_core::H256;
301pub type BlockNumber = u32;
303pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
305pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
307pub type Block = generic::Block<Header, UncheckedExtrinsic>;
309pub type SignedBlock = generic::SignedBlock<Block>;
311pub type BlockId = generic::BlockId<Block>;
313pub type TxExtension = (
315 frame_system::AuthorizeCall<Runtime>,
316 pallet_sudo::CheckOnlySudoAccount<Runtime>,
317 frame_system::CheckNonZeroSender<Runtime>,
318 frame_system::CheckSpecVersion<Runtime>,
319 frame_system::CheckTxVersion<Runtime>,
320 frame_system::CheckGenesis<Runtime>,
321 frame_system::CheckEra<Runtime>,
322 frame_system::CheckWeight<Runtime>,
323 frame_system::WeightReclaim<Runtime>,
324);
325pub type UncheckedExtrinsic =
327 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
328pub type Executive = frame_executive::Executive<
330 Runtime,
331 Block,
332 frame_system::ChainContext<Runtime>,
333 Runtime,
334 AllPalletsWithSystem,
335>;
336
337#[cfg(feature = "runtime-benchmarks")]
338mod benches {
339 frame_benchmarking::define_benchmarks!(
340 [cumulus_pallet_parachain_system, ParachainSystem]
341 [frame_system, SystemBench::<Runtime>]
342 [frame_system_extensions, SystemExtensionsBench::<Runtime>]
343 [pallet_glutton, Glutton]
344 [pallet_message_queue, MessageQueue]
345 [pallet_timestamp, Timestamp]
346 );
347}
348
349impl_runtime_apis! {
350 impl sp_api::Core<Block> for Runtime {
351 fn version() -> RuntimeVersion {
352 VERSION
353 }
354
355 fn execute_block(block: <Block as BlockT>::LazyBlock) {
356 Executive::execute_block(block)
357 }
358
359 fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
360 Executive::initialize_block(header)
361 }
362 }
363
364 impl sp_api::Metadata<Block> for Runtime {
365 fn metadata() -> OpaqueMetadata {
366 OpaqueMetadata::new(Runtime::metadata().into())
367 }
368
369 fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
370 Runtime::metadata_at_version(version)
371 }
372
373 fn metadata_versions() -> alloc::vec::Vec<u32> {
374 Runtime::metadata_versions()
375 }
376 }
377
378 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
379 fn slot_duration() -> sp_consensus_aura::SlotDuration {
380 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
381 }
382
383 fn authorities() -> Vec<AuraId> {
384 pallet_aura::Authorities::<Runtime>::get().into_inner()
385 }
386 }
387
388 impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
389 fn relay_parent_offset() -> u32 {
390 RELAY_PARENT_OFFSET
391 }
392
393 fn max_claim_queue_offset() -> u8 {
394 cumulus_pallet_parachain_system::Pallet::<Runtime>::max_claim_queue_offset()
395 }
396 }
397
398 impl cumulus_primitives_core::SchedulingV3EnabledApi<Block> for Runtime {
399 fn scheduling_v3_enabled() -> bool {
400 <Runtime as cumulus_pallet_parachain_system::Config>::SchedulingSignatureVerifier::V3_SCHEDULING_ENABLED
401 }
402 }
403
404 impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
405 fn can_build_upon(
406 included_hash: <Block as BlockT>::Hash,
407 slot: cumulus_primitives_aura::Slot,
408 ) -> bool {
409 ConsensusHook::can_build_upon(included_hash, slot)
410 }
411 }
412
413 impl sp_block_builder::BlockBuilder<Block> for Runtime {
414 fn apply_extrinsic(
415 extrinsic: <Block as BlockT>::Extrinsic,
416 ) -> ApplyExtrinsicResult {
417 Executive::apply_extrinsic(extrinsic)
418 }
419
420 fn finalize_block() -> <Block as BlockT>::Header {
421 Executive::finalize_block()
422 }
423
424 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
425 data.create_extrinsics()
426 }
427
428 fn check_inherents(block: <Block as BlockT>::LazyBlock, data: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
429 data.check_extrinsics(&block)
430 }
431 }
432
433 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
434 fn validate_transaction(
435 source: TransactionSource,
436 tx: <Block as BlockT>::Extrinsic,
437 block_hash: <Block as BlockT>::Hash,
438 ) -> TransactionValidity {
439 Executive::validate_transaction(source, tx, block_hash)
440 }
441 }
442
443 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
444 fn offchain_worker(header: &<Block as BlockT>::Header) {
445 Executive::offchain_worker(header)
446 }
447 }
448
449 impl sp_session::SessionKeys<Block> for Runtime {
450 fn generate_session_keys(owner: Vec<u8>, seed: Option<Vec<u8>>) -> OpaqueGeneratedSessionKeys {
451 SessionKeys::generate(&owner, seed).into()
452 }
453
454 fn decode_session_keys(
455 encoded: Vec<u8>,
456 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
457 SessionKeys::decode_into_raw_public_keys(&encoded)
458 }
459 }
460
461 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
462 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
463 ParachainSystem::collect_collation_info(header)
464 }
465 }
466
467 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
468 fn account_nonce(account: AccountId) -> Nonce {
469 System::account_nonce(account)
470 }
471 }
472
473 #[cfg(feature = "runtime-benchmarks")]
474 impl frame_benchmarking::Benchmark<Block> for Runtime {
475 fn benchmark_metadata(extra: bool) -> (
476 Vec<frame_benchmarking::BenchmarkList>,
477 Vec<frame_support::traits::StorageInfo>,
478 ) {
479 use frame_benchmarking::BenchmarkList;
480 use frame_support::traits::StorageInfoTrait;
481 use frame_system_benchmarking::Pallet as SystemBench;
482 use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
483
484 let mut list = Vec::<BenchmarkList>::new();
485 list_benchmarks!(list, extra);
486
487 let storage_info = AllPalletsWithSystem::storage_info();
488
489 (list, storage_info)
490 }
491
492 #[allow(non_local_definitions)]
493 fn dispatch_benchmark(
494 config: frame_benchmarking::BenchmarkConfig
495 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
496 use frame_benchmarking::{BenchmarkBatch, BenchmarkError};
497 use sp_storage::TrackedStorageKey;
498
499 use frame_system_benchmarking::Pallet as SystemBench;
500 use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
501 impl frame_system_benchmarking::Config for Runtime {
502 fn setup_set_code_requirements(code: &alloc::vec::Vec<u8>) -> Result<(), BenchmarkError> {
503 ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
504 Ok(())
505 }
506
507 fn verify_set_code() {
508 System::assert_last_event(cumulus_pallet_parachain_system::Event::<Runtime>::ValidationFunctionStored.into());
509 }
510 }
511
512 use frame_support::traits::WhitelistedStorageKeys;
513 let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
514
515 let mut batches = Vec::<BenchmarkBatch>::new();
516 let params = (&config, &whitelist);
517 add_benchmarks!(params, batches);
518 Ok(batches)
519 }
520 }
521
522 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
523 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
524 build_state::<RuntimeGenesisConfig>(config)
525 }
526
527 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
528 get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
529 }
530
531 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
532 genesis_config_presets::preset_names()
533 }
534 }
535
536 impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
537 fn parachain_id() -> ParaId {
538 ParachainInfo::parachain_id()
539 }
540 }
541
542 impl cumulus_primitives_core::TargetBlockRate<Block> for Runtime {
543 fn target_block_rate() -> u32 {
544 BLOCK_PROCESSING_VELOCITY
545 }
546 }
547}
548
549cumulus_pallet_parachain_system::register_validate_block! {
550 Runtime = Runtime,
551 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
552}