referrerpolicy=no-referrer-when-downgrade

testnet_parachains_constants/
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	use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight};
112
113	/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
114	/// into the relay chain.
115	pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
116	/// How many parachain blocks are processed by the relay chain per parent. Limits the
117	/// number of blocks authored per slot.
118	pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
119	/// Relay chain slot duration, in milliseconds.
120	pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
121
122	/// We allow for 2 seconds of compute with a 6 second average block.
123	pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
124		WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
125		cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
126	);
127
128	/// This determines the average expected block time that we are targeting.
129	/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
130	/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
131	/// up by `pallet_aura` to implement `fn slot_duration()`.
132	///
133	/// Change this to adjust the block time.
134	pub const MILLISECS_PER_BLOCK: u64 = 6000;
135	pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
136}
137
138/// Time-related
139pub mod time {
140	use polkadot_core_primitives::BlockNumber;
141
142	// Time is measured by number of blocks.
143	pub const MINUTES: BlockNumber =
144		60_000 / (super::consensus::MILLISECS_PER_BLOCK as BlockNumber);
145	pub const HOURS: BlockNumber = MINUTES * 60;
146	pub const DAYS: BlockNumber = HOURS * 24;
147}
148
149pub mod snowbridge {
150	use frame_support::parameter_types;
151	use xcm::prelude::{Location, NetworkId};
152
153	/// The pallet index of the Ethereum inbound queue pallet in the bridge hub runtime.
154	pub const INBOUND_QUEUE_PALLET_INDEX: u8 = 80;
155
156	parameter_types! {
157		/// Network and location for the Ethereum chain. On Rococo, the Ethereum chain bridged
158		/// to is the Sepolia Ethereum testnet, with chain ID 11155111.
159		/// <https://chainlist.org/chain/11155111>
160		/// <https://ethereum.org/en/developers/docs/apis/json-rpc/#net_version>
161		pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 11155111 };
162		pub EthereumLocation: Location = Location::new(2, EthereumNetwork::get());
163	}
164}
165
166pub mod xcm_version {
167	/// The default XCM version to set in genesis config.
168	pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
169}
170
171pub mod locations {
172	use frame_support::parameter_types;
173	pub use rococo_runtime_constants::system_parachain::{AssetHubParaId, PeopleParaId};
174	use xcm::latest::prelude::{Location, Parachain};
175
176	parameter_types! {
177		pub AssetHubLocation: Location = Location::new(1, Parachain(rococo_runtime_constants::system_parachain::ASSET_HUB_ID));
178		pub PeopleLocation: Location = Location::new(1, Parachain(rococo_runtime_constants::system_parachain::PEOPLE_ID));
179	}
180}