1#![cfg_attr(not(feature = "std"), no_std)]
25#![recursion_limit = "256"]
27
28#[cfg(feature = "std")]
30include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
31
32pub mod xcm_config;
33
34extern crate alloc;
35
36use alloc::{vec, vec::Vec};
37use codec::{Decode, Encode};
38use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
39use cumulus_primitives_core::AggregateMessageOrigin;
40use frame_support::unsigned::TransactionValidityError;
41use scale_info::TypeInfo;
42use sp_api::impl_runtime_apis;
43pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
44use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
45use sp_runtime::{
46 create_runtime_str, generic, impl_opaque_keys,
47 traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf},
48 transaction_validity::{TransactionSource, TransactionValidity},
49 ApplyExtrinsicResult,
50};
51#[cfg(feature = "std")]
52use sp_version::NativeVersion;
53use sp_version::RuntimeVersion;
54
55pub use frame_support::{
57 construct_runtime, derive_impl,
58 dispatch::DispatchClass,
59 genesis_builder_helper::{build_state, get_preset},
60 parameter_types,
61 traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness},
62 weights::{
63 constants::{
64 BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
65 },
66 IdentityFee, Weight,
67 },
68 StorageValue,
69};
70use frame_system::limits::{BlockLength, BlockWeights};
71use parachains_common::{AccountId, Signature};
72#[cfg(any(feature = "std", test))]
73pub use sp_runtime::BuildStorage;
74pub use sp_runtime::{Perbill, Permill};
75
76impl_opaque_keys! {
77 pub struct SessionKeys {
78 pub aura: Aura,
79 }
80}
81
82#[sp_version::runtime_version]
84pub const VERSION: RuntimeVersion = RuntimeVersion {
85 spec_name: create_runtime_str!("shell"),
86 impl_name: create_runtime_str!("shell"),
87 authoring_version: 1,
88 spec_version: 2,
89 impl_version: 0,
90 apis: RUNTIME_API_VERSIONS,
91 transaction_version: 1,
92 state_version: 0,
93};
94
95#[cfg(feature = "std")]
97pub fn native_version() -> NativeVersion {
98 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
99}
100
101const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
104const BLOCK_PROCESSING_VELOCITY: u32 = 1;
107const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
109
110const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
113const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
116const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
118 WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
119 cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
120);
121
122parameter_types! {
123 pub const BlockHashCount: BlockNumber = 250;
124 pub const Version: RuntimeVersion = VERSION;
125 pub RuntimeBlockLength: BlockLength =
126 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
127 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
128 .base_block(BlockExecutionWeight::get())
129 .for_class(DispatchClass::all(), |weights| {
130 weights.base_extrinsic = ExtrinsicBaseWeight::get();
131 })
132 .for_class(DispatchClass::Normal, |weights| {
133 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
134 })
135 .for_class(DispatchClass::Operational, |weights| {
136 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
137 weights.reserved = Some(
140 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
141 );
142 })
143 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
144 .build_or_panic();
145 pub const SS58Prefix: u8 = 42;
146}
147
148#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
149impl frame_system::Config for Runtime {
150 type AccountId = AccountId;
152 type RuntimeCall = RuntimeCall;
154 type Lookup = AccountIdLookup<AccountId, ()>;
156 type Nonce = Nonce;
158 type Hash = Hash;
160 type Hashing = BlakeTwo256;
162 type Block = Block;
164 type RuntimeEvent = RuntimeEvent;
166 type RuntimeOrigin = RuntimeOrigin;
168 type BlockHashCount = BlockHashCount;
170 type Version = Version;
172 type PalletInfo = PalletInfo;
174 type AccountData = ();
175 type OnNewAccount = ();
176 type OnKilledAccount = ();
177 type DbWeight = ();
178 type BaseCallFilter = frame_support::traits::Everything;
179 type SystemWeightInfo = ();
180 type BlockWeights = RuntimeBlockWeights;
181 type BlockLength = RuntimeBlockLength;
182 type SS58Prefix = SS58Prefix;
183 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
184 type MaxConsumers = frame_support::traits::ConstU32<16>;
185}
186
187parameter_types! {
188 pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
189 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
190}
191
192impl cumulus_pallet_parachain_system::Config for Runtime {
193 type WeightInfo = ();
194 type RuntimeEvent = RuntimeEvent;
195 type OnSystemEvent = ();
196 type SelfParaId = parachain_info::Pallet<Runtime>;
197 type OutboundXcmpMessageSource = ();
198 type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
199 type ReservedDmpWeight = ReservedDmpWeight;
200 type XcmpMessageHandler = ();
201 type ReservedXcmpWeight = ();
202 type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
203 type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
204 Runtime,
205 RELAY_CHAIN_SLOT_DURATION_MILLIS,
206 BLOCK_PROCESSING_VELOCITY,
207 UNINCLUDED_SEGMENT_CAPACITY,
208 >;
209}
210
211impl parachain_info::Config for Runtime {}
212
213parameter_types! {
214 pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
215}
216
217impl pallet_message_queue::Config for Runtime {
218 type RuntimeEvent = RuntimeEvent;
219 type WeightInfo = ();
220 #[cfg(feature = "runtime-benchmarks")]
221 type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor<
222 cumulus_primitives_core::AggregateMessageOrigin,
223 >;
224 #[cfg(not(feature = "runtime-benchmarks"))]
225 type MessageProcessor = xcm_builder::ProcessXcmMessage<
226 AggregateMessageOrigin,
227 xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
228 RuntimeCall,
229 >;
230 type Size = u32;
231 type QueueChangeHandler = ();
233 type QueuePausedQuery = ();
234 type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
235 type MaxStale = sp_core::ConstU32<8>;
236 type ServiceWeight = MessageQueueServiceWeight;
237 type IdleMaxServiceWeight = MessageQueueServiceWeight;
238}
239
240impl cumulus_pallet_aura_ext::Config for Runtime {}
241
242impl pallet_aura::Config for Runtime {
243 type AuthorityId = AuraId;
244 type DisabledValidators = ();
245 type MaxAuthorities = ConstU32<100_000>;
246 type AllowMultipleBlocksPerSlot = ConstBool<false>;
247 type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>;
248}
249
250impl pallet_timestamp::Config for Runtime {
251 type Moment = u64;
252 type OnTimestampSet = Aura;
253 type MinimumPeriod = ConstU64<0>;
254 type WeightInfo = ();
255}
256
257construct_runtime! {
258 pub enum Runtime
259 {
260 System: frame_system,
261 Timestamp: pallet_timestamp,
262
263 ParachainSystem: cumulus_pallet_parachain_system,
264 ParachainInfo: parachain_info,
265
266 CumulusXcm: cumulus_pallet_xcm,
267 MessageQueue: pallet_message_queue,
268
269 Aura: pallet_aura,
270 AuraExt: cumulus_pallet_aura_ext,
271 }
272}
273
274#[derive(Eq, PartialEq, Clone, Default, sp_core::RuntimeDebug, Encode, Decode, TypeInfo)]
276pub struct DisallowSigned;
277impl sp_runtime::traits::SignedExtension for DisallowSigned {
278 const IDENTIFIER: &'static str = "DisallowSigned";
279 type AccountId = AccountId;
280 type Call = RuntimeCall;
281 type AdditionalSigned = ();
282 type Pre = ();
283 fn additional_signed(
284 &self,
285 ) -> core::result::Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
286 Ok(())
287 }
288 fn pre_dispatch(
289 self,
290 who: &Self::AccountId,
291 call: &Self::Call,
292 info: &DispatchInfoOf<Self::Call>,
293 len: usize,
294 ) -> Result<Self::Pre, TransactionValidityError> {
295 self.validate(who, call, info, len).map(|_| ())
296 }
297 fn validate(
298 &self,
299 _who: &Self::AccountId,
300 _call: &Self::Call,
301 _info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
302 _len: usize,
303 ) -> TransactionValidity {
304 let i = sp_runtime::transaction_validity::InvalidTransaction::BadProof;
305 Err(sp_runtime::transaction_validity::TransactionValidityError::Invalid(i))
306 }
307}
308
309pub type Nonce = u32;
311pub type Hash = sp_core::H256;
313pub type BlockNumber = u32;
315pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
317pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
319pub type Block = generic::Block<Header, UncheckedExtrinsic>;
321pub type SignedBlock = generic::SignedBlock<Block>;
323pub type BlockId = generic::BlockId<Block>;
325pub type SignedExtra = DisallowSigned;
327pub type UncheckedExtrinsic =
329 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
330pub type Executive = frame_executive::Executive<
332 Runtime,
333 Block,
334 frame_system::ChainContext<Runtime>,
335 Runtime,
336 AllPalletsWithSystem,
337>;
338
339impl_runtime_apis! {
340 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
341 fn slot_duration() -> sp_consensus_aura::SlotDuration {
342 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
343 }
344
345 fn authorities() -> Vec<AuraId> {
346 pallet_aura::Authorities::<Runtime>::get().into_inner()
347 }
348 }
349
350 impl sp_api::Core<Block> for Runtime {
351 fn version() -> RuntimeVersion {
352 VERSION
353 }
354
355 fn execute_block(block: Block) {
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_block_builder::BlockBuilder<Block> for Runtime {
379 fn apply_extrinsic(
380 extrinsic: <Block as BlockT>::Extrinsic,
381 ) -> ApplyExtrinsicResult {
382 Executive::apply_extrinsic(extrinsic)
383 }
384
385 fn finalize_block() -> <Block as BlockT>::Header {
386 Executive::finalize_block()
387 }
388
389 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
390 data.create_extrinsics()
391 }
392
393 fn check_inherents(block: Block, data: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
394 data.check_extrinsics(&block)
395 }
396 }
397
398 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
399 fn validate_transaction(
400 source: TransactionSource,
401 tx: <Block as BlockT>::Extrinsic,
402 block_hash: <Block as BlockT>::Hash,
403 ) -> TransactionValidity {
404 Executive::validate_transaction(source, tx, block_hash)
405 }
406 }
407
408 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
409 fn offchain_worker(header: &<Block as BlockT>::Header) {
410 Executive::offchain_worker(header)
411 }
412 }
413
414 impl sp_session::SessionKeys<Block> for Runtime {
415 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
416 SessionKeys::generate(seed)
417 }
418
419 fn decode_session_keys(
420 encoded: Vec<u8>,
421 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
422 SessionKeys::decode_into_raw_public_keys(&encoded)
423 }
424 }
425
426 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
427 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
428 ParachainSystem::collect_collation_info(header)
429 }
430 }
431
432 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
433 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
434 build_state::<RuntimeGenesisConfig>(config)
435 }
436
437 fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
438 get_preset::<RuntimeGenesisConfig>(id, |_| None)
439 }
440
441 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
442 vec![]
443 }
444 }
445}
446
447cumulus_pallet_parachain_system::register_validate_block! {
448 Runtime = Runtime,
449 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
450}