From f8bf9cb82757cd094c52a86b3df0bc9d46904f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Fri, 8 Dec 2023 17:50:44 +0000 Subject: [PATCH 01/12] Add kusama and polkadot SP constants --- Cargo.lock | 12 +++ Cargo.toml | 1 + system-parachains/common/Cargo.toml | 31 +++++++ system-parachains/common/src/kusama.rs | 122 +++++++++++++++++++++++++ system-parachains/common/src/lib.rs | 64 +++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 system-parachains/common/Cargo.toml create mode 100644 system-parachains/common/src/kusama.rs create mode 100644 system-parachains/common/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b007446808..3ffaa12c78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11828,6 +11828,18 @@ dependencies = [ "libc", ] +[[package]] +name = "system-parachains-common" +version = "1.0.0" +dependencies = [ + "frame-support", + "parachains-common", + "polkadot-core-primitives", + "polkadot-primitives", + "smallvec", + "sp-runtime", +] + [[package]] name = "tap" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index ae60da4073..994a3df509 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ members = [ "system-parachains/bridge-hubs/bridge-hub-kusama", "system-parachains/bridge-hubs/bridge-hub-polkadot", "system-parachains/collectives/collectives-polkadot", + "system-parachains/common", "system-parachains/gluttons/glutton-kusama", ] diff --git a/system-parachains/common/Cargo.toml b/system-parachains/common/Cargo.toml new file mode 100644 index 0000000000..54d7463015 --- /dev/null +++ b/system-parachains/common/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "system-parachains-common" +repository.workspace = true +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +smallvec = "1.8.0" + +# Substrate +frame-support = { default-features = false , version = "25.0.0" } +sp-runtime = { default-features = false , version = "28.0.0" } + +# Polkadot +polkadot-core-primitives = { default-features = false, version = "4.0.0"} +polkadot-primitives = { default-features = false , version = "4.0.0" } + +# Cumulus +parachains-common = { default-features = false , version = "4.0.0" } + +[features] +default = [ "std" ] +std = [ + "frame-support/std", + "parachains-common/std", + "polkadot-core-primitives/std", + "polkadot-primitives/std", + "sp-runtime/std", +] diff --git a/system-parachains/common/src/kusama.rs b/system-parachains/common/src/kusama.rs new file mode 100644 index 0000000000..073971a707 --- /dev/null +++ b/system-parachains/common/src/kusama.rs @@ -0,0 +1,122 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// Consensus-related. +pub mod consensus { + /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included + /// into the relay chain. + pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; + /// How many parachain blocks are processed by the relay chain per parent. Limits the + /// number of blocks authored per slot. + pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; + /// Relay chain slot duration, in milliseconds. + pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; +} + +/// Constants relating to KSM. +pub mod currency { + use polkadot_core_primitives::Balance; + + /// The existential deposit. Set to 1/10 of its parent Relay Chain. + pub const EXISTENTIAL_DEPOSIT: Balance = 1 * CENTS / 10; + + pub const UNITS: Balance = 1_000_000_000_000; + pub const QUID: Balance = UNITS / 30; + pub const CENTS: Balance = QUID / 100; + pub const GRAND: Balance = QUID * 1_000; + pub const MILLICENTS: Balance = CENTS / 1_000; + + pub const fn deposit(items: u32, bytes: u32) -> Balance { + // map to 1/100 of what the kusama relay chain charges (v9020) + (items as Balance * 2_000 * CENTS + (bytes as Balance) * 100 * MILLICENTS) / 100 + } +} + +/// Constants related to Kusama fee payment. +pub mod fee { + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, + }; + use polkadot_core_primitives::Balance; + use smallvec::smallvec; + pub use sp_runtime::Perbill; + + /// The block saturation level. Fees will be updates based on this value. + pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); + + /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the + /// node's balance type. + /// + /// This should typically create a mapping between the following ranges: + /// - [0, MAXIMUM_BLOCK_WEIGHT] + /// - [Balance::min, Balance::max] + /// + /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: + /// - Setting it to `0` will essentially disable the weight fee. + /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. + pub struct WeightToFee; + impl frame_support::weights::WeightToFee for WeightToFee { + type Balance = Balance; + + fn weight_to_fee(weight: &Weight) -> Self::Balance { + let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); + let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); + + // Take the maximum instead of the sum to charge by the more scarce resource. + time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) + } + } + + /// Maps the reference time component of `Weight` to a fee. + pub struct RefTimeToFee; + impl WeightToFeePolynomial for RefTimeToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + // In Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // The standard system parachain configuration is 1/10 of that, as in 1/100 CENT. + let p = super::currency::CENTS; + let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); + + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } + + /// Maps the proof size component of `Weight` to a fee. + pub struct ProofSizeToFee; + impl WeightToFeePolynomial for ProofSizeToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + // Map 10kb proof to 1 CENT. + let p = super::currency::CENTS; + let q = 10_000; + + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } +} diff --git a/system-parachains/common/src/lib.rs b/system-parachains/common/src/lib.rs new file mode 100644 index 0000000000..17f3c339bc --- /dev/null +++ b/system-parachains/common/src/lib.rs @@ -0,0 +1,64 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod kusama; +pub mod polkadot; + +pub use constants::*; + +/// re-export types from upstream +pub use parachains_common::BlockNumber; + +/// Common constants of parachains. +mod constants { + use super::BlockNumber; + use frame_support::{ + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + PalletId, + }; + use sp_runtime::Perbill; + /// This determines the average expected block time that we are targeting. Blocks will be + /// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by + /// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn + /// slot_duration()`. + /// + /// Change this to adjust the block time. + pub const MILLISECS_PER_BLOCK: u64 = 12000; + pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; + + // Time is measured by number of blocks. + pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); + pub const HOURS: BlockNumber = MINUTES * 60; + pub const DAYS: BlockNumber = HOURS * 24; + + /// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is + /// used to limit the maximal weight of a single extrinsic. + pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); + /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by + /// Operational extrinsics. + pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); + + /// We allow for 0.5 seconds of compute with a 6 second average block time. + pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( + WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), + polkadot_primitives::MAX_POV_SIZE as u64, + ); + + /// Treasury pallet id of the local chain, used to convert into AccountId + pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry"); +} From f05c9500f85ef890f5b796ff3112a5a8ebda7938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Fri, 8 Dec 2023 18:10:55 +0000 Subject: [PATCH 02/12] Rename to constants --- Cargo.lock | 6 ++++++ system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml | 2 ++ system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml | 2 ++ system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 ++ .../bridge-hubs/bridge-hub-polkadot/Cargo.toml | 2 ++ .../collectives/collectives-polkadot/Cargo.toml | 2 ++ system-parachains/{common => constants}/Cargo.toml | 2 +- system-parachains/{common => constants}/src/kusama.rs | 0 system-parachains/{common => constants}/src/lib.rs | 0 system-parachains/gluttons/glutton-kusama/Cargo.toml | 2 ++ 10 files changed, 19 insertions(+), 1 deletion(-) rename system-parachains/{common => constants}/Cargo.toml (95%) rename system-parachains/{common => constants}/src/kusama.rs (100%) rename system-parachains/{common => constants}/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 3ffaa12c78..dace4df8bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -596,6 +596,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "system-parachains-common", ] [[package]] @@ -666,6 +667,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "system-parachains-common", ] [[package]] @@ -1325,6 +1327,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "system-parachains-common", ] [[package]] @@ -1389,6 +1392,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "system-parachains-common", ] [[package]] @@ -1890,6 +1894,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "system-parachains-common", ] [[package]] @@ -3961,6 +3966,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "system-parachains-common", ] [[package]] diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index c7abca8d60..b5e514e71f 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml @@ -81,6 +81,7 @@ cumulus-primitives-utility = { default-features = false , version = "0.4.0" } pallet-collator-selection = { default-features = false , version = "6.0.0" } parachain-info = { package = "staging-parachain-info", default-features = false , version = "0.4.0" } parachains-common = { default-features = false , version = "4.0.0" } +system-parachains-constants = { path = "../../constants", default-features = false } assets-common = { default-features = false , version = "0.4.0" } [dev-dependencies] @@ -223,6 +224,7 @@ std = [ "sp-version/std", "sp-weights/std", "substrate-wasm-builder", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index a3125308b7..0b626126ed 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -76,6 +76,7 @@ cumulus-primitives-utility = { default-features = false , version = "0.4.0" } pallet-collator-selection = { default-features = false , version = "6.0.0" } parachain-info = { package = "staging-parachain-info", default-features = false , version = "0.4.0" } parachains-common = { default-features = false , version = "4.0.0" } +system-parachains-constants = { path = "../../constants", default-features = false } assets-common = { default-features = false , version = "0.4.0" } [dev-dependencies] @@ -204,6 +205,7 @@ std = [ "sp-version/std", "sp-weights/std", "substrate-wasm-builder", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index ed7d2bf1f1..cecd47bb88 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -74,6 +74,7 @@ cumulus-primitives-utility = { default-features = false , version = "0.4.0" } pallet-collator-selection = { default-features = false , version = "6.0.0" } parachain-info = { package = "staging-parachain-info", default-features = false , version = "0.4.0" } parachains-common = { default-features = false , version = "4.0.0" } +system-parachains-constants = { path = "../../constants", default-features = false } [dev-dependencies] bridge-hub-test-utils = { version = "0.4.0" } @@ -133,6 +134,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 2e74c27c78..46aef5b926 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -74,6 +74,7 @@ cumulus-primitives-utility = { default-features = false , version = "0.4.0" } pallet-collator-selection = { default-features = false , version = "6.0.0" } parachain-info = { package = "staging-parachain-info", default-features = false , version = "0.4.0" } parachains-common = { default-features = false , version = "4.0.0" } +system-parachains-constants = { path = "../../constants", default-features = false } [dev-dependencies] bridge-hub-test-utils = { version = "0.4.0" } @@ -133,6 +134,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index dd0182ac0c..0bbf5bf237 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -78,6 +78,7 @@ cumulus-primitives-utility = { default-features = false , version = "0.4.0" } pallet-collator-selection = { default-features = false , version = "6.0.0" } parachain-info = { package = "staging-parachain-info", default-features = false , version = "0.4.0" } parachains-common = { default-features = false , version = "4.0.0" } +system-parachains-constants = { path = "../../constants", default-features = false } [build-dependencies] substrate-wasm-builder = { optional = true , version = "14.0.0" } @@ -206,6 +207,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/system-parachains/common/Cargo.toml b/system-parachains/constants/Cargo.toml similarity index 95% rename from system-parachains/common/Cargo.toml rename to system-parachains/constants/Cargo.toml index 54d7463015..2721f0a19c 100644 --- a/system-parachains/common/Cargo.toml +++ b/system-parachains/constants/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "system-parachains-common" +name = "system-parachains-constants" repository.workspace = true version.workspace = true authors.workspace = true diff --git a/system-parachains/common/src/kusama.rs b/system-parachains/constants/src/kusama.rs similarity index 100% rename from system-parachains/common/src/kusama.rs rename to system-parachains/constants/src/kusama.rs diff --git a/system-parachains/common/src/lib.rs b/system-parachains/constants/src/lib.rs similarity index 100% rename from system-parachains/common/src/lib.rs rename to system-parachains/constants/src/lib.rs diff --git a/system-parachains/gluttons/glutton-kusama/Cargo.toml b/system-parachains/gluttons/glutton-kusama/Cargo.toml index f86a9159d1..1399159633 100644 --- a/system-parachains/gluttons/glutton-kusama/Cargo.toml +++ b/system-parachains/gluttons/glutton-kusama/Cargo.toml @@ -46,6 +46,7 @@ cumulus-pallet-xcm = { default-features = false , version = "0.4.0" } cumulus-primitives-core = { default-features = false , version = "0.4.0" } parachain-info = { package = "staging-parachain-info", default-features = false , version = "0.4.0" } parachains-common = { default-features = false , version = "4.0.0" } +system-parachains-constants = { path = "../../constants", default-features = false } [build-dependencies] substrate-wasm-builder = { version = "14.0.0" } @@ -94,6 +95,7 @@ std = [ "sp-storage/std", "sp-transaction-pool/std", "sp-version/std", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", From 7f86f41f582f79dfa967d81536fef7c5cec66d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Fri, 8 Dec 2023 18:15:32 +0000 Subject: [PATCH 03/12] Actually rename it in workspace --- Cargo.lock | 14 +++++++------- Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dace4df8bf..ae1d2934dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -596,7 +596,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "system-parachains-common", + "system-parachains-constants", ] [[package]] @@ -667,7 +667,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "system-parachains-common", + "system-parachains-constants", ] [[package]] @@ -1327,7 +1327,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "system-parachains-common", + "system-parachains-constants", ] [[package]] @@ -1392,7 +1392,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "system-parachains-common", + "system-parachains-constants", ] [[package]] @@ -1894,7 +1894,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "system-parachains-common", + "system-parachains-constants", ] [[package]] @@ -3966,7 +3966,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "system-parachains-common", + "system-parachains-constants", ] [[package]] @@ -11835,7 +11835,7 @@ dependencies = [ ] [[package]] -name = "system-parachains-common" +name = "system-parachains-constants" version = "1.0.0" dependencies = [ "frame-support", diff --git a/Cargo.toml b/Cargo.toml index 994a3df509..77c699d3c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ members = [ "system-parachains/bridge-hubs/bridge-hub-kusama", "system-parachains/bridge-hubs/bridge-hub-polkadot", "system-parachains/collectives/collectives-polkadot", - "system-parachains/common", + "system-parachains/constants", "system-parachains/gluttons/glutton-kusama", ] From 1e6da9996a45959a46ee866999c94829102da09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Fri, 8 Dec 2023 18:33:11 +0000 Subject: [PATCH 04/12] Use constants from fellowship crate --- .../asset-hubs/asset-hub-kusama/src/lib.rs | 15 +++++++++------ .../asset-hubs/asset-hub-kusama/src/xcm_config.rs | 2 +- .../asset-hubs/asset-hub-kusama/tests/tests.rs | 5 ++--- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 13 +++++++++---- .../asset-hub-polkadot/src/xcm_config.rs | 2 +- .../asset-hubs/asset-hub-polkadot/tests/tests.rs | 4 ++-- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 7 ++++--- .../bridge-hub-kusama/src/xcm_config.rs | 2 +- .../bridge-hubs/bridge-hub-kusama/tests/tests.rs | 3 ++- .../bridge-hubs/bridge-hub-polkadot/src/lib.rs | 7 ++++--- .../bridge-hub-polkadot/src/xcm_config.rs | 2 +- .../bridge-hub-polkadot/tests/tests.rs | 3 ++- .../collectives-polkadot/src/fellowship/mod.rs | 2 +- .../collectives/collectives-polkadot/src/lib.rs | 8 +++++--- .../collectives-polkadot/src/xcm_config.rs | 2 +- 15 files changed, 45 insertions(+), 32 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 1d03f75a01..af33dcb8cf 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -67,15 +67,18 @@ use frame_system::{ }; use pallet_asset_conversion_tx_payment::AssetConversionAdapter; use pallet_nfts::PalletFeatures; +// TODO make combined mod to re-export pub use parachains_common as common; use parachains_common::{ - impls::DealWithFees, - kusama::{consensus::*, currency::*, fee::WeightToFee}, - AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, Nonce, - Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, - NORMAL_DISPATCH_RATIO, SLOT_DURATION, + impls::DealWithFees, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, + Hash, Header, Nonce, Signature, }; use sp_runtime::RuntimeDebug; +use system_parachains_constants::{ + kusama::{consensus::*, currency::*, fee::WeightToFee}, + AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, + SLOT_DURATION, +}; use xcm::opaque::v3::MultiLocation; use xcm_config::{ FellowshipLocation, ForeignAssetsConvertedConcreteId, GovernanceLocation, KsmLocation, @@ -1483,9 +1486,9 @@ fn ensure_key_ss58() { mod tests { use super::*; use crate::{CENTS, MILLICENTS}; - use parachains_common::kusama::fee; use sp_runtime::traits::Zero; use sp_weights::WeightToFee; + use system_parachains_constants::kusama::fee; /// We can fit at least 1000 transfers in a block. #[test] diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 13fb5bdd8c..f64d61f98b 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -36,10 +36,10 @@ use parachains_common::{ AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, RelayOrOtherSystemParachains, }, - TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 20477cb24e..f207fb83de 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -34,10 +34,9 @@ use frame_support::{ traits::fungibles::InspectEnumerable, weights::{Weight, WeightToFee as WeightToFeeT}, }; -use parachains_common::{ - kusama::fee::WeightToFee, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, -}; +use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}; use sp_runtime::traits::MaybeEquivalence; +use system_parachains_constants::kusama::fee::WeightToFee; use xcm::latest::prelude::*; use xcm_executor::traits::{Identity, JustTry, WeightTrader}; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 2c62e27069..e05e9edf30 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -98,15 +98,20 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_nfts::PalletFeatures; +// TODO make combined mod to re-export pub use parachains_common as common; use parachains_common::{ impls::{AssetsToBlockAuthor, DealWithFees}, - polkadot::{consensus::*, currency::*, fee::WeightToFee}, AccountId, AssetHubPolkadotAuraId as AuraId, AssetIdForTrustBackedAssets, Balance, BlockNumber, - Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, - NORMAL_DISPATCH_RATIO, SLOT_DURATION, + Hash, Header, Nonce, Signature, }; + use sp_runtime::RuntimeDebug; +use system_parachains_constants::{ + polkadot::{consensus::*, currency::*, fee::WeightToFee}, + AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, + SLOT_DURATION, +}; use xcm_config::{ DotLocation, FellowshipLocation, ForeignAssetsConvertedConcreteId, GovernanceLocation, TrustBackedAssetsConvertedConcreteId, XcmConfig, XcmOriginToTransactDispatchOrigin, @@ -1317,9 +1322,9 @@ cumulus_pallet_parachain_system::register_validate_block! { mod tests { use super::*; use crate::{CENTS, MILLICENTS}; - use parachains_common::polkadot::fee; use sp_runtime::traits::Zero; use sp_weights::WeightToFee; + use system_parachains_constants::polkadot::fee; /// We can fit at least 1000 transfers in a block. #[test] diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 92776aa1dc..3ae0ef162d 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -31,11 +31,11 @@ use parachains_common::{ AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, RelayOrOtherSystemParachains, }, - TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 5af2c63c18..c56381e099 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -35,10 +35,10 @@ use frame_support::{ weights::{Weight, WeightToFee as WeightToFeeT}, }; use parachains_common::{ - polkadot::fee::WeightToFee, AccountId, AssetHubPolkadotAuraId as AuraId, - AssetIdForTrustBackedAssets, Balance, + AccountId, AssetHubPolkadotAuraId as AuraId, AssetIdForTrustBackedAssets, Balance, }; use sp_runtime::traits::MaybeEquivalence; +use system_parachains_constants::polkadot::fee::WeightToFee; use xcm::latest::prelude::*; use xcm_executor::traits::{Identity, JustTry, WeightTrader}; diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index f0d5f8a3cb..8a694b432e 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -68,10 +68,11 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use parachains_common::{ - impls::DealWithFees, + impls::DealWithFees, AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, +}; +use system_parachains_constants::{ kusama::{consensus::*, currency::*, fee::WeightToFee}, - AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, - HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, + AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; // XCM Imports diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 3a1ac9c8b1..a6085806f6 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -29,10 +29,10 @@ use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::AccountIdConversion; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 893524e12f..54ebc96a7a 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -20,7 +20,8 @@ pub use bridge_hub_kusama_runtime::{ }; use codec::Decode; use frame_support::parameter_types; -use parachains_common::{kusama::fee::WeightToFee, AccountId, AuraId}; +use parachains_common::{AccountId, AuraId}; +use system_parachains_constants::kusama::fee::WeightToFee; const ALICE: [u8; 32] = [1u8; 32]; diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index a811d768bd..8b93995261 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -69,10 +69,11 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use parachains_common::{ - impls::DealWithFees, + impls::DealWithFees, AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, +}; +use system_parachains_constants::{ polkadot::{consensus::*, currency::*, fee::WeightToFee}, - AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, - HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, + AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; // XCM Imports use xcm::prelude::*; diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index be8f1dfa00..853cf81600 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -28,11 +28,11 @@ use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use sp_runtime::traits::AccountIdConversion; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 0be87bd46f..1529f77025 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -20,7 +20,8 @@ pub use bridge_hub_polkadot_runtime::{ }; use codec::Decode; use frame_support::parameter_types; -use parachains_common::{polkadot::fee::WeightToFee, AccountId, AuraId}; +use parachains_common::{AccountId, AuraId}; +use system_parachains_constants::polkadot::fee::WeightToFee; const ALICE: [u8; 32] = [1u8; 32]; diff --git a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs index f8abba46e2..2b684cd6d7 100644 --- a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -35,10 +35,10 @@ pub use origins::{ }; use pallet_ranked_collective::EnsureOfRank; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; -use parachains_common::polkadot::account; use polkadot_runtime_constants::{time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX}; use sp_core::{ConstU128, ConstU32}; use sp_runtime::traits::{AccountIdConversion, ConstU16, ConvertToValue, Replace, TakeFirst}; +use system_parachains_constants::polkadot::account; use xcm::latest::BodyId; use xcm_builder::{AliasesIntoAccountId32, LocatableAssetId, PayOverXcm}; diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index c3d12985ef..819e6bda00 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -76,15 +76,17 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; +// TODO make combined mod to re-export pub use parachains_common as common; use parachains_common::{ - impls::DealWithFees, + impls::DealWithFees, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature, +}; +use sp_runtime::RuntimeDebug; +use system_parachains_constants::{ polkadot::{account::*, consensus::*, currency::*, fee::WeightToFee}, - AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; -use sp_runtime::RuntimeDebug; use xcm_config::{GovernanceLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index c609b491d1..0832b627ff 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -28,11 +28,11 @@ use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, xcm_config::{ConcreteAssetFromSystem, RelayOrOtherSystemParachains}, - TREASURY_PALLET_ID, }; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use sp_runtime::traits::AccountIdConversion; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, From 094bcec9de0f4d2dd11364e44fe4c05ce7718bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Tue, 12 Dec 2023 15:47:11 +0000 Subject: [PATCH 05/12] Add explicitly ignored file --- system-parachains/constants/src/polkadot.rs | 144 ++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 system-parachains/constants/src/polkadot.rs diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs new file mode 100644 index 0000000000..ca41383034 --- /dev/null +++ b/system-parachains/constants/src/polkadot.rs @@ -0,0 +1,144 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// Universally recognized accounts. +pub mod account { + use frame_support::PalletId; + + /// Polkadot treasury pallet id, used to convert into AccountId + pub const POLKADOT_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry"); + /// Alliance pallet ID. + /// It is used as a temporarily place to deposit a slashed imbalance + /// before the teleport to the Treasury. + pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia"); + /// Referenda pallet ID. + /// It is used as a temporarily place to deposit a slashed imbalance + /// before the teleport to the Treasury. + pub const REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/refer"); + /// Ambassador Referenda pallet ID. + /// It is used as a temporarily place to deposit a slashed imbalance + /// before the teleport to the Treasury. + pub const AMBASSADOR_REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/amref"); + /// Fellowship treasury pallet ID + pub const FELLOWSHIP_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/feltr"); +} + +/// Consensus-related. +pub mod consensus { + /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included + /// into the relay chain. + pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; + /// How many parachain blocks are processed by the relay chain per parent. Limits the + /// number of blocks authored per slot. + pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; + /// Relay chain slot duration, in milliseconds. + pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; +} + +/// Constants relating to DOT. +pub mod currency { + use polkadot_core_primitives::Balance; + + /// The existential deposit. Set to 1/10 of its parent Relay Chain. + pub const EXISTENTIAL_DEPOSIT: Balance = 100 * CENTS / 10; + + pub const UNITS: Balance = 10_000_000_000; + pub const DOLLARS: Balance = UNITS; // 10_000_000_000 + pub const GRAND: Balance = DOLLARS * 1_000; // 10_000_000_000_000 + pub const CENTS: Balance = DOLLARS / 100; // 100_000_000 + pub const MILLICENTS: Balance = CENTS / 1_000; // 100_000 + + pub const fn deposit(items: u32, bytes: u32) -> Balance { + // 1/100 of Polkadot + (items as Balance * 20 * DOLLARS + (bytes as Balance) * 100 * MILLICENTS) / 100 + } +} + +/// Constants related to Polkadot fee payment. +pub mod fee { + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, + }; + use polkadot_core_primitives::Balance; + use smallvec::smallvec; + pub use sp_runtime::Perbill; + + /// The block saturation level. Fees will be updates based on this value. + pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); + + /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the + /// node's balance type. + /// + /// This should typically create a mapping between the following ranges: + /// - [0, MAXIMUM_BLOCK_WEIGHT] + /// - [Balance::min, Balance::max] + /// + /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: + /// - Setting it to `0` will essentially disable the weight fee. + /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. + pub struct WeightToFee; + impl frame_support::weights::WeightToFee for WeightToFee { + type Balance = Balance; + + fn weight_to_fee(weight: &Weight) -> Self::Balance { + let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); + let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); + + // Take the maximum instead of the sum to charge by the more scarce resource. + time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) + } + } + + /// Maps the reference time component of `Weight` to a fee. + pub struct RefTimeToFee; + impl WeightToFeePolynomial for RefTimeToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + // In Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // The standard system parachain configuration is 1/10 of that, as in 1/100 CENT. + let p = super::currency::CENTS; + let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); + + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } + + /// Maps the proof size component of `Weight` to a fee. + pub struct ProofSizeToFee; + impl WeightToFeePolynomial for ProofSizeToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + // Map 10kb proof to 1 CENT. + let p = super::currency::CENTS; + let q = 10_000; + + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } +} From 9736cb02b2da2034ab199557bdd7e2f4f3b27106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Wed, 13 Dec 2023 09:53:14 +0000 Subject: [PATCH 06/12] Use relay ED and deposit calculations in system parachains --- Cargo.lock | 2 ++ .../collectives/collectives-polkadot/Cargo.toml | 6 +++--- system-parachains/constants/Cargo.toml | 4 ++++ system-parachains/constants/src/kusama.rs | 8 ++++---- system-parachains/constants/src/polkadot.rs | 8 ++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed063a7afb..0c68e51ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11846,9 +11846,11 @@ name = "system-parachains-constants" version = "1.0.0" dependencies = [ "frame-support", + "kusama-runtime-constants", "parachains-common", "polkadot-core-primitives", "polkadot-primitives", + "polkadot-runtime-constants", "smallvec", "sp-runtime", ] diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index cd66f78262..d45f676231 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -95,8 +95,8 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", - "pallet-asset-rate/runtime-benchmarks", "pallet-alliance/runtime-benchmarks", + "pallet-asset-rate/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", @@ -128,8 +128,8 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime/try-runtime", - "pallet-asset-rate/try-runtime", "pallet-alliance/try-runtime", + "pallet-asset-rate/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", @@ -171,8 +171,8 @@ std = [ "frame-system/std", "frame-try-runtime?/std", "log/std", - "pallet-asset-rate/std", "pallet-alliance/std", + "pallet-asset-rate/std", "pallet-aura/std", "pallet-authorship/std", "pallet-balances/std", diff --git a/system-parachains/constants/Cargo.toml b/system-parachains/constants/Cargo.toml index 2721f0a19c..3946d0cc17 100644 --- a/system-parachains/constants/Cargo.toml +++ b/system-parachains/constants/Cargo.toml @@ -16,6 +16,8 @@ sp-runtime = { default-features = false , version = "28.0.0" } # Polkadot polkadot-core-primitives = { default-features = false, version = "4.0.0"} polkadot-primitives = { default-features = false , version = "4.0.0" } +polkadot-runtime-constants = { path = "../../relay/polkadot/constants", default-features = false} +kusama-runtime-constants = { path = "../../relay/kusama/constants", default-features = false} # Cumulus parachains-common = { default-features = false , version = "4.0.0" } @@ -24,8 +26,10 @@ parachains-common = { default-features = false , version = "4.0.0" } default = [ "std" ] std = [ "frame-support/std", + "kusama-runtime-constants/std", "parachains-common/std", "polkadot-core-primitives/std", "polkadot-primitives/std", + "polkadot-runtime-constants/std", "sp-runtime/std", ] diff --git a/system-parachains/constants/src/kusama.rs b/system-parachains/constants/src/kusama.rs index 073971a707..2b91f06d79 100644 --- a/system-parachains/constants/src/kusama.rs +++ b/system-parachains/constants/src/kusama.rs @@ -29,8 +29,9 @@ pub mod consensus { pub mod currency { use polkadot_core_primitives::Balance; - /// The existential deposit. Set to 1/10 of its parent Relay Chain. - pub const EXISTENTIAL_DEPOSIT: Balance = 1 * CENTS / 10; + /// The existential deposit. + pub const EXISTENTIAL_DEPOSIT: Balance = + kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10; pub const UNITS: Balance = 1_000_000_000_000; pub const QUID: Balance = UNITS / 30; @@ -39,8 +40,7 @@ pub mod currency { pub const MILLICENTS: Balance = CENTS / 1_000; pub const fn deposit(items: u32, bytes: u32) -> Balance { - // map to 1/100 of what the kusama relay chain charges (v9020) - (items as Balance * 2_000 * CENTS + (bytes as Balance) * 100 * MILLICENTS) / 100 + kusama_runtime_constants::currency::deposit(items, bytes) / 100 } } diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs index ca41383034..15b3aa66f1 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -51,8 +51,9 @@ pub mod consensus { pub mod currency { use polkadot_core_primitives::Balance; - /// The existential deposit. Set to 1/10 of its parent Relay Chain. - pub const EXISTENTIAL_DEPOSIT: Balance = 100 * CENTS / 10; + /// The existential deposit. + pub const EXISTENTIAL_DEPOSIT: Balance = + polkadot_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10; pub const UNITS: Balance = 10_000_000_000; pub const DOLLARS: Balance = UNITS; // 10_000_000_000 @@ -61,8 +62,7 @@ pub mod currency { pub const MILLICENTS: Balance = CENTS / 1_000; // 100_000 pub const fn deposit(items: u32, bytes: u32) -> Balance { - // 1/100 of Polkadot - (items as Balance * 20 * DOLLARS + (bytes as Balance) * 100 * MILLICENTS) / 100 + polkadot_runtime_constants::currency::deposit(items, bytes) / 100 } } From 40f4ac0625164d32d66eeb0902a4626e37626e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Thu, 21 Dec 2023 10:25:41 +0000 Subject: [PATCH 07/12] Remove re-exports These should be imported from parachains_common directly, not through the runtimes. --- system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs | 2 -- system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 2 -- system-parachains/collectives/collectives-polkadot/src/lib.rs | 2 -- 3 files changed, 6 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index af33dcb8cf..45baa5a16e 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -67,8 +67,6 @@ use frame_system::{ }; use pallet_asset_conversion_tx_payment::AssetConversionAdapter; use pallet_nfts::PalletFeatures; -// TODO make combined mod to re-export -pub use parachains_common as common; use parachains_common::{ impls::DealWithFees, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature, diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index e05e9edf30..8dc01e93e3 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -98,8 +98,6 @@ use frame_system::{ EnsureRoot, EnsureSigned, }; use pallet_nfts::PalletFeatures; -// TODO make combined mod to re-export -pub use parachains_common as common; use parachains_common::{ impls::{AssetsToBlockAuthor, DealWithFees}, AccountId, AssetHubPolkadotAuraId as AuraId, AssetIdForTrustBackedAssets, Balance, BlockNumber, diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index 6d8dc1b11c..1a0e82c052 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -77,8 +77,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; -// TODO make combined mod to re-export -pub use parachains_common as common; use parachains_common::{ impls::DealWithFees, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Nonce, Signature, }; From afa38574fe34b31377b840c2ccf6a20f9de0f6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Wed, 3 Jan 2024 11:06:20 +0000 Subject: [PATCH 08/12] Propagate changes from people pallet addition --- system-parachains/constants/src/polkadot.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs index 15b3aa66f1..dfca992715 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -20,17 +20,17 @@ pub mod account { /// Polkadot treasury pallet id, used to convert into AccountId pub const POLKADOT_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry"); /// Alliance pallet ID. - /// It is used as a temporarily place to deposit a slashed imbalance - /// before the teleport to the Treasury. + /// Used as a temporary place to deposit a slashed imbalance before teleporting to the Treasury. pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia"); /// Referenda pallet ID. - /// It is used as a temporarily place to deposit a slashed imbalance - /// before the teleport to the Treasury. + /// Used as a temporary place to deposit a slashed imbalance before teleporting to the Treasury. pub const REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/refer"); /// Ambassador Referenda pallet ID. - /// It is used as a temporarily place to deposit a slashed imbalance - /// before the teleport to the Treasury. + /// Used as a temporary place to deposit a slashed imbalance before teleporting to the Treasury. pub const AMBASSADOR_REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/amref"); + /// Identity pallet ID. + /// Used as a temporary place to deposit a slashed imbalance before teleporting to the Treasury. + pub const IDENTITY_PALLET_ID: PalletId = PalletId(*b"py/ident"); /// Fellowship treasury pallet ID pub const FELLOWSHIP_TREASURY_PALLET_ID: PalletId = PalletId(*b"py/feltr"); } From 6542acb3e22f518882a150eac658f2618ae41f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Wed, 3 Jan 2024 13:34:04 +0000 Subject: [PATCH 09/12] Add description --- system-parachains/constants/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/system-parachains/constants/Cargo.toml b/system-parachains/constants/Cargo.toml index 3946d0cc17..fd3b85813b 100644 --- a/system-parachains/constants/Cargo.toml +++ b/system-parachains/constants/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "system-parachains-constants" +description = "Common constants for System Parachains runtimes" repository.workspace = true version.workspace = true authors.workspace = true From 0c7db1d1145b17c343616755c94729fb63f81a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Wed, 3 Jan 2024 13:39:52 +0000 Subject: [PATCH 10/12] Apply suggestions from OTY code review Co-authored-by: Oliver Tale-Yazdi --- system-parachains/constants/src/kusama.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system-parachains/constants/src/kusama.rs b/system-parachains/constants/src/kusama.rs index 2b91f06d79..3ae72f6514 100644 --- a/system-parachains/constants/src/kusama.rs +++ b/system-parachains/constants/src/kusama.rs @@ -29,7 +29,7 @@ pub mod consensus { pub mod currency { use polkadot_core_primitives::Balance; - /// The existential deposit. + /// The existential deposit. 1/10th of the relay deposit. pub const EXISTENTIAL_DEPOSIT: Balance = kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10; @@ -39,6 +39,7 @@ pub mod currency { pub const GRAND: Balance = QUID * 1_000; pub const MILLICENTS: Balance = CENTS / 1_000; + /// Deposit for stored data. 1/100th of the relay deposit. pub const fn deposit(items: u32, bytes: u32) -> Balance { kusama_runtime_constants::currency::deposit(items, bytes) / 100 } From 8a4cedfa1d4319fe17ac95a0a3c4b0d0b56d2cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Wed, 3 Jan 2024 13:46:21 +0000 Subject: [PATCH 11/12] Combine and sort polkadot-sdk dependencies --- system-parachains/constants/Cargo.toml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/system-parachains/constants/Cargo.toml b/system-parachains/constants/Cargo.toml index fd3b85813b..20bd904bf3 100644 --- a/system-parachains/constants/Cargo.toml +++ b/system-parachains/constants/Cargo.toml @@ -10,18 +10,13 @@ license.workspace = true [dependencies] smallvec = "1.8.0" -# Substrate frame-support = { default-features = false , version = "25.0.0" } -sp-runtime = { default-features = false , version = "28.0.0" } - -# Polkadot +kusama-runtime-constants = { path = "../../relay/kusama/constants", default-features = false} +parachains-common = { default-features = false , version = "4.0.0" } polkadot-core-primitives = { default-features = false, version = "4.0.0"} polkadot-primitives = { default-features = false , version = "4.0.0" } polkadot-runtime-constants = { path = "../../relay/polkadot/constants", default-features = false} -kusama-runtime-constants = { path = "../../relay/kusama/constants", default-features = false} - -# Cumulus -parachains-common = { default-features = false , version = "4.0.0" } +sp-runtime = { default-features = false , version = "28.0.0" } [features] default = [ "std" ] From 332998dbd401f6e7beeb0c76385e9575d24680f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Wed, 3 Jan 2024 13:49:58 +0000 Subject: [PATCH 12/12] Remove constants mod --- system-parachains/constants/src/lib.rs | 77 ++++++++++++-------------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/system-parachains/constants/src/lib.rs b/system-parachains/constants/src/lib.rs index 17f3c339bc..d0d320d968 100644 --- a/system-parachains/constants/src/lib.rs +++ b/system-parachains/constants/src/lib.rs @@ -19,46 +19,39 @@ pub mod kusama; pub mod polkadot; -pub use constants::*; - -/// re-export types from upstream +use frame_support::{ + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + PalletId, +}; pub use parachains_common::BlockNumber; - -/// Common constants of parachains. -mod constants { - use super::BlockNumber; - use frame_support::{ - weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, - PalletId, - }; - use sp_runtime::Perbill; - /// This determines the average expected block time that we are targeting. Blocks will be - /// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by - /// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn - /// slot_duration()`. - /// - /// Change this to adjust the block time. - pub const MILLISECS_PER_BLOCK: u64 = 12000; - pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; - - // Time is measured by number of blocks. - pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); - pub const HOURS: BlockNumber = MINUTES * 60; - pub const DAYS: BlockNumber = HOURS * 24; - - /// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is - /// used to limit the maximal weight of a single extrinsic. - pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); - /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by - /// Operational extrinsics. - pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); - - /// We allow for 0.5 seconds of compute with a 6 second average block time. - pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( - WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), - polkadot_primitives::MAX_POV_SIZE as u64, - ); - - /// Treasury pallet id of the local chain, used to convert into AccountId - pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry"); -} +use sp_runtime::Perbill; + +/// This determines the average expected block time that we are targeting. Blocks will be +/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by +/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn +/// slot_duration()`. +/// +/// Change this to adjust the block time. +pub const MILLISECS_PER_BLOCK: u64 = 12000; +pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; + +// Time is measured by number of blocks. +pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); +pub const HOURS: BlockNumber = MINUTES * 60; +pub const DAYS: BlockNumber = HOURS * 24; + +/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is +/// used to limit the maximal weight of a single extrinsic. +pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); +/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by +/// Operational extrinsics. +pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); + +/// We allow for 0.5 seconds of compute with a 6 second average block time. +pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( + WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), + polkadot_primitives::MAX_POV_SIZE as u64, +); + +/// Treasury pallet id of the local chain, used to convert into AccountId +pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");