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, Get},
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 number of blocks per virtual bucket
89pub type MSAMortalityWindowSize = ConstU32<{ 20 * MINUTES }>;
90/// The upper limit on total stored signatures.
91/// Set to an average of 50 signatures per block
92pub type MSAMaxSignaturesStored = ConstU32<50_000>;
93/// The maximum size of a provider name (in bytes)
94#[derive(Clone, Copy, Debug, Eq, PartialEq)]
95pub struct MsaMaxProviderNameSize;
96impl Get<u32> for MsaMaxProviderNameSize {
97	fn get() -> u32 {
98		256
99	}
100}
101/// The maximum size of a provider language code (in bytes)
102#[derive(Clone, Copy, Debug, Eq, PartialEq)]
103pub struct MsaMaxLanguageCodeSize;
104impl Get<u32> for MsaMaxLanguageCodeSize {
105	fn get() -> u32 {
106		8
107	}
108}
109/// The maximum size of a provider logo CID (in bytes)
110#[derive(Clone, Copy, Debug, Eq, PartialEq)]
111pub struct MsaMaxLogoCidSize;
112impl Get<u32> for MsaMaxLogoCidSize {
113	fn get() -> u32 {
114		64
115	}
116}
117/// The maximum size of a provider locale count
118#[derive(Clone, Copy, Debug, Eq, PartialEq)]
119pub struct MsaMaxLocaleCount;
120impl Get<u32> for MsaMaxLocaleCount {
121	fn get() -> u32 {
122		10
123	}
124}
125/// The maximum size of a provider logo (in bytes)
126#[derive(Clone, Copy, Debug, Eq, PartialEq)]
127pub struct MsaMaxLogoSize;
128impl Get<u32> for MsaMaxLogoSize {
129	fn get() -> u32 {
130		1024 * 128
131	}
132}
133// -end- MSA Pallet ---
134
135// --- Schemas Pallet ---
136parameter_types! {
137	/// The maximum length of a schema model (in bytes)
138	pub const SchemasMaxBytesBoundedVecLimit :u32 = 65_500;
139}
140/// The maximum number of schema registrations
141pub type SchemasMaxRegistrations = ConstU16<65_000>;
142/// The minimum schema model size (in bytes)
143pub type SchemasMinModelSizeBytes = ConstU32<8>;
144/// The maximum number of grants allowed per schema
145pub type MaxSchemaSettingsPerSchema = ConstU32<2>;
146
147impl Encode for SchemasMaxBytesBoundedVecLimit {}
148
149impl MaxEncodedLen for SchemasMaxBytesBoundedVecLimit {
150	fn max_encoded_len() -> usize {
151		u32::max_encoded_len()
152	}
153}
154// -end- Schemas Pallet ---
155
156// --- Handles Pallet ---
157// IMPORTANT: These values should only increase and never overlap with a previous set!
158/// The minimum suffix value
159pub type HandleSuffixMin = ConstU16<10>;
160/// The maximum suffix value
161pub type HandleSuffixMax = ConstU16<99>;
162// -end- Handles Pallet
163
164// --- TimeRelease Pallet ---
165pub type MinReleaseTransfer = ConstU128<{ currency::EXISTENTIAL_DEPOSIT }>;
166
167/// Update
168pub const MAX_RELEASE_SCHEDULES: u32 = 50;
169// -end- TimeRelease Pallet ---
170
171// --- Timestamp Pallet ---
172pub type MinimumPeriod = ConstU64<0>;
173// -end- Timestamp Pallet ---
174
175// --- Authorship Pallet ---
176pub type AuthorshipUncleGenerations = ZERO;
177// -end- Authorship Pallet ---
178
179// --- Balances Pallet ---
180pub type BalancesMaxLocks = FIFTY;
181pub type BalancesMaxReserves = FIFTY;
182pub type BalancesMaxFreezes = TWO; // capacity + time-release
183								   // -end- Balances Pallet ---
184
185// --- Scheduler Pallet ---
186pub type SchedulerMaxScheduledPerBlock = FIFTY;
187// -end- Scheduler Pallet ---
188
189// --- Preimage Pallet ---
190/// Preimage maximum size set to 4 MB
191/// Expected to be removed in Polkadot v0.9.31
192pub type PreimageMaxSize = ConstU32<{ 4096 * 1024 }>;
193
194pub type PreimageBaseDeposit = ConstU128<{ currency::deposit(10, 64) }>;
195pub type PreimageByteDeposit = ConstU128<{ currency::deposit(0, 1) }>;
196// -end- Preimage Pallet ---
197
198// --- Council ---
199// The maximum number of council proposals
200pub type CouncilMaxProposals = ConstU32<25>;
201// The maximum number of council members
202pub type CouncilMaxMembers = ConstU32<10>;
203
204pub type CouncilMotionDuration = ConstU32<{ 5 * DAYS }>;
205// -end- Council ---
206
207// --- Technical Committee ---
208// The maximum number of technical committee proposals
209pub type TCMaxProposals = ConstU32<25>;
210// The maximum number of technical committee members
211pub type TCMaxMembers = ConstU32<10>;
212
213pub type TCMotionDuration = ConstU32<{ 5 * DAYS }>;
214// -end- Technical Committee ---
215
216// --- Democracy Pallet ---
217// Config from
218// https://github.com/paritytech/substrate/blob/367dab0d4bd7fd7b6c222dd15c753169c057dd42/bin/node/runtime/src/lib.rs#L880
219pub type LaunchPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
220pub type VotingPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
221pub type FastTrackVotingPeriod =
222	ConstU32<{ prod_or_testnet_or_local!(3 * HOURS, 30 * MINUTES, 5 * MINUTES) }>;
223pub type EnactmentPeriod =
224	ConstU32<{ prod_or_testnet_or_local!(8 * DAYS, 30 * HOURS, 10 * MINUTES) }>;
225pub type CooloffPeriod = ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 1 * DAYS, 5 * MINUTES) }>;
226pub type MinimumDeposit = ConstU128<
227	{
228		prod_or_testnet_or_local!(
229			currency::deposit(5, 0),
230			100 * currency::deposit(5, 0),
231			100 * currency::deposit(5, 0)
232		)
233	},
234>;
235pub type SpendPeriod =
236	ConstU32<{ prod_or_testnet_or_local!(7 * DAYS, 10 * MINUTES, 10 * MINUTES) }>;
237pub type DemocracyMaxVotes = ConstU32<100>;
238pub type DemocracyMaxProposals = HUNDRED;
239// -end- Democracy Pallet ---
240
241// --- Treasury Pallet ---
242/// Generates the pallet "account"
243/// 5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z
244pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");
245
246// https://wiki.polkadot.network/docs/learn-treasury
247// https://paritytech.github.io/substrate/master/pallet_treasury/pallet/trait.Config.html
248// Needs parameter_types! for the Permill and PalletId
249parameter_types! {
250
251	/// Keyless account that holds the money for the treasury
252	pub const TreasuryPalletId: PalletId = TREASURY_PALLET_ID;
253
254	/// Bond amount a treasury request must put up to make the proposal
255	/// This will be transferred to OnSlash if the proposal is rejected
256	pub const ProposalBondPercent: Permill = Permill::from_percent(5);
257
258	/// How much of the treasury to burn, if funds remain at the end of the SpendPeriod
259	/// Set to zero until the economic system is setup and stabilized
260	pub const Burn: Permill = Permill::zero();
261}
262
263/// Maximum number of approved proposals per Spending Period
264/// Set to 64 or 16 per week
265pub type MaxApprovals = ConstU32<64>;
266
267/// Minimum bond for a treasury proposal
268pub type ProposalBondMinimum = ConstU128<{ 100 * currency::DOLLARS }>;
269
270/// Minimum bond for a treasury proposal
271pub type ProposalBondMaximum = ConstU128<{ 1_000 * currency::DOLLARS }>;
272
273// -end- Treasury Pallet ---
274
275// --- Transaction Payment Pallet ---
276// The fee multiplier
277pub type TransactionPaymentOperationalFeeMultiplier = ConstU8<5>;
278
279/// Relay Chain `TransactionByteFee` / 10
280pub type TransactionByteFee = ConstU128<{ 10 * currency::MILLICENTS }>;
281// -end- Transaction Payment Pallet ---
282
283// --- Frequency Transaction Payment Pallet ---
284pub type MaximumCapacityBatchLength = ConstU8<10>;
285// -end- Frequency Transaction Payment Pallet ---
286
287// --- Session Pallet ---
288pub type SessionPeriod = ConstU32<{ 6 * HOURS }>;
289pub type SessionOffset = ZERO;
290// -end- Session Pallet ---
291
292// --- Aura Pallet ---
293/// The maximum number of authorities
294pub type AuraMaxAuthorities = ConstU32<100_000>;
295// -end- Aura Pallet ---
296
297// --- Collator Selection Pallet ---
298// Values for each runtime environment are independently configurable.
299// Example CollatorMaxInvulnerables are 16 in production(mainnet),
300// 5 in testnet and 5 in local
301
302pub type CollatorMaxCandidates = ConstU32<50>;
303pub type CollatorMinCandidates = ConstU32<{ prod_or_testnet_or_local!(1, 0, 0) }>;
304pub type CollatorMaxInvulnerables = ConstU32<{ prod_or_testnet_or_local!(16, 5, 5) }>;
305pub type CollatorKickThreshold =
306	ConstU32<{ prod_or_testnet_or_local!(6 * HOURS, 6 * HOURS, 6 * HOURS) }>;
307
308// Needs parameter_types! for the PalletId and impls below
309parameter_types! {
310	pub const NeverDepositIntoId: PalletId = PalletId(*b"NeverDep");
311	pub const MessagesMaxPayloadSizeBytes: u32 = 1024 * 3; // 3K
312}
313// -end- Collator Selection Pallet ---
314
315// --- Proxy Pallet ---
316// Copied from Polkadot Runtime v1.2.0
317parameter_types! {
318	// One storage item; key size 32, value size 8; .
319	pub const ProxyDepositBase: Balance = currency::deposit(1, 8);
320	// Additional storage item size of 33 bytes.
321	pub const ProxyDepositFactor: Balance = currency::deposit(0, 33);
322	pub const MaxProxies: u16 = 32;
323	pub const AnnouncementDepositBase: Balance = currency::deposit(1, 8);
324	pub const AnnouncementDepositFactor: Balance = currency::deposit(0, 66);
325	pub const MaxPending: u16 = 32;
326}
327// -end- Proxy Pallet ---
328
329// --- Messages Pallet ---
330impl Clone for MessagesMaxPayloadSizeBytes {
331	fn clone(&self) -> Self {
332		MessagesMaxPayloadSizeBytes {}
333	}
334}
335
336impl core::fmt::Debug for MessagesMaxPayloadSizeBytes {
337	#[cfg(feature = "std")]
338	fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
339		write!(f, "MessagesMaxPayloadSizeBytes<{:?}>", Self::get())
340	}
341
342	#[cfg(not(feature = "std"))]
343	fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
344		Ok(())
345	}
346}
347
348impl Encode for MessagesMaxPayloadSizeBytes {}
349
350impl MaxEncodedLen for MessagesMaxPayloadSizeBytes {
351	fn max_encoded_len() -> usize {
352		u32::max_encoded_len()
353	}
354}
355// -end- Messages Pallet ---
356
357// Needs parameter_types! to reduce pallet dependencies
358parameter_types! {
359	/// SS58 Prefix for the for Frequency Network
360	/// 90 is the prefix for the Frequency Network on Polkadot
361	/// 42 is the default prefix elsewhere
362	pub const Ss58Prefix: u16 = prod_or_testnet_or_local!(90, 42, 42);
363}
364
365// --- Stateful Storage Pallet ---
366// Needs parameter_types! for the impls below
367parameter_types! {
368	/// The maximum size of a single item in an itemized storage model (in bytes)
369	pub const MaxItemizedBlobSizeBytes: u32 = 1024;
370	/// The maximum size of a page (in bytes) for an Itemized storage model ~ (10KiB)
371	/// extra 2 bytes is for ItemHeader which enables us to simulate max PoV in benchmarks
372	pub const MaxItemizedPageSizeBytes: u32 = 10 * (1024 + 2);
373	/// The maximum size of a page (in bytes) for a Paginated storage model (1KiB)
374	pub const MaxPaginatedPageSizeBytes: u32 = 1 * 1024;
375}
376/// The maximum number of pages in a Paginated storage model
377pub type MaxPaginatedPageId = ConstU16<32>;
378/// The maximum number of actions in itemized actions
379pub type MaxItemizedActionsCount = ConstU32<5>;
380/// The number of blocks for Stateful mortality is 48 hours
381pub type StatefulMortalityWindowSize = ConstU32<{ 2 * DAYS }>;
382// -end- Stateful Storage Pallet
383
384impl Default for MaxItemizedPageSizeBytes {
385	fn default() -> Self {
386		Self
387	}
388}
389
390impl Default for MaxPaginatedPageSizeBytes {
391	fn default() -> Self {
392		Self
393	}
394}
395
396impl Clone for MaxItemizedBlobSizeBytes {
397	fn clone(&self) -> Self {
398		MaxItemizedBlobSizeBytes {}
399	}
400}
401
402impl PartialEq for MaxItemizedBlobSizeBytes {
403	fn eq(&self, _other: &Self) -> bool {
404		// This is a constant. It is always equal to itself
405		true
406	}
407}
408
409impl core::fmt::Debug for MaxItemizedBlobSizeBytes {
410	#[cfg(feature = "std")]
411	fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
412		Ok(())
413	}
414
415	#[cfg(not(feature = "std"))]
416	fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
417		Ok(())
418	}
419}
420
421// --- Capacity Pallet ---
422pub type CapacityMinimumStakingAmount = ConstU128<{ currency::EXISTENTIAL_DEPOSIT }>;
423pub type CapacityMinimumTokenBalance = ConstU128<{ currency::DOLLARS }>;
424pub type CapacityMaxUnlockingChunks = ConstU32<4>;
425pub type CapacityMaxEpochLength = ConstU32<{ 2 * DAYS }>; // Two days, assuming 6 second blocks.
426
427#[cfg(not(any(feature = "frequency-local", feature = "frequency-no-relay")))]
428pub type CapacityUnstakingThawPeriod = ConstU16<30>; // 30 Epochs, or 30 days given the above
429
430#[cfg(any(feature = "frequency-local", feature = "frequency-no-relay"))]
431pub type CapacityUnstakingThawPeriod = ConstU16<2>; // 2 Epochs
432
433// Needs parameter_types! for the Perbil
434parameter_types! {
435	// 1:50 Capacity:Token, must be declared this way instead of using `from_rational` because of
436	//  ```error[E0015]: cannot call non-const fn `Perbill::from_rational::<u32>` in constant functions```
437	pub const CapacityPerToken: Perbill = Perbill::from_percent(2);
438	pub const CapacityRewardCap: Permill = Permill::from_parts(5_750);  // 0.575% or 0.00575 per RewardEra
439}
440pub type CapacityRewardEraLength =
441	ConstU32<{ prod_or_testnet_or_local!(14 * DAYS, 1 * HOURS, 50) }>;
442
443// -end- Capacity Pallet ---
444
445// --- XCM Version ---
446#[cfg(feature = "frequency-bridging")]
447pub mod xcm_version {
448	/// The default XCM version considered safe for the network.
449	/// This is not the latest version, but the one that is considered stable and safe to use.
450	/// It is used to ensure that the network can handle XCM messages without issues.
451	pub const SAFE_XCM_VERSION: u32 = 4;
452}