referrerpolicy=no-referrer-when-downgrade

parachain_template_runtime/configs/
mod.rs

1// This is free and unencumbered software released into the public domain.
2//
3// Anyone is free to copy, modify, publish, use, compile, sell, or
4// distribute this software, either in source code form or as a compiled
5// binary, for any purpose, commercial or non-commercial, and by any
6// means.
7//
8// In jurisdictions that recognize copyright laws, the author or authors
9// of this software dedicate any and all copyright interest in the
10// software to the public domain. We make this dedication for the benefit
11// of the public at large and to the detriment of our heirs and
12// successors. We intend this dedication to be an overt act of
13// relinquishment in perpetuity of all present and future rights to this
14// software under copyright law.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22// OTHER DEALINGS IN THE SOFTWARE.
23//
24// For more information, please refer to <http://unlicense.org>
25
26mod xcm_config;
27
28use polkadot_sdk::{staging_parachain_info as parachain_info, staging_xcm as xcm, *};
29#[cfg(not(feature = "runtime-benchmarks"))]
30use polkadot_sdk::{staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor};
31
32// Substrate and Polkadot dependencies
33use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
34use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
35use frame_support::{
36	derive_impl,
37	dispatch::DispatchClass,
38	parameter_types,
39	traits::{
40		ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin, VariantCountOf,
41	},
42	weights::{ConstantMultiplier, Weight},
43	PalletId,
44};
45use frame_system::{
46	limits::{BlockLength, BlockWeights},
47	EnsureRoot,
48};
49use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
50use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
51use polkadot_runtime_common::{
52	xcm_sender::NoPriceForMessageDelivery, BlockHashCount, SlowAdjustingFeeUpdate,
53};
54use sp_consensus_aura::sr25519::AuthorityId as AuraId;
55use sp_runtime::Perbill;
56use sp_version::RuntimeVersion;
57use xcm::latest::prelude::BodyId;
58
59// Local module imports
60use super::{
61	weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
62	AccountId, Aura, Balance, Balances, Block, BlockNumber, CollatorSelection, ConsensusHook, Hash,
63	MessageQueue, Nonce, PalletInfo, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent,
64	RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Session, SessionKeys,
65	System, WeightToFee, XcmpQueue, AVERAGE_ON_INITIALIZE_RATIO, EXISTENTIAL_DEPOSIT, HOURS,
66	MAXIMUM_BLOCK_WEIGHT, MICRO_UNIT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, VERSION,
67};
68use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin};
69
70parameter_types! {
71	pub const Version: RuntimeVersion = VERSION;
72
73	// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
74	//  The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
75	// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
76	// the lazy contract deletion.
77	pub RuntimeBlockLength: BlockLength =
78		BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
79	pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
80		.base_block(BlockExecutionWeight::get())
81		.for_class(DispatchClass::all(), |weights| {
82			weights.base_extrinsic = ExtrinsicBaseWeight::get();
83		})
84		.for_class(DispatchClass::Normal, |weights| {
85			weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
86		})
87		.for_class(DispatchClass::Operational, |weights| {
88			weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
89			// Operational transactions have some extra reserved space, so that they
90			// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
91			weights.reserved = Some(
92				MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
93			);
94		})
95		.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
96		.build_or_panic();
97	pub const SS58Prefix: u16 = 42;
98}
99
100/// All migrations of the runtime, aside from the ones declared in the pallets.
101///
102/// This can be a tuple of types, each implementing `OnRuntimeUpgrade`.
103#[allow(unused_parens)]
104type SingleBlockMigrations = ();
105
106/// The default types are being injected by [`derive_impl`](`frame_support::derive_impl`) from
107/// [`ParaChainDefaultConfig`](`struct@frame_system::config_preludes::ParaChainDefaultConfig`),
108/// but overridden as needed.
109#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig)]
110impl frame_system::Config for Runtime {
111	/// The identifier used to distinguish between accounts.
112	type AccountId = AccountId;
113	/// The index type for storing how many extrinsics an account has signed.
114	type Nonce = Nonce;
115	/// The type for hashing blocks and tries.
116	type Hash = Hash;
117	/// The block type.
118	type Block = Block;
119	/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
120	type BlockHashCount = BlockHashCount;
121	/// Runtime version.
122	type Version = Version;
123	/// The data to be stored in an account.
124	type AccountData = pallet_balances::AccountData<Balance>;
125	/// The weight of database operations that the runtime can invoke.
126	type DbWeight = RocksDbWeight;
127	/// Block & extrinsics weights: base values and limits.
128	type BlockWeights = RuntimeBlockWeights;
129	/// The maximum length of a block (in bytes).
130	type BlockLength = RuntimeBlockLength;
131	/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
132	type SS58Prefix = SS58Prefix;
133	/// The action to take on a Runtime Upgrade
134	type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
135	type MaxConsumers = frame_support::traits::ConstU32<16>;
136	type SingleBlockMigrations = SingleBlockMigrations;
137}
138
139/// Configure the palelt weight reclaim tx.
140impl cumulus_pallet_weight_reclaim::Config for Runtime {
141	type WeightInfo = ();
142}
143
144impl pallet_timestamp::Config for Runtime {
145	/// A timestamp: milliseconds since the unix epoch.
146	type Moment = u64;
147	type OnTimestampSet = Aura;
148	type MinimumPeriod = ConstU64<0>;
149	type WeightInfo = ();
150}
151
152impl pallet_authorship::Config for Runtime {
153	type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
154	type EventHandler = (CollatorSelection,);
155}
156
157parameter_types! {
158	pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
159}
160
161impl pallet_balances::Config for Runtime {
162	type MaxLocks = ConstU32<50>;
163	/// The type for recording an account's balance.
164	type Balance = Balance;
165	/// The ubiquitous event type.
166	type RuntimeEvent = RuntimeEvent;
167	type DustRemoval = ();
168	type ExistentialDeposit = ExistentialDeposit;
169	type AccountStore = System;
170	type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
171	type MaxReserves = ConstU32<50>;
172	type ReserveIdentifier = [u8; 8];
173	type RuntimeHoldReason = RuntimeHoldReason;
174	type RuntimeFreezeReason = RuntimeFreezeReason;
175	type FreezeIdentifier = RuntimeFreezeReason;
176	type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
177	type DoneSlashHandler = ();
178}
179
180parameter_types! {
181	/// Relay Chain `TransactionByteFee` / 10
182	pub const TransactionByteFee: Balance = 10 * MICRO_UNIT;
183}
184
185impl pallet_transaction_payment::Config for Runtime {
186	type RuntimeEvent = RuntimeEvent;
187	type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
188	type WeightToFee = WeightToFee;
189	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
190	type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
191	type OperationalFeeMultiplier = ConstU8<5>;
192	type WeightInfo = ();
193}
194
195impl pallet_sudo::Config for Runtime {
196	type RuntimeEvent = RuntimeEvent;
197	type RuntimeCall = RuntimeCall;
198	type WeightInfo = ();
199}
200
201parameter_types! {
202	pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
203	pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
204	pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
205}
206
207impl cumulus_pallet_parachain_system::Config for Runtime {
208	type WeightInfo = ();
209	type RuntimeEvent = RuntimeEvent;
210	type OnSystemEvent = ();
211	type SelfParaId = parachain_info::Pallet<Runtime>;
212	type OutboundXcmpMessageSource = XcmpQueue;
213	type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
214	type ReservedDmpWeight = ReservedDmpWeight;
215	type XcmpMessageHandler = XcmpQueue;
216	type ReservedXcmpWeight = ReservedXcmpWeight;
217	type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
218	type ConsensusHook = ConsensusHook;
219	type RelayParentOffset = ConstU32<0>;
220}
221
222impl parachain_info::Config for Runtime {}
223
224parameter_types! {
225	pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
226}
227
228impl pallet_message_queue::Config for Runtime {
229	type RuntimeEvent = RuntimeEvent;
230	type WeightInfo = ();
231	#[cfg(feature = "runtime-benchmarks")]
232	type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor<
233		cumulus_primitives_core::AggregateMessageOrigin,
234	>;
235	#[cfg(not(feature = "runtime-benchmarks"))]
236	type MessageProcessor = xcm_builder::ProcessXcmMessage<
237		AggregateMessageOrigin,
238		xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
239		RuntimeCall,
240	>;
241	type Size = u32;
242	// The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin:
243	type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
244	type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
245	type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
246	type MaxStale = sp_core::ConstU32<8>;
247	type ServiceWeight = MessageQueueServiceWeight;
248	type IdleMaxServiceWeight = ();
249}
250
251impl cumulus_pallet_aura_ext::Config for Runtime {}
252
253impl cumulus_pallet_xcmp_queue::Config for Runtime {
254	type RuntimeEvent = RuntimeEvent;
255	type ChannelInfo = ParachainSystem;
256	type VersionWrapper = ();
257	// Enqueue XCMP messages from siblings for later processing.
258	type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
259	type MaxInboundSuspended = sp_core::ConstU32<1_000>;
260	type MaxActiveOutboundChannels = ConstU32<128>;
261	type MaxPageSize = ConstU32<{ 1 << 16 }>;
262	type ControllerOrigin = EnsureRoot<AccountId>;
263	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
264	type WeightInfo = ();
265	type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
266}
267
268parameter_types! {
269	pub const Period: u32 = 6 * HOURS;
270	pub const Offset: u32 = 0;
271}
272
273impl pallet_session::Config for Runtime {
274	type RuntimeEvent = RuntimeEvent;
275	type ValidatorId = <Self as frame_system::Config>::AccountId;
276	// we don't have stash and controller, thus we don't need the convert as well.
277	type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
278	type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
279	type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
280	type SessionManager = CollatorSelection;
281	// Essentially just Aura, but let's be pedantic.
282	type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
283	type Keys = SessionKeys;
284	type DisablingStrategy = ();
285	type WeightInfo = ();
286	type Currency = Balances;
287	type KeyDeposit = ();
288}
289
290#[docify::export(aura_config)]
291impl pallet_aura::Config for Runtime {
292	type AuthorityId = AuraId;
293	type DisabledValidators = ();
294	type MaxAuthorities = ConstU32<100_000>;
295	type AllowMultipleBlocksPerSlot = ConstBool<true>;
296	type SlotDuration = ConstU64<SLOT_DURATION>;
297}
298
299parameter_types! {
300	pub const PotId: PalletId = PalletId(*b"PotStake");
301	pub const SessionLength: BlockNumber = 6 * HOURS;
302	// StakingAdmin pluralistic body.
303	pub const StakingAdminBodyId: BodyId = BodyId::Defense;
304}
305
306/// We allow root and the StakingAdmin to execute privileged collator selection operations.
307pub type CollatorSelectionUpdateOrigin = EitherOfDiverse<
308	EnsureRoot<AccountId>,
309	EnsureXcm<IsVoiceOfBody<RelayLocation, StakingAdminBodyId>>,
310>;
311
312impl pallet_collator_selection::Config for Runtime {
313	type RuntimeEvent = RuntimeEvent;
314	type Currency = Balances;
315	type UpdateOrigin = CollatorSelectionUpdateOrigin;
316	type PotId = PotId;
317	type MaxCandidates = ConstU32<100>;
318	type MinEligibleCollators = ConstU32<4>;
319	type MaxInvulnerables = ConstU32<20>;
320	// should be a multiple of session or things will get inconsistent
321	type KickThreshold = Period;
322	type ValidatorId = <Self as frame_system::Config>::AccountId;
323	type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
324	type ValidatorRegistration = Session;
325	type WeightInfo = ();
326}
327
328/// Configure the pallet template in pallets/template.
329impl pallet_parachain_template::Config for Runtime {
330	type RuntimeEvent = RuntimeEvent;
331	type WeightInfo = pallet_parachain_template::weights::SubstrateWeight<Runtime>;
332}