1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
34// 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.
89// 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.
1314// You should have received a copy of the GNU General Public License
15// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1617#![cfg_attr(not(feature = "std"), no_std)]
1819pub mod weights;
2021/// Money matters.
22pub mod currency {
23use polkadot_primitives::Balance;
2425/// The existential deposit.
26pub const EXISTENTIAL_DEPOSIT: Balance = 1 * CENTS;
2728pub const UNITS: Balance = 1_000_000_000_000;
29pub const CENTS: Balance = UNITS / 30_000;
30pub const GRAND: Balance = CENTS * 100_000;
31pub const MILLICENTS: Balance = CENTS / 1_000;
3233pub const fn deposit(items: u32, bytes: u32) -> Balance {
34 items as Balance * 2_000 * CENTS + (bytes as Balance) * 100 * MILLICENTS
35 }
36}
3738/// Time and blocks.
39pub mod time {
40use polkadot_runtime_common::prod_or_fast;
4142use polkadot_primitives::{BlockNumber, Moment};
43pub const MILLISECS_PER_BLOCK: Moment = 6000;
44pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
4546frame_support::parameter_types! {
47pub EpochDurationInBlocks: BlockNumber =
48prod_or_fast!(1 * HOURS, 1 * MINUTES, "ROCOCO_EPOCH_DURATION");
49 }
5051// These time units are defined in number of blocks.
52pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
53pub const HOURS: BlockNumber = MINUTES * 60;
54pub const DAYS: BlockNumber = HOURS * 24;
55pub const WEEKS: BlockNumber = DAYS * 7;
5657// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
58 // The choice of is done in accordance to the slot duration and expected target
59 // block time, for safely resisting network delays of maximum two seconds.
60 // <https://research.web3.foundation/Polkadot/protocols/block-production/Babe#6-practical-results>
61pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
62}
6364/// Fee-related.
65pub mod fee {
66use crate::weights::ExtrinsicBaseWeight;
67use frame_support::weights::{
68 WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
69 };
70use polkadot_primitives::Balance;
71use smallvec::smallvec;
72pub use sp_runtime::Perbill;
7374/// The block saturation level. Fees will be updates based on this value.
75pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
7677/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
78 /// node's balance type.
79 ///
80 /// This should typically create a mapping between the following ranges:
81 /// - [0, `frame_system::MaximumBlockWeight`]
82 /// - [Balance::min, Balance::max]
83 ///
84 /// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
85 /// - Setting it to `0` will essentially disable the weight fee.
86 /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
87pub struct WeightToFee;
88impl WeightToFeePolynomial for WeightToFee {
89type Balance = Balance;
90fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
91// in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
92let p = super::currency::CENTS;
93let q = 10 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
94smallvec![WeightToFeeCoefficient {
95 degree: 1,
96 negative: false,
97 coeff_frac: Perbill::from_rational(p % q, q),
98 coeff_integer: p / q,
99 }]
100 }
101 }
102}
103104/// System Parachains.
105pub mod system_parachain {
106use polkadot_primitives::Id;
107use xcm_builder::IsChildSystemParachain;
108109/// Network's Asset Hub parachain ID.
110pub const ASSET_HUB_ID: u32 = 1000;
111/// Contracts parachain ID.
112pub const CONTRACTS_ID: u32 = 1002;
113/// Encointer parachain ID.
114pub const ENCOINTER_ID: u32 = 1003;
115/// People parachain ID.
116pub const PEOPLE_ID: u32 = 1004;
117/// BridgeHub parachain ID.
118pub const BRIDGE_HUB_ID: u32 = 1013;
119/// Brokerage parachain ID.
120pub const BROKER_ID: u32 = 1005;
121122/// All system parachains of Rococo.
123pub type SystemParachains = IsChildSystemParachain<Id>;
124125/// Coretime constants
126pub mod coretime {
127/// Coretime timeslice period in blocks
128 /// WARNING: This constant is used accross chains, so additional care should be taken
129 /// when changing it.
130#[cfg(feature = "fast-runtime")]
131pub const TIMESLICE_PERIOD: u32 = 20;
132#[cfg(not(feature = "fast-runtime"))]
133pub const TIMESLICE_PERIOD: u32 = 80;
134 }
135}
136137/// Rococo Treasury pallet instance.
138pub const TREASURY_PALLET_ID: u8 = 18;
139140#[cfg(test)]
141mod tests {
142use super::{
143 currency::{CENTS, MILLICENTS},
144 fee::WeightToFee,
145 };
146use crate::weights::ExtrinsicBaseWeight;
147use frame_support::weights::WeightToFee as WeightToFeeT;
148use polkadot_runtime_common::MAXIMUM_BLOCK_WEIGHT;
149150#[test]
151// Test that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight has sane bounds.
152fn full_block_fee_is_correct() {
153// A full block should cost between 1,000 and 10,000 CENTS.
154let full_block = WeightToFee::weight_to_fee(&MAXIMUM_BLOCK_WEIGHT);
155assert!(full_block >= 1_000 * CENTS);
156assert!(full_block <= 10_000 * CENTS);
157 }
158159#[test]
160// This function tests that the fee for `ExtrinsicBaseWeight` of weight is correct
161fn extrinsic_base_fee_is_correct() {
162// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
163println!("Base: {}", ExtrinsicBaseWeight::get());
164let x = WeightToFee::weight_to_fee(&ExtrinsicBaseWeight::get());
165let y = CENTS / 10;
166assert!(x.max(y) - x.min(y) < MILLICENTS);
167 }
168}