testnets_common/
rococo.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16pub mod currency {
17	use polkadot_core_primitives::Balance;
18	use rococo_runtime_constants as constants;
19
20	/// The existential deposit. Set to 1/10 of its parent Relay Chain (v9010).
21	pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10;
22
23	pub const UNITS: Balance = constants::currency::UNITS;
24	pub const CENTS: Balance = constants::currency::CENTS;
25	pub const MILLICENTS: Balance = constants::currency::MILLICENTS;
26
27	pub const fn deposit(items: u32, bytes: u32) -> Balance {
28		// map to 1/100 of what the rococo relay chain charges
29		constants::currency::deposit(items, bytes) / 100
30	}
31}
32
33pub mod fee {
34	use frame_support::{
35		pallet_prelude::Weight,
36		weights::{
37			constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient,
38			WeightToFeeCoefficients, WeightToFeePolynomial,
39		},
40	};
41	use polkadot_core_primitives::Balance;
42	use smallvec::smallvec;
43	pub use sp_runtime::Perbill;
44
45	/// The block saturation level. Fees will be updates based on this value.
46	pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
47
48	/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
49	/// node's balance type.
50	///
51	/// This should typically create a mapping between the following ranges:
52	///   - `[0, MAXIMUM_BLOCK_WEIGHT]`
53	///   - `[Balance::min, Balance::max]`
54	///
55	/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
56	///   - Setting it to `0` will essentially disable the weight fee.
57	///   - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
58	pub struct WeightToFee;
59	impl frame_support::weights::WeightToFee for WeightToFee {
60		type Balance = Balance;
61
62		fn weight_to_fee(weight: &Weight) -> Self::Balance {
63			let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
64			let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();
65
66			// Take the maximum instead of the sum to charge by the more scarce resource.
67			time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
68		}
69	}
70
71	/// Maps the reference time component of `Weight` to a fee.
72	pub struct RefTimeToFee;
73	impl WeightToFeePolynomial for RefTimeToFee {
74		type Balance = Balance;
75		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
76			// In Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
77			// The standard system parachain configuration is 1/10 of that, as in 1/100 CENT.
78			let p = super::currency::CENTS;
79			let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
80
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
90	/// Maps the proof size component of `Weight` to a fee.
91	pub struct ProofSizeToFee;
92	impl WeightToFeePolynomial for ProofSizeToFee {
93		type Balance = Balance;
94		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
95			// Map 10kb proof to 1 CENT.
96			let p = super::currency::CENTS;
97			let q = 10_000;
98
99			smallvec![WeightToFeeCoefficient {
100				degree: 1,
101				negative: false,
102				coeff_frac: Perbill::from_rational(p % q, q),
103				coeff_integer: p / q,
104			}]
105		}
106	}
107}
108
109/// Consensus-related.
110pub mod consensus {
111	/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
112	/// into the relay chain.
113	pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
114	/// How many parachain blocks are processed by the relay chain per parent. Limits the
115	/// number of blocks authored per slot.
116	pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
117	/// Relay chain slot duration, in milliseconds.
118	pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
119}