common_runtime/
constants.rs

1use crate::prod_or_testnet_or_local;
2use common_primitives::node::{Balance, BlockNumber};
3use parity_scale_codec::{Encode, MaxEncodedLen};
4
5use frame_support::{
6	parameter_types,
7	sp_runtime::{Perbill, Permill},
8	traits::{ConstU128, ConstU16, ConstU32, ConstU64, ConstU8},
9	weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
10	PalletId,
11};
12
13// Duplicated in runtime/frequency/build.rs to keep build dependencies low
14pub const FREQUENCY_TESTNET_TOKEN: &str = "XRQCY";
15pub const FREQUENCY_LOCAL_TOKEN: &str = "UNIT";
16pub const FREQUENCY_TOKEN: &str = "FRQCY";
17pub const TOKEN_DECIMALS: u8 = 8;
18
19// Chain ID used for Ethereum signatures
20pub const CHAIN_ID: u32 = prod_or_testnet_or_local!(2091u32, 420420420u32, 420420420u32);
21
22/// The maximum number of schema grants allowed per delegation
23pub type MaxSchemaGrants = ConstU32<30>;
24
25/// This determines the average expected block time that we are targeting.
26/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
27/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
28/// up by `pallet_aura` to implement `fn slot_duration()`.
29///
30/// Change this to adjust the block time.
31pub const MILLISECS_PER_BLOCK: u64 = 6_000;
32
33// NOTE: Currently it is not possible to change the slot duration after the chain has started.
34//       Attempting to do so will brick block production.
35pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
36
37// Time is measured by number of blocks.
38pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
39pub const HOURS: BlockNumber = MINUTES * 60;
40pub const DAYS: BlockNumber = HOURS * 24;
41
42// Unit = the base number of indivisible units for balances
43pub mod currency {
44	use common_primitives::node::Balance;
45
46	/// The existential deposit. Set to be 1/100th of a token.
47	pub const EXISTENTIAL_DEPOSIT: Balance = CENTS;
48
49	pub const UNITS: Balance = 10u128.saturating_pow(super::TOKEN_DECIMALS as u32);
50	pub const DOLLARS: Balance = UNITS; // 100_000_000
51	pub const CENTS: Balance = DOLLARS / 100; // 1_000_000
52	pub const MILLICENTS: Balance = CENTS / 1_000; // 1_000
53
54	/// Generates a balance based on amount of items and bytes
55	/// Items are each worth 20 Dollars
56	/// Bytes each cost 1/1_000 of a Dollar
57	pub const fn deposit(items: u32, bytes: u32) -> Balance {
58		items as Balance * 20 * DOLLARS + (bytes as Balance) * 100 * MILLICENTS
59	}
60}
61
62/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
63/// used to limit the maximal weight of a single extrinsic.
64pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
65
66/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
67/// `Operational` extrinsics.
68pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
69
70/// We allow for 2 seconds of compute with a 6 second average block time.
71pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
72	WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
73	cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
74);
75
76pub type ZERO = ConstU32<0>;
77pub type TWO = ConstU32<2>;
78pub type FIFTY = ConstU32<50>;
79pub type HUNDRED = ConstU32<100>;
80
81// --- Frame System Pallet ---
82pub type FrameSystemMaxConsumers = ConstU32<16>;
83// -end- Frame System Pallet ---
84
85// --- MSA Pallet ---
86/// The maximum number of public keys per MSA
87pub type MsaMaxPublicKeysPerMsa = ConstU8<25>;
88/// The maximum size of the provider name (in bytes)
89pub type MsaMaxProviderNameSize = ConstU32<16>;
90/// The number of blocks per virtual bucket
91pub type MSAMortalityWindowSize = ConstU32<{ 20 * MINUTES }>;
92/// The upper limit on total stored signatures.
93/// Set to an average of 50 signatures per block
94pub type MSAMaxSignaturesStored = ConstU32<50_000>;
95// -end- MSA Pallet ---
96
97// --- Schemas Pallet ---
98parameter_types! {
99	/// The maximum length of a schema model (in bytes)
100	pub const SchemasMaxBytesBoundedVecLimit :u32 = 65_500;
101}
102/// The maximum number of schema registrations
103pub type SchemasMaxRegistrations = ConstU16<65_000>;
104/// The minimum schema model size (in bytes)
105pub type SchemasMinModelSizeBytes = ConstU32<8>;
106/// The maximum number of grants allowed per schema
107pub type MaxSchemaSettingsPerSchema = ConstU32<2>;
108
109impl Encode for SchemasMaxBytesBoundedVecLimit {}
110
111impl MaxEncodedLen for SchemasMaxBytesBoundedVecLimit {
112	fn max_encoded_len() -> usize {
113		u32::max_encoded_len()
114	}
115}
116// -end- Schemas Pallet ---
117
118// --- Handles Pallet ---
119// IMPORTANT: These values should only increase and never overlap with a previous set!
120/// The minimum suffix value
121pub type HandleSuffixMin = ConstU16<10>;
122/// The maximum suffix value
123pub type HandleSuffixMax = ConstU16<99>;
124// -end- Handles Pallet
125
126// --- TimeRelease Pallet ---
127pub type MinReleaseTransfer = ConstU128<{ currency::EXISTENTIAL_DEPOSIT }>;
128
129/// Update
130pub const MAX_RELEASE_SCHEDULES: u32 = 50;
131// -end- TimeRelease Pallet ---
132
133// --- Timestamp Pallet ---
134pub type MinimumPeriod = ConstU64<0>;
135// -end- Timestamp Pallet ---
136
137// --- Authorship Pallet ---
138pub type AuthorshipUncleGenerations = ZERO;
139// -end- Authorship Pallet ---
140
141// --- Balances Pallet ---
142pub type BalancesMaxLocks = FIFTY;
143pub type BalancesMaxReserves = FIFTY;
144pub type BalancesMaxFreezes = TWO; // capacity + time-release
145								   // -end- Balances Pallet ---
146
147// --- Scheduler Pallet ---
148pub type SchedulerMaxScheduledPerBlock = FIFTY;
149// -end- Scheduler Pallet ---
150
151// --- Preimage Pallet ---
152/// Preimage maximum size set to 4 MB
153/// Expected to be removed in Polkadot v0.9.31
154pub type PreimageMaxSize = ConstU32<{ 4096 * 1024 }>;
155
156pub type PreimageBaseDeposit = ConstU128<{ currency::deposit(10, 64) }>;
157pub type PreimageByteDeposit = ConstU128<{ currency::deposit(0, 1) }>;
158// -end- Preimage Pallet ---
159
160// --- Council ---
161// The maximum number of council proposals
162pub type CouncilMaxProposals = ConstU32<25>;
163// The maximum number of council members
164pub type CouncilMaxMembers = ConstU32<10>;
165
166pub type CouncilMotionDuration = ConstU32<{ 5 * DAYS }>;
167// -end- Council ---
168
169// --- Technical Committee ---
170// The maximum number of technical committee proposals
171pub type TCMaxProposals = ConstU32<25>;
172// The maximum number of technical committee members
173pub type TCMaxMembers = ConstU32<10>;
174
175pub type TCMotionDuration = ConstU32<{ 5 * DAYS }>;
176// -end- Technical Committee ---
177
178// --- Democracy Pallet ---
179// Config from
180// https://github.com/paritytech/substrate/blob/367dab0d4bd7fd7b6c222dd15c753169c057dd42/bin/node/runtime/src/lib.rs#L880
181pub type LaunchPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
182pub type VotingPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
183pub type FastTrackVotingPeriod =
184	ConstU32<{ prod_or_testnet_or_local!(3 * HOURS, 30 * MINUTES, 5 * MINUTES) }>;
185pub type EnactmentPeriod =
186	ConstU32<{ prod_or_testnet_or_local!(8 * DAYS, 30 * HOURS, 10 * MINUTES) }>;
187pub type CooloffPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
188pub type MinimumDeposit = ConstU128<
189	{
190		prod_or_testnet_or_local!(
191			currency::deposit(5, 0),
192			100 * currency::deposit(5, 0),
193			100 * currency::deposit(5, 0)
194		)
195	},
196>;
197pub type SpendPeriod =
198	ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 10 * MINUTES, 10 * MINUTES) }>;
199pub type DemocracyMaxVotes = ConstU32<100>;
200pub type DemocracyMaxProposals = HUNDRED;
201// -end- Democracy Pallet ---
202
203// --- Treasury Pallet ---
204/// Generates the pallet "account"
205/// 5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z
206pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");
207
208// https://wiki.polkadot.network/docs/learn-treasury
209// https://paritytech.github.io/substrate/master/pallet_treasury/pallet/trait.Config.html
210// Needs parameter_types! for the Permill and PalletId
211parameter_types! {
212
213	/// Keyless account that holds the money for the treasury
214	pub const TreasuryPalletId: PalletId = TREASURY_PALLET_ID;
215
216	/// Bond amount a treasury request must put up to make the proposal
217	/// This will be transferred to OnSlash if the proposal is rejected
218	pub const ProposalBondPercent: Permill = Permill::from_percent(5);
219
220	/// How much of the treasury to burn, if funds remain at the end of the SpendPeriod
221	/// Set to zero until the economic system is setup and stabilized
222	pub const Burn: Permill = Permill::zero();
223}
224
225/// Maximum number of approved proposals per Spending Period
226/// Set to 64 or 16 per week
227pub type MaxApprovals = ConstU32<64>;
228
229/// Minimum bond for a treasury proposal
230pub type ProposalBondMinimum = ConstU128<{ 100 * currency::DOLLARS }>;
231
232/// Minimum bond for a treasury proposal
233pub type ProposalBondMaximum = ConstU128<{ 1_000 * currency::DOLLARS }>;
234
235// -end- Treasury Pallet ---
236
237// --- Transaction Payment Pallet ---
238// The fee multiplier
239pub type TransactionPaymentOperationalFeeMultiplier = ConstU8<5>;
240
241/// Relay Chain `TransactionByteFee` / 10
242pub type TransactionByteFee = ConstU128<{ 10 * currency::MILLICENTS }>;
243// -end- Transaction Payment Pallet ---
244
245// --- Frequency Transaction Payment Pallet ---
246pub type MaximumCapacityBatchLength = ConstU8<10>;
247// -end- Frequency Transaction Payment Pallet ---
248
249// --- Session Pallet ---
250pub type SessionPeriod = ConstU32<{ 6 * HOURS }>;
251pub type SessionOffset = ZERO;
252// -end- Session Pallet ---
253
254// --- Aura Pallet ---
255/// The maximum number of authorities
256pub type AuraMaxAuthorities = ConstU32<100_000>;
257// -end- Aura Pallet ---
258
259// --- Collator Selection Pallet ---
260// Values for each runtime environment are independently configurable.
261// Example CollatorMaxInvulnerables are 16 in production(mainnet),
262// 5 in testnet and 5 in local
263
264pub type CollatorMaxCandidates = ConstU32<50>;
265pub type CollatorMinCandidates = ConstU32<{ prod_or_testnet_or_local!(1, 0, 0) }>;
266pub type CollatorMaxInvulnerables = ConstU32<{ prod_or_testnet_or_local!(16, 5, 5) }>;
267pub type CollatorKickThreshold =
268	ConstU32<{ prod_or_testnet_or_local!(6 * HOURS, 6 * HOURS, 6 * HOURS) }>;
269
270// Needs parameter_types! for the PalletId and impls below
271parameter_types! {
272	pub const NeverDepositIntoId: PalletId = PalletId(*b"NeverDep");
273	pub const MessagesMaxPayloadSizeBytes: u32 = 1024 * 3; // 3K
274}
275// -end- Collator Selection Pallet ---
276
277// --- Proxy Pallet ---
278// Copied from Polkadot Runtime v1.2.0
279parameter_types! {
280	// One storage item; key size 32, value size 8; .
281	pub const ProxyDepositBase: Balance = currency::deposit(1, 8);
282	// Additional storage item size of 33 bytes.
283	pub const ProxyDepositFactor: Balance = currency::deposit(0, 33);
284	pub const MaxProxies: u16 = 32;
285	pub const AnnouncementDepositBase: Balance = currency::deposit(1, 8);
286	pub const AnnouncementDepositFactor: Balance = currency::deposit(0, 66);
287	pub const MaxPending: u16 = 32;
288}
289// -end- Proxy Pallet ---
290
291// --- Messages Pallet ---
292impl Clone for MessagesMaxPayloadSizeBytes {
293	fn clone(&self) -> Self {
294		MessagesMaxPayloadSizeBytes {}
295	}
296}
297
298impl core::fmt::Debug for MessagesMaxPayloadSizeBytes {
299	#[cfg(feature = "std")]
300	fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
301		write!(f, "MessagesMaxPayloadSizeBytes<{:?}>", Self::get())
302	}
303
304	#[cfg(not(feature = "std"))]
305	fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
306		Ok(())
307	}
308}
309
310impl Encode for MessagesMaxPayloadSizeBytes {}
311
312impl MaxEncodedLen for MessagesMaxPayloadSizeBytes {
313	fn max_encoded_len() -> usize {
314		u32::max_encoded_len()
315	}
316}
317// -end- Messages Pallet ---
318
319// Needs parameter_types! to reduce pallet dependencies
320parameter_types! {
321	/// SS58 Prefix for the for Frequency Network
322	/// 90 is the prefix for the Frequency Network on Polkadot
323	/// 42 is the default prefix elsewhere
324	pub const Ss58Prefix: u16 = prod_or_testnet_or_local!(90, 42, 42);
325}
326
327// --- Stateful Storage Pallet ---
328// Needs parameter_types! for the impls below
329parameter_types! {
330	/// The maximum size of a single item in an itemized storage model (in bytes)
331	pub const MaxItemizedBlobSizeBytes: u32 = 1024;
332	/// The maximum size of a page (in bytes) for an Itemized storage model ~ (10KiB)
333	/// extra 2 bytes is for ItemHeader which enables us to simulate max PoV in benchmarks
334	pub const MaxItemizedPageSizeBytes: u32 = 10 * (1024 + 2);
335	/// The maximum size of a page (in bytes) for a Paginated storage model (1KiB)
336	pub const MaxPaginatedPageSizeBytes: u32 = 1 * 1024;
337}
338/// The maximum number of pages in a Paginated storage model
339pub type MaxPaginatedPageId = ConstU16<32>;
340/// The maximum number of actions in itemized actions
341pub type MaxItemizedActionsCount = ConstU32<5>;
342/// The number of blocks for Stateful mortality is 48 hours
343pub type StatefulMortalityWindowSize = ConstU32<{ 2 * DAYS }>;
344// -end- Stateful Storage Pallet
345
346impl Default for MaxItemizedPageSizeBytes {
347	fn default() -> Self {
348		Self
349	}
350}
351
352impl Default for MaxPaginatedPageSizeBytes {
353	fn default() -> Self {
354		Self
355	}
356}
357
358impl Clone for MaxItemizedBlobSizeBytes {
359	fn clone(&self) -> Self {
360		MaxItemizedBlobSizeBytes {}
361	}
362}
363
364impl PartialEq for MaxItemizedBlobSizeBytes {
365	fn eq(&self, _other: &Self) -> bool {
366		// This is a constant. It is always equal to itself
367		true
368	}
369}
370
371impl core::fmt::Debug for MaxItemizedBlobSizeBytes {
372	#[cfg(feature = "std")]
373	fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
374		Ok(())
375	}
376
377	#[cfg(not(feature = "std"))]
378	fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
379		Ok(())
380	}
381}
382
383// --- Capacity Pallet ---
384pub type CapacityMinimumStakingAmount = ConstU128<{ currency::EXISTENTIAL_DEPOSIT }>;
385pub type CapacityMinimumTokenBalance = ConstU128<{ currency::DOLLARS }>;
386pub type CapacityMaxUnlockingChunks = ConstU32<4>;
387pub type CapacityMaxEpochLength = ConstU32<{ 2 * DAYS }>; // Two days, assuming 6 second blocks.
388
389#[cfg(not(any(feature = "frequency-local", feature = "frequency-no-relay")))]
390pub type CapacityUnstakingThawPeriod = ConstU16<30>; // 30 Epochs, or 30 days given the above
391
392#[cfg(any(feature = "frequency-local", feature = "frequency-no-relay"))]
393pub type CapacityUnstakingThawPeriod = ConstU16<2>; // 2 Epochs
394
395// Needs parameter_types! for the Perbil
396parameter_types! {
397	// 1:50 Capacity:Token, must be declared this way instead of using `from_rational` because of
398	//  ```error[E0015]: cannot call non-const fn `Perbill::from_rational::<u32>` in constant functions```
399	pub const CapacityPerToken: Perbill = Perbill::from_percent(2);
400	pub const CapacityRewardCap: Permill = Permill::from_parts(5_750);  // 0.575% or 0.00575 per RewardEra
401}
402pub type CapacityRewardEraLength =
403	ConstU32<{ prod_or_testnet_or_local!(14 * DAYS, 1 * HOURS, 50) }>;
404
405// -end- Capacity Pallet ---
406
407// --- XCM Version ---
408#[cfg(feature = "frequency-bridging")]
409pub mod xcm_version {
410	/// The default XCM version considered safe for the network.
411	/// This is not the latest version, but the one that is considered stable and safe to use.
412	/// It is used to ensure that the network can handle XCM messages without issues.
413	pub const SAFE_XCM_VERSION: u32 = 4;
414}