referrerpolicy=no-referrer-when-downgrade

westend_runtime_constants/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17#![cfg_attr(not(feature = "std"), no_std)]
18
19pub mod weights;
20
21/// Money matters.
22pub mod currency {
23	use polkadot_primitives::Balance;
24
25	/// The existential deposit.
26	pub const EXISTENTIAL_DEPOSIT: Balance = 1 * CENTS;
27
28	pub const UNITS: Balance = 1_000_000_000_000;
29	pub const CENTS: Balance = UNITS / 100;
30	pub const MILLICENTS: Balance = CENTS / 1_000;
31	pub const GRAND: Balance = CENTS * 100_000;
32
33	pub const fn deposit(items: u32, bytes: u32) -> Balance {
34		items as Balance * 100 * CENTS + (bytes as Balance) * 5 * MILLICENTS
35	}
36}
37
38/// Time and blocks.
39pub mod time {
40	use polkadot_primitives::{BlockNumber, Moment};
41	use polkadot_runtime_common::prod_or_fast;
42
43	pub const MILLISECS_PER_BLOCK: Moment = 6000;
44	pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
45	pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES);
46
47	// These time units are defined in number of blocks.
48	pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
49	pub const HOURS: BlockNumber = MINUTES * 60;
50	pub const DAYS: BlockNumber = HOURS * 24;
51
52	// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
53	// The choice of is done in accordance to the slot duration and expected target
54	// block time, for safely resisting network delays of maximum two seconds.
55	// <https://research.web3.foundation/Polkadot/protocols/block-production/Babe#6-practical-results>
56	pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
57}
58
59/// Fee-related.
60pub mod fee {
61	use crate::weights::ExtrinsicBaseWeight;
62	use frame_support::weights::{
63		WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
64	};
65	use polkadot_primitives::Balance;
66	use smallvec::smallvec;
67	pub use sp_runtime::Perbill;
68
69	/// The block saturation level. Fees will be updates based on this value.
70	pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
71
72	/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
73	/// node's balance type.
74	///
75	/// This should typically create a mapping between the following ranges:
76	///   - [0,` MAXIMUM_BLOCK_WEIGHT`]
77	///   - [Balance::min, Balance::max]
78	///
79	/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
80	///   - Setting it to `0` will essentially disable the weight fee.
81	///   - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
82	pub struct WeightToFee;
83	impl WeightToFeePolynomial for WeightToFee {
84		type Balance = Balance;
85		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
86			// in Westend, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
87			let p = super::currency::CENTS;
88			let q = 10 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
89			smallvec![WeightToFeeCoefficient {
90				degree: 1,
91				negative: false,
92				coeff_frac: Perbill::from_rational(p % q, q),
93				coeff_integer: p / q,
94			}]
95		}
96	}
97}
98
99/// System Parachains.
100pub mod system_parachain {
101	use frame_support::parameter_types;
102	use polkadot_primitives::Id as ParaId;
103	use xcm_builder::IsChildSystemParachain;
104
105	parameter_types! {
106		pub AssetHubParaId: ParaId = ASSET_HUB_ID.into();
107		pub PeopleParaId: ParaId = PEOPLE_ID.into();
108	}
109
110	/// Network's Asset Hub parachain ID.
111	pub const ASSET_HUB_ID: u32 = 1000;
112	/// Collectives parachain ID.
113	pub const COLLECTIVES_ID: u32 = 1001;
114	/// BridgeHub parachain ID.
115	pub const BRIDGE_HUB_ID: u32 = 1002;
116	/// Encointer parachain ID.
117	pub const ENCOINTER_ID: u32 = 1003;
118	/// People Chain parachain ID.
119	pub const PEOPLE_ID: u32 = 1004;
120	/// Brokerage parachain ID.
121	pub const BROKER_ID: u32 = 1005;
122	/// AH-next - temporary AH clone.
123	pub const ASSET_HUB_NEXT_ID: u32 = 1100;
124
125	/// All system parachains of Westend.
126	pub type SystemParachains = IsChildSystemParachain<ParaId>;
127
128	/// DAP constants.
129	pub mod dap {
130		use frame_support::parameter_types;
131		use sp_runtime::traits::AccountIdConversion;
132		use xcm::latest::{InteriorLocation, Junction};
133
134		parameter_types! {
135			/// The interior location of the DAP staging account on AssetHub.
136			pub DapStagingLocation: InteriorLocation = Junction::AccountId32 {
137				network: None,
138				id: sp_dap::DAP_PALLET_ID
139				.into_sub_account_truncating(sp_dap::DAP_STAGING_ACCOUNT_ID),
140			}
141			.into();
142		}
143	}
144
145	/// Accumulate-and-forward constants.
146	pub mod accumulate_forward {
147		use frame_support::{parameter_types, PalletId};
148		use polkadot_primitives::{Balance, BlockNumber};
149
150		parameter_types! {
151			/// The pallet ID used to derive the accumulation account.
152			pub const AccumulateForwardPalletId: PalletId = PalletId(*b"acf/dott");
153			/// How often the accumulation account forwards to the destination.
154			pub const ForwardPeriod: BlockNumber = super::super::time::HOURS;
155			/// Minimum balance required to trigger a forward.
156			pub const MinForwardAmount: Balance = 10 * super::super::currency::UNITS;
157		}
158	}
159
160	/// Coretime constants
161	pub mod coretime {
162		/// Coretime timeslice period in blocks
163		/// WARNING: This constant is used accross chains, so additional care should be taken
164		/// when changing it.
165		#[cfg(feature = "fast-runtime")]
166		pub const TIMESLICE_PERIOD: u32 = 20;
167		#[cfg(not(feature = "fast-runtime"))]
168		pub const TIMESLICE_PERIOD: u32 = 80;
169	}
170}
171
172/// Westend Treasury pallet instance.
173pub const TREASURY_PALLET_ID: u8 = 37;
174
175/// XCM protocol related constants.
176pub mod xcm {
177	/// Pluralistic bodies existing within the consensus.
178	pub mod body {
179		// Preallocated for the Root body.
180		#[allow(dead_code)]
181		const ROOT_INDEX: u32 = 0;
182		// The bodies corresponding to the Polkadot OpenGov Origins.
183		pub const FELLOWSHIP_ADMIN_INDEX: u32 = 1;
184	}
185}
186
187#[cfg(test)]
188mod tests {
189	use super::{
190		currency::{CENTS, MILLICENTS, UNITS},
191		fee::WeightToFee,
192	};
193	use crate::weights::ExtrinsicBaseWeight;
194	use frame_support::weights::WeightToFee as WeightToFeeT;
195	use polkadot_runtime_common::MAXIMUM_BLOCK_WEIGHT;
196
197	#[test]
198	// Test that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight has sane bounds.
199	fn full_block_fee_is_correct() {
200		// A full block should cost between 10 and 100 UNITS.
201		let full_block = WeightToFee::weight_to_fee(&MAXIMUM_BLOCK_WEIGHT);
202		assert!(full_block >= 10 * UNITS);
203		assert!(full_block <= 100 * UNITS);
204	}
205
206	#[test]
207	// This function tests that the fee for `ExtrinsicBaseWeight` of weight is correct
208	fn extrinsic_base_fee_is_correct() {
209		// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
210		println!("Base: {}", ExtrinsicBaseWeight::get());
211		let x = WeightToFee::weight_to_fee(&ExtrinsicBaseWeight::get());
212		let y = CENTS / 10;
213		assert!(x.max(y) - x.min(y) < MILLICENTS);
214	}
215}