referrerpolicy=no-referrer-when-downgrade

solochain_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
26// Substrate and Polkadot dependencies
27use frame_support::{
28	derive_impl,
29	dispatch::DispatchClass,
30	parameter_types,
31	traits::{ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, VariantCountOf},
32	weights::{
33		constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
34		IdentityFee, Weight,
35	},
36};
37use frame_system::limits::{BlockLength, BlockWeights};
38use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier};
39use sp_consensus_aura::sr25519::AuthorityId as AuraId;
40use sp_runtime::{traits::One, Perbill};
41use sp_version::RuntimeVersion;
42
43// Local module imports
44use super::{
45	AccountId, Aura, Balance, Balances, Block, BlockNumber, Hash, Nonce, PalletInfo, Runtime,
46	RuntimeCall, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask,
47	System, EXISTENTIAL_DEPOSIT, SLOT_DURATION, VERSION,
48};
49
50const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
51
52parameter_types! {
53	pub const BlockHashCount: BlockNumber = 2400;
54	pub const Version: RuntimeVersion = VERSION;
55
56	/// We allow for 2 seconds of compute with a 6 second average block time.
57	pub RuntimeBlockWeights: BlockWeights = BlockWeights::with_sensible_defaults(
58		Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
59		NORMAL_DISPATCH_RATIO,
60	);
61	pub RuntimeBlockLength: BlockLength = BlockLength::builder()
62		.max_length(5 * 1024 * 1024)
63		.modify_max_length_for_class(DispatchClass::Normal, |m| *m = NORMAL_DISPATCH_RATIO * *m)
64		.build();
65	pub const SS58Prefix: u8 = 42;
66}
67
68/// All migrations of the runtime, aside from the ones declared in the pallets.
69///
70/// This can be a tuple of types, each implementing `OnRuntimeUpgrade`.
71#[allow(unused_parens)]
72type SingleBlockMigrations = ();
73
74/// The default types are being injected by [`derive_impl`](`frame_support::derive_impl`) from
75/// [`SoloChainDefaultConfig`](`struct@frame_system::config_preludes::SolochainDefaultConfig`),
76/// but overridden as needed.
77#[derive_impl(frame_system::config_preludes::SolochainDefaultConfig)]
78impl frame_system::Config for Runtime {
79	/// The block type for the runtime.
80	type Block = Block;
81	/// Block & extrinsics weights: base values and limits.
82	type BlockWeights = RuntimeBlockWeights;
83	/// The maximum length of a block (in bytes).
84	type BlockLength = RuntimeBlockLength;
85	/// The identifier used to distinguish between accounts.
86	type AccountId = AccountId;
87	/// The type for storing how many extrinsics an account has signed.
88	type Nonce = Nonce;
89	/// The type for hashing blocks and tries.
90	type Hash = Hash;
91	/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
92	type BlockHashCount = BlockHashCount;
93	/// The weight of database operations that the runtime can invoke.
94	type DbWeight = RocksDbWeight;
95	/// Version of the runtime.
96	type Version = Version;
97	/// The data to be stored in an account.
98	type AccountData = pallet_balances::AccountData<Balance>;
99	/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
100	type SS58Prefix = SS58Prefix;
101	type MaxConsumers = frame_support::traits::ConstU32<16>;
102	type SingleBlockMigrations = SingleBlockMigrations;
103}
104
105impl pallet_aura::Config for Runtime {
106	type AuthorityId = AuraId;
107	type DisabledValidators = ();
108	type MaxAuthorities = ConstU32<32>;
109	type AllowMultipleBlocksPerSlot = ConstBool<false>;
110	type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Runtime>;
111}
112
113impl pallet_grandpa::Config for Runtime {
114	type RuntimeEvent = RuntimeEvent;
115
116	type WeightInfo = ();
117	type MaxAuthorities = ConstU32<32>;
118	type MaxNominators = ConstU32<0>;
119	type MaxSetIdSessionEntries = ConstU64<0>;
120
121	type KeyOwnerProof = sp_core::Void;
122	type EquivocationReportSystem = ();
123}
124
125impl pallet_timestamp::Config for Runtime {
126	/// A timestamp: milliseconds since the unix epoch.
127	type Moment = u64;
128	type OnTimestampSet = Aura;
129	type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
130	type WeightInfo = ();
131}
132
133impl pallet_balances::Config for Runtime {
134	type MaxLocks = ConstU32<50>;
135	type MaxReserves = ();
136	type ReserveIdentifier = [u8; 8];
137	/// The type for recording an account's balance.
138	type Balance = Balance;
139	/// The ubiquitous event type.
140	type RuntimeEvent = RuntimeEvent;
141	type DustRemoval = ();
142	type ExistentialDeposit = ConstU128<EXISTENTIAL_DEPOSIT>;
143	type AccountStore = System;
144	type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
145	type FreezeIdentifier = RuntimeFreezeReason;
146	type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
147	type RuntimeHoldReason = RuntimeHoldReason;
148	type RuntimeFreezeReason = RuntimeFreezeReason;
149	type DoneSlashHandler = ();
150}
151
152parameter_types! {
153	pub FeeMultiplier: Multiplier = Multiplier::one();
154}
155
156impl pallet_transaction_payment::Config for Runtime {
157	type RuntimeEvent = RuntimeEvent;
158	type OnChargeTransaction = FungibleAdapter<Balances, ()>;
159	type OperationalFeeMultiplier = ConstU8<5>;
160	type WeightToFee = IdentityFee<Balance>;
161	type LengthToFee = IdentityFee<Balance>;
162	type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
163	type WeightInfo = pallet_transaction_payment::weights::SubstrateWeight<Runtime>;
164}
165
166impl pallet_sudo::Config for Runtime {
167	type RuntimeEvent = RuntimeEvent;
168	type RuntimeCall = RuntimeCall;
169	type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
170}
171
172/// Configure the pallet-template in pallets/template.
173impl pallet_template::Config for Runtime {
174	type RuntimeEvent = RuntimeEvent;
175	type WeightInfo = pallet_template::weights::SubstrateWeight<Runtime>;
176}