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