parachain_template_runtime/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
2#![recursion_limit = "256"]
4
5#[cfg(feature = "std")]
7include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
8
9pub mod apis;
10#[cfg(feature = "runtime-benchmarks")]
11mod benchmarks;
12pub mod configs;
13mod genesis_config_presets;
14mod weights;
15
16extern crate alloc;
17use alloc::vec::Vec;
18use smallvec::smallvec;
19
20use polkadot_sdk::{staging_parachain_info as parachain_info, *};
21
22use sp_runtime::{
23 generic, impl_opaque_keys,
24 traits::{BlakeTwo256, IdentifyAccount, Verify},
25 MultiSignature,
26};
27
28#[cfg(feature = "std")]
29use sp_version::NativeVersion;
30use sp_version::RuntimeVersion;
31
32use frame_support::weights::{
33 constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
34 WeightToFeePolynomial,
35};
36pub use genesis_config_presets::PARACHAIN_ID;
37pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
38pub use sp_runtime::{MultiAddress, Perbill, Permill};
39
40use weights::ExtrinsicBaseWeight;
41
42pub type Signature = MultiSignature;
44
45pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
48
49pub type Balance = u128;
51
52pub type Nonce = u32;
54
55pub type Hash = sp_core::H256;
57
58pub type BlockNumber = u32;
60
61pub type Address = MultiAddress<AccountId, ()>;
63
64pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
66
67pub type Block = generic::Block<Header, UncheckedExtrinsic>;
69
70pub type SignedBlock = generic::SignedBlock<Block>;
72
73pub type BlockId = generic::BlockId<Block>;
75
76#[docify::export(template_signed_extra)]
78pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim<
79 Runtime,
80 (
81 frame_system::AuthorizeCall<Runtime>,
82 frame_system::CheckNonZeroSender<Runtime>,
83 frame_system::CheckSpecVersion<Runtime>,
84 frame_system::CheckTxVersion<Runtime>,
85 frame_system::CheckGenesis<Runtime>,
86 frame_system::CheckEra<Runtime>,
87 frame_system::CheckNonce<Runtime>,
88 frame_system::CheckWeight<Runtime>,
89 pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
90 frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
91 ),
92>;
93
94pub type UncheckedExtrinsic =
96 generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
97
98pub type Executive = frame_executive::Executive<
100 Runtime,
101 Block,
102 frame_system::ChainContext<Runtime>,
103 Runtime,
104 AllPalletsWithSystem,
105>;
106
107pub struct WeightToFee;
118impl WeightToFeePolynomial for WeightToFee {
119 type Balance = Balance;
120 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
121 let p = MILLI_UNIT / 10;
124 let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
125 smallvec![WeightToFeeCoefficient {
126 degree: 1,
127 negative: false,
128 coeff_frac: Perbill::from_rational(p % q, q),
129 coeff_integer: p / q,
130 }]
131 }
132}
133
134pub mod opaque {
139 use super::*;
140 pub use polkadot_sdk::sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
141 use polkadot_sdk::sp_runtime::{
142 generic,
143 traits::{BlakeTwo256, Hash as HashT},
144 };
145
146 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
148 pub type Block = generic::Block<Header, UncheckedExtrinsic>;
150 pub type BlockId = generic::BlockId<Block>;
152 pub type Hash = <BlakeTwo256 as HashT>::Output;
154}
155
156impl_opaque_keys! {
157 pub struct SessionKeys {
158 pub aura: Aura,
159 }
160}
161
162#[sp_version::runtime_version]
163pub const VERSION: RuntimeVersion = RuntimeVersion {
164 spec_name: alloc::borrow::Cow::Borrowed("parachain-template-runtime"),
165 impl_name: alloc::borrow::Cow::Borrowed("parachain-template-runtime"),
166 authoring_version: 1,
167 spec_version: 1,
168 impl_version: 0,
169 apis: apis::RUNTIME_API_VERSIONS,
170 transaction_version: 1,
171 system_version: 1,
172};
173
174#[docify::export]
175mod block_times {
176 pub const MILLI_SECS_PER_BLOCK: u64 = 6000;
183
184 pub const SLOT_DURATION: u64 = MILLI_SECS_PER_BLOCK;
187}
188pub use block_times::*;
189
190pub const MINUTES: BlockNumber = 60_000 / (MILLI_SECS_PER_BLOCK as BlockNumber);
192pub const HOURS: BlockNumber = MINUTES * 60;
193pub const DAYS: BlockNumber = HOURS * 24;
194
195pub const UNIT: Balance = 1_000_000_000_000;
197pub const MILLI_UNIT: Balance = 1_000_000_000;
198pub const MICRO_UNIT: Balance = 1_000_000;
199
200pub const EXISTENTIAL_DEPOSIT: Balance = MILLI_UNIT;
202
203const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
206
207const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
210
211#[docify::export(max_block_weight)]
212const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
214 WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
215 cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
216);
217
218#[docify::export]
219mod async_backing_params {
220 pub(crate) const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
223 pub(crate) const BLOCK_PROCESSING_VELOCITY: u32 = 1;
226 pub(crate) const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
228}
229pub(crate) use async_backing_params::*;
230
231#[docify::export]
232type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
234 Runtime,
235 RELAY_CHAIN_SLOT_DURATION_MILLIS,
236 BLOCK_PROCESSING_VELOCITY,
237 UNINCLUDED_SEGMENT_CAPACITY,
238>;
239
240#[cfg(feature = "std")]
242pub fn native_version() -> NativeVersion {
243 NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
244}
245
246#[frame_support::runtime]
248mod runtime {
249 #[runtime::runtime]
250 #[runtime::derive(
251 RuntimeCall,
252 RuntimeEvent,
253 RuntimeError,
254 RuntimeOrigin,
255 RuntimeFreezeReason,
256 RuntimeHoldReason,
257 RuntimeSlashReason,
258 RuntimeLockId,
259 RuntimeTask,
260 RuntimeViewFunction
261 )]
262 pub struct Runtime;
263
264 #[runtime::pallet_index(0)]
265 pub type System = frame_system;
266 #[runtime::pallet_index(1)]
267 pub type ParachainSystem = cumulus_pallet_parachain_system;
268 #[runtime::pallet_index(2)]
269 pub type Timestamp = pallet_timestamp;
270 #[runtime::pallet_index(3)]
271 pub type ParachainInfo = parachain_info;
272 #[runtime::pallet_index(4)]
273 pub type WeightReclaim = cumulus_pallet_weight_reclaim;
274
275 #[runtime::pallet_index(10)]
277 pub type Balances = pallet_balances;
278 #[runtime::pallet_index(11)]
279 pub type TransactionPayment = pallet_transaction_payment;
280
281 #[runtime::pallet_index(15)]
283 pub type Sudo = pallet_sudo;
284
285 #[runtime::pallet_index(20)]
287 pub type Authorship = pallet_authorship;
288 #[runtime::pallet_index(21)]
289 pub type CollatorSelection = pallet_collator_selection;
290 #[runtime::pallet_index(22)]
291 pub type Session = pallet_session;
292 #[runtime::pallet_index(23)]
293 pub type Aura = pallet_aura;
294 #[runtime::pallet_index(24)]
295 pub type AuraExt = cumulus_pallet_aura_ext;
296
297 #[runtime::pallet_index(30)]
299 pub type XcmpQueue = cumulus_pallet_xcmp_queue;
300 #[runtime::pallet_index(31)]
301 pub type PolkadotXcm = pallet_xcm;
302 #[runtime::pallet_index(32)]
303 pub type CumulusXcm = cumulus_pallet_xcm;
304 #[runtime::pallet_index(33)]
305 pub type MessageQueue = pallet_message_queue;
306
307 #[runtime::pallet_index(50)]
309 pub type TemplatePallet = pallet_parachain_template;
310}
311
312#[docify::export(register_validate_block)]
313cumulus_pallet_parachain_system::register_validate_block! {
314 Runtime = Runtime,
315 BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
316}