referrerpolicy=no-referrer-when-downgrade

test_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	pub const DOTS: Balance = 1_000_000_000_000;
26	pub const DOLLARS: Balance = DOTS;
27	pub const CENTS: Balance = DOLLARS / 100;
28	pub const MILLICENTS: Balance = CENTS / 1_000;
29}
30
31/// Time and blocks.
32pub mod time {
33	use polkadot_primitives::{BlockNumber, Moment};
34	// Testnet
35	pub const MILLISECS_PER_BLOCK: Moment = 6000;
36	pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
37	// 30 seconds for now
38	pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = MINUTES / 2;
39
40	// These time units are defined in number of blocks.
41	pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
42	pub const HOURS: BlockNumber = MINUTES * 60;
43	pub const DAYS: BlockNumber = HOURS * 24;
44
45	// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
46	// The choice of is done in accordance to the slot duration and expected target
47	// block time, for safely resisting network delays of maximum two seconds.
48	// <https://research.web3.foundation/Polkadot/protocols/block-production/Babe#6-practical-results>
49	pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
50}
51
52/// Fee-related.
53pub mod fee {
54	use crate::weights::ExtrinsicBaseWeight;
55	use frame_support::weights::{
56		WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
57	};
58	use polkadot_primitives::Balance;
59	use smallvec::smallvec;
60	pub use sp_runtime::Perbill;
61
62	/// The block saturation level. Fees will be updates based on this value.
63	pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
64
65	/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
66	/// node's balance type.
67	///
68	/// This should typically create a mapping between the following ranges:
69	///   - [0, `frame_system::MaximumBlockWeight`]
70	///   - [Balance::min, Balance::max]
71	///
72	/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
73	///   - Setting it to `0` will essentially disable the weight fee.
74	///   - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
75	pub struct WeightToFee;
76	impl WeightToFeePolynomial for WeightToFee {
77		type Balance = Balance;
78		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
79			let p = super::currency::CENTS;
80			let q = 10 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
81			smallvec![WeightToFeeCoefficient {
82				degree: 1,
83				negative: false,
84				coeff_frac: Perbill::from_rational(p % q, q),
85				coeff_integer: p / q,
86			}]
87		}
88	}
89}