testnets_common/
westend.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
16/// Universally recognized accounts.
17pub mod account {
18	use frame_support::PalletId;
19
20	/// Westend treasury pallet id, used to convert into AccountId - in Westend as a destination for
21	/// slashed funds.
22	pub const WESTEND_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");
23	/// Alliance pallet ID - used as a temporary place to deposit a slashed imbalance before the
24	/// teleport to the Treasury.
25	pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia");
26	/// Referenda pallet ID - used as a temporary place to deposit a slashed imbalance before the
27	/// teleport to the Treasury.
28	pub const REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/refer");
29	/// Ambassador Referenda pallet ID - used as a temporary place to deposit a slashed imbalance
30	/// before the teleport to the Treasury.
31	pub const AMBASSADOR_REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/amref");
32}
33
34pub mod currency {
35	use polkadot_core_primitives::Balance;
36	use westend_runtime_constants as constants;
37
38	/// The existential deposit. Set to 1/10 of its parent Relay Chain.
39	pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10;
40
41	pub const UNITS: Balance = constants::currency::UNITS;
42	pub const DOLLARS: Balance = UNITS; // 1_000_000_000_000
43	pub const CENTS: Balance = constants::currency::CENTS;
44	pub const MILLICENTS: Balance = constants::currency::MILLICENTS;
45	pub const GRAND: Balance = constants::currency::GRAND;
46
47	pub const fn deposit(items: u32, bytes: u32) -> Balance {
48		// 1/100 of Westend testnet
49		constants::currency::deposit(items, bytes) / 100
50	}
51}
52
53/// Fee-related.
54pub mod fee {
55	use frame_support::{
56		pallet_prelude::Weight,
57		weights::{
58			constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient,
59			WeightToFeeCoefficients, WeightToFeePolynomial,
60		},
61	};
62	use polkadot_core_primitives::Balance;
63	use smallvec::smallvec;
64	pub use sp_runtime::Perbill;
65
66	/// The block saturation level. Fees will be updated based on this value.
67	pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
68
69	/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
70	/// node's balance type.
71	///
72	/// This should typically create a mapping between the following ranges:
73	///   - [0, MAXIMUM_BLOCK_WEIGHT]
74	///   - [Balance::min, Balance::max]
75	///
76	/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
77	///   - Setting it to `0` will essentially disable the weight fee.
78	///   - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
79	pub struct WeightToFee;
80	impl frame_support::weights::WeightToFee for WeightToFee {
81		type Balance = Balance;
82
83		fn weight_to_fee(weight: &Weight) -> Self::Balance {
84			let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
85			let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();
86
87			// Take the maximum instead of the sum to charge by the more scarce resource.
88			time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
89		}
90	}
91
92	/// Maps the reference time component of `Weight` to a fee.
93	pub struct RefTimeToFee;
94	impl WeightToFeePolynomial for RefTimeToFee {
95		type Balance = Balance;
96		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
97			// In Westend, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
98			// The standard system parachain configuration is 1/10 of that, as in 1/100 CENT.
99			let p = super::currency::CENTS;
100			let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
101
102			smallvec![WeightToFeeCoefficient {
103				degree: 1,
104				negative: false,
105				coeff_frac: Perbill::from_rational(p % q, q),
106				coeff_integer: p / q,
107			}]
108		}
109	}
110
111	/// Maps the proof size component of `Weight` to a fee.
112	pub struct ProofSizeToFee;
113	impl WeightToFeePolynomial for ProofSizeToFee {
114		type Balance = Balance;
115		fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
116			// Map 10kb proof to 1 CENT.
117			let p = super::currency::CENTS;
118			let q = 10_000;
119
120			smallvec![WeightToFeeCoefficient {
121				degree: 1,
122				negative: false,
123				coeff_frac: Perbill::from_rational(p % q, q),
124				coeff_integer: p / q,
125			}]
126		}
127	}
128}
129
130/// Consensus-related.
131pub mod consensus {
132	/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the
133	/// relay chain.
134	pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
135	/// How many parachain blocks are processed by the relay chain per parent. Limits the number of
136	/// blocks authored per slot.
137	pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
138	/// Relay chain slot duration, in milliseconds.
139	pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
140}