From c5ae80d4e58bfbe0d77d5a5c41feb9c3491af67b Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 15 Mar 2023 17:28:42 +0100 Subject: [PATCH 1/8] Generalize trait requirement Use the trait directly instead of something that will have a blanket implementation for it. Signed-off-by: Oliver Tale-Yazdi --- parachains/common/src/xcm_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachains/common/src/xcm_config.rs b/parachains/common/src/xcm_config.rs index 753aa97c6fe..04f73c6b7e7 100644 --- a/parachains/common/src/xcm_config.rs +++ b/parachains/common/src/xcm_config.rs @@ -3,7 +3,7 @@ use core::{marker::PhantomData, ops::ControlFlow}; use frame_support::{ log, traits::{fungibles::Inspect, tokens::BalanceConversion, ContainsPair}, - weights::{Weight, WeightToFee, WeightToFeePolynomial}, + weights::Weight, }; use sp_runtime::traits::Get; use xcm::{latest::prelude::*, CreateMatcher, MatchXcm}; @@ -95,7 +95,7 @@ impl > for AssetFeeAsExistentialDepositMultiplier where Runtime: pallet_assets::Config, - WeightToFee: WeightToFeePolynomial, + WeightToFee: frame_support::weights::WeightToFee, BalanceConverter: BalanceConversion< CurrencyBalance, >::AssetId, From 7855684420305aac46dbddb8c9c8e035137548df Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 15 Mar 2023 17:29:35 +0100 Subject: [PATCH 2/8] Charge for proof size weight Signed-off-by: Oliver Tale-Yazdi --- .../runtimes/assets/statemine/Cargo.toml | 3 +- .../assets/statemine/src/constants.rs | 38 ++++++++++++- .../runtimes/assets/statemine/src/lib.rs | 56 +++++++++++++++++++ .../runtimes/assets/statemint/Cargo.toml | 1 + .../assets/statemint/src/constants.rs | 43 ++++++++++++-- .../runtimes/assets/statemint/src/lib.rs | 56 +++++++++++++++++++ .../runtimes/assets/westmint/src/constants.rs | 47 ++++++++++++++-- .../bridge-hub-kusama/src/constants.rs | 45 +++++++++++++-- .../bridge-hub-polkadot/src/constants.rs | 38 ++++++++++++- .../bridge-hub-rococo/src/constants.rs | 47 ++++++++++++++-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 39 +++++++++++-- .../collectives-polkadot/src/constants.rs | 43 ++++++++++++-- .../contracts-rococo/src/constants.rs | 34 ++++++++++- parachains/runtimes/testing/penpal/src/lib.rs | 40 +++++++++++-- 14 files changed, 487 insertions(+), 43 deletions(-) diff --git a/parachains/runtimes/assets/statemine/Cargo.toml b/parachains/runtimes/assets/statemine/Cargo.toml index 0f0921976a8..d114d06ba02 100644 --- a/parachains/runtimes/assets/statemine/Cargo.toml +++ b/parachains/runtimes/assets/statemine/Cargo.toml @@ -28,6 +28,7 @@ pallet-balances = { git = "https://github.com/paritytech/substrate", default-fea pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-state-trie-migration = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master", optional = true } pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } @@ -44,7 +45,7 @@ sp-session = { git = "https://github.com/paritytech/substrate", default-features sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } -pallet-state-trie-migration = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master", optional = true } +sp-weights = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } # Polkadot kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } diff --git a/parachains/runtimes/assets/statemine/src/constants.rs b/parachains/runtimes/assets/statemine/src/constants.rs index 6dccf0089ca..e53da737d02 100644 --- a/parachains/runtimes/assets/statemine/src/constants.rs +++ b/parachains/runtimes/assets/statemine/src/constants.rs @@ -34,8 +34,8 @@ pub mod currency { /// Fee-related. pub mod fee { use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + constants::ExtrinsicBaseWeight, FeePolynomial, Weight, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; @@ -55,13 +55,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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: // in Statemine, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index b937e7c1397..dddf3dae010 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -1117,3 +1117,59 @@ fn ensure_key_ss58() { assert_eq!(acc, RootMigController::sorted_members()[0]); //panic!("{:x?}", acc); } + +#[cfg(test)] +mod tests { + use super::{constants::fee, *}; + use crate::{CENTS, MILLICENTS}; + use sp_runtime::traits::Zero; + use sp_weights::WeightToFee; + + /// We can fit at least 1000 transfers in a block. + #[test] + fn sane_block_weight() { + use pallet_balances::WeightInfo; + let block = RuntimeBlockWeights::get().max_block; + let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; + let transfer = base + weights::pallet_balances::WeightInfo::::transfer(); + + let fit = block.checked_div_per_component(&transfer).unwrap_or_default(); + assert!(fit >= 1000, "{} should be at least 1000", fit); + } + + /// The fee for one transfer it at most 1 CENT. + #[test] + fn sane_transfer_fee() { + use pallet_balances::WeightInfo; + let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; + let transfer = base + weights::pallet_balances::WeightInfo::::transfer(); + + let fee: Balance = fee::WeightToFee::weight_to_fee(&transfer); + assert!(fee <= CENTS, "{} MILLICENTS should be at most 1000", fee / MILLICENTS); + } + + /// Weight is being charged for both dimensions. + #[test] + fn weight_charged_for_both_components() { + let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(10_000, 0)); + assert!(!fee.is_zero(), "Charges for ref time"); + + let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, 10_000)); + assert_eq!(fee, CENTS, "10kb maps to CENT"); + } + + /// Filling up a block by proof size is at most 30 times more expensive then ref time. + /// + /// This is just a sanity check. + #[test] + fn full_block_fee_ratio() { + let block = RuntimeBlockWeights::get().max_block; + let time_fee: Balance = fee::WeightToFee::weight_to_fee(&block.without_proof_size()); + let proof_fee: Balance = fee::WeightToFee::weight_to_fee(&block.without_ref_time()); + + let proof_o_time = proof_fee.checked_div(time_fee).unwrap_or_default(); + assert!(proof_o_time <= 30, "{} should be at most 30", proof_o_time); + let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default(); + assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof); + } +} diff --git a/parachains/runtimes/assets/statemint/Cargo.toml b/parachains/runtimes/assets/statemint/Cargo.toml index f6d54cbd85f..89d08d23ab3 100644 --- a/parachains/runtimes/assets/statemint/Cargo.toml +++ b/parachains/runtimes/assets/statemint/Cargo.toml @@ -44,6 +44,7 @@ sp-session = { git = "https://github.com/paritytech/substrate", default-features sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-weights = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } # Polkadot pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } diff --git a/parachains/runtimes/assets/statemint/src/constants.rs b/parachains/runtimes/assets/statemint/src/constants.rs index 393f62858cd..af331652e2a 100644 --- a/parachains/runtimes/assets/statemint/src/constants.rs +++ b/parachains/runtimes/assets/statemint/src/constants.rs @@ -34,12 +34,13 @@ pub mod currency { /// Fee-related. pub mod fee { use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; pub use sp_runtime::Perbill; + use sp_weights::Weight; /// The block saturation level. Fees will be updates based on this value. pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); @@ -55,13 +56,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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: - // in Statemint, we map to 1/10 of that, or 1/100 CENT + // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Statemine, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 0e27fa58fb5..53eec2bacb7 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -1069,3 +1069,59 @@ cumulus_pallet_parachain_system::register_validate_block! { BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, CheckInherents = CheckInherents, } + +#[cfg(test)] +mod tests { + use super::{constants::fee, *}; + use crate::{CENTS, MILLICENTS}; + use sp_runtime::traits::Zero; + use sp_weights::WeightToFee; + + /// We can fit at least 1000 transfers in a block. + #[test] + fn sane_block_weight() { + use pallet_balances::WeightInfo; + let block = RuntimeBlockWeights::get().max_block; + let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; + let transfer = base + weights::pallet_balances::WeightInfo::::transfer(); + + let fit = block.checked_div_per_component(&transfer).unwrap_or_default(); + assert!(fit >= 1000, "{} should be at least 1000", fit); + } + + /// The fee for one transfer it at most 1 CENT. + #[test] + fn sane_transfer_fee() { + use pallet_balances::WeightInfo; + let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; + let transfer = base + weights::pallet_balances::WeightInfo::::transfer(); + + let fee: Balance = fee::WeightToFee::weight_to_fee(&transfer); + assert!(fee <= CENTS, "{} MILLICENTS should be at most 1000", fee / MILLICENTS); + } + + /// Weight is being charged for both dimensions. + #[test] + fn weight_charged_for_both_components() { + let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(10_000, 0)); + assert!(!fee.is_zero(), "Charges for ref time"); + + let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, 10_000)); + assert_eq!(fee, CENTS, "10kb maps to CENT"); + } + + /// Filling up a block by proof size is at most 30 times more expensive then ref time. + /// + /// This is just a sanity check. + #[test] + fn full_block_fee_ratio() { + let block = RuntimeBlockWeights::get().max_block; + let time_fee: Balance = fee::WeightToFee::weight_to_fee(&block.without_proof_size()); + let proof_fee: Balance = fee::WeightToFee::weight_to_fee(&block.without_ref_time()); + + let proof_o_time = proof_fee.checked_div(time_fee).unwrap_or_default(); + assert!(proof_o_time <= 30, "{} should be at most 30", proof_o_time); + let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default(); + assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof); + } +} diff --git a/parachains/runtimes/assets/westmint/src/constants.rs b/parachains/runtimes/assets/westmint/src/constants.rs index 8a94ad2ad9f..64bc38fc8ac 100644 --- a/parachains/runtimes/assets/westmint/src/constants.rs +++ b/parachains/runtimes/assets/westmint/src/constants.rs @@ -33,9 +33,12 @@ pub mod currency { /// Fee-related. pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; @@ -55,13 +58,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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: - // in Statemint, we map to 1/10 of that, or 1/100 CENT + // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Statemine, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs index c4943f85232..8605afa3e8e 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs @@ -32,9 +32,12 @@ pub mod currency { /// Fee-related. pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; @@ -51,13 +54,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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: - // in BridgeHub, we map to 1/10 of that, or 1/100 CENT + // in Statemine, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs index de22cf7883a..4c426cb8b12 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs @@ -51,13 +51,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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: - // in BridgeHub, we map to 1/10 of that, or 1/100 CENT + // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Statemine, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs index 549e549d38a..d9ca2922bde 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs @@ -30,9 +30,12 @@ pub mod currency { } pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; @@ -52,13 +55,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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 Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in BridgeHub, we map to 1/10 of that, or 1/100 CENT + // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Statemine, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index e424a7290ab..0c98fb66a50 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -46,10 +46,11 @@ use constants::currency::*; use frame_support::{ construct_runtime, dispatch::DispatchClass, + pallet_prelude::Weight, parameter_types, traits::{ConstU32, ConstU64, ConstU8, Everything}, weights::{ - ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + ConstantMultiplier, FeePolynomial, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, PalletId, @@ -129,13 +130,43 @@ pub type Executive = frame_executive::Executive< /// - 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 WeightToFeePolynomial for 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(); + + 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 Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1 MILLIUNIT: - // in our template, we map to 1/10 of that, or 1/10 MILLIUNIT let p = MILLIUNIT / 10; 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/10 MILLIUNIT. + let p = MILLIUNIT / 10; + let q = 10_000; + smallvec![WeightToFeeCoefficient { degree: 1, negative: false, diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs b/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs index cc41d5c6378..6e105698403 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs @@ -43,9 +43,12 @@ pub mod currency { /// Fee-related. pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; @@ -65,13 +68,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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: // in a parachain, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/contracts/contracts-rococo/src/constants.rs b/parachains/runtimes/contracts/contracts-rococo/src/constants.rs index 6dccf0089ca..40c72100d83 100644 --- a/parachains/runtimes/contracts/contracts-rococo/src/constants.rs +++ b/parachains/runtimes/contracts/contracts-rococo/src/constants.rs @@ -55,13 +55,45 @@ pub mod fee { /// - 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 WeightToFeePolynomial for 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(); + + 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: // in Statemine, we map to 1/10 of that, or 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, diff --git a/parachains/runtimes/testing/penpal/src/lib.rs b/parachains/runtimes/testing/penpal/src/lib.rs index d38d44be3a7..f6ff272807f 100644 --- a/parachains/runtimes/testing/penpal/src/lib.rs +++ b/parachains/runtimes/testing/penpal/src/lib.rs @@ -34,11 +34,12 @@ use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, dispatch::DispatchClass, + pallet_prelude::Weight, parameter_types, traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, ConstU8, Everything}, weights::{ - constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, + constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial, Weight, + WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, PalletId, }; @@ -149,13 +150,25 @@ pub type Executive = frame_executive::Executive< /// - 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 WeightToFeePolynomial for 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(); + + 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 Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1 MILLIUNIT: - // in our template, we map to 1/10 of that, or 1/10 MILLIUNIT let p = MILLIUNIT / 10; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); + smallvec![WeightToFeeCoefficient { degree: 1, negative: false, @@ -165,6 +178,23 @@ impl WeightToFeePolynomial for WeightToFee { } } +/// 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 = MILLIUNIT / 10; + let q = 10_000; + + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } +} /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats /// of data like extrinsics, allowing for them to continue syncing the network through upgrades From afedfa882ac4e435c79b29eac82b779ea1b979bd Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 16 Mar 2023 15:18:22 +0100 Subject: [PATCH 3/8] Fix doc comments Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- parachains/runtimes/assets/statemine/src/lib.rs | 4 ++-- parachains/runtimes/assets/statemint/src/lib.rs | 4 ++-- parachains/runtimes/assets/westmint/src/constants.rs | 4 ++-- .../runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs | 2 +- .../runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs | 4 ++-- .../runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index dddf3dae010..3f127c4c27c 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -1137,7 +1137,7 @@ mod tests { assert!(fit >= 1000, "{} should be at least 1000", fit); } - /// The fee for one transfer it at most 1 CENT. + /// The fee for one transfer is at most 1 CENT. #[test] fn sane_transfer_fee() { use pallet_balances::WeightInfo; @@ -1158,7 +1158,7 @@ mod tests { assert_eq!(fee, CENTS, "10kb maps to CENT"); } - /// Filling up a block by proof size is at most 30 times more expensive then ref time. + /// Filling up a block by proof size is at most 30 times more expensive than ref time. /// /// This is just a sanity check. #[test] diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 53eec2bacb7..3cf27fdf1a0 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -1089,7 +1089,7 @@ mod tests { assert!(fit >= 1000, "{} should be at least 1000", fit); } - /// The fee for one transfer it at most 1 CENT. + /// The fee for one transfer is at most 1 CENT. #[test] fn sane_transfer_fee() { use pallet_balances::WeightInfo; @@ -1110,7 +1110,7 @@ mod tests { assert_eq!(fee, CENTS, "10kb maps to CENT"); } - /// Filling up a block by proof size is at most 30 times more expensive then ref time. + /// Filling up a block by proof size is at most 30 times more expensive than ref time. /// /// This is just a sanity check. #[test] diff --git a/parachains/runtimes/assets/westmint/src/constants.rs b/parachains/runtimes/assets/westmint/src/constants.rs index 64bc38fc8ac..d6449d95dbc 100644 --- a/parachains/runtimes/assets/westmint/src/constants.rs +++ b/parachains/runtimes/assets/westmint/src/constants.rs @@ -74,8 +74,8 @@ pub mod fee { 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: - // in Statemine, we map to 1/10 of that, or 1/100 CENT + // in Westend, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Westmint, we map to 1/10 of that, or 1/100 CENT let p = super::currency::CENTS; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs index 8605afa3e8e..3ab18192108 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs @@ -71,7 +71,7 @@ pub mod fee { type Balance = Balance; fn polynomial() -> WeightToFeeCoefficients { // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in Statemine, we map to 1/10 of that, or 1/100 CENT + // in Bridge Hub, we map to 1/10 of that, or 1/100 CENT let p = super::currency::CENTS; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs index 4c426cb8b12..d3db1705eb4 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs @@ -67,8 +67,8 @@ pub mod fee { 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: - // in Statemine, we map to 1/10 of that, or 1/100 CENT + // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Bridge Hub, we map to 1/10 of that, or 1/100 CENT let p = super::currency::CENTS; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs index d9ca2922bde..708a9894bac 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs @@ -71,8 +71,8 @@ pub mod fee { 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: - // in Statemine, we map to 1/10 of that, or 1/100 CENT + // in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Bridge Hub, we map to 1/10 of that, or 1/100 CENT let p = super::currency::CENTS; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); From 3a0d5381e694acd2965fe6f96cfc218363f4e9d6 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 16 Mar 2023 15:19:11 +0100 Subject: [PATCH 4/8] Fix docs Signed-off-by: Oliver Tale-Yazdi --- parachains/runtimes/assets/statemint/src/constants.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/constants.rs b/parachains/runtimes/assets/statemint/src/constants.rs index af331652e2a..0426a976a55 100644 --- a/parachains/runtimes/assets/statemint/src/constants.rs +++ b/parachains/runtimes/assets/statemint/src/constants.rs @@ -72,8 +72,8 @@ pub mod fee { 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: - // in Statemine, we map to 1/10 of that, or 1/100 CENT + // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Statemint, we map to 1/10 of that, or 1/100 CENT let p = super::currency::CENTS; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); From 2c70c68d8138320c9b51f4d65a240721804160d2 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 16 Mar 2023 15:49:20 +0100 Subject: [PATCH 5/8] Update lock file Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 9ce52f3fe3f..ef3f081943e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12429,6 +12429,7 @@ dependencies = [ "sp-std", "sp-transaction-pool", "sp-version", + "sp-weights", "substrate-wasm-builder", "xcm", "xcm-builder", @@ -12495,6 +12496,7 @@ dependencies = [ "sp-std", "sp-transaction-pool", "sp-version", + "sp-weights", "substrate-wasm-builder", "xcm", "xcm-builder", From 7550fdbf30b9ea3b2be4c7d3e618ff68f188c38b Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 16 Mar 2023 17:13:26 +0100 Subject: [PATCH 6/8] Fix imports Signed-off-by: Oliver Tale-Yazdi --- .../bridge-hubs/bridge-hub-polkadot/src/constants.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs index d3db1705eb4..8aafe22e4f5 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs @@ -32,9 +32,12 @@ pub mod currency { /// Fee-related. pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; From b6ca4b5454d935b4b677365fa1ef10a5279b1aef Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 17 Mar 2023 16:22:08 +0100 Subject: [PATCH 7/8] Docs Signed-off-by: Oliver Tale-Yazdi --- parachains/runtimes/assets/statemine/src/constants.rs | 1 + parachains/runtimes/assets/statemint/src/constants.rs | 1 + parachains/runtimes/assets/westmint/src/constants.rs | 1 + .../runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs | 1 + .../runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs | 1 + .../runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs | 1 + parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 1 + .../runtimes/collectives/collectives-polkadot/src/constants.rs | 1 + parachains/runtimes/contracts/contracts-rococo/src/constants.rs | 1 + parachains/runtimes/testing/penpal/src/lib.rs | 1 + 10 files changed, 10 insertions(+) diff --git a/parachains/runtimes/assets/statemine/src/constants.rs b/parachains/runtimes/assets/statemine/src/constants.rs index e53da737d02..95e8c166a96 100644 --- a/parachains/runtimes/assets/statemine/src/constants.rs +++ b/parachains/runtimes/assets/statemine/src/constants.rs @@ -62,6 +62,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/assets/statemint/src/constants.rs b/parachains/runtimes/assets/statemint/src/constants.rs index 0426a976a55..35e7f03695b 100644 --- a/parachains/runtimes/assets/statemint/src/constants.rs +++ b/parachains/runtimes/assets/statemint/src/constants.rs @@ -63,6 +63,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/assets/westmint/src/constants.rs b/parachains/runtimes/assets/westmint/src/constants.rs index d6449d95dbc..11e6d1bf35b 100644 --- a/parachains/runtimes/assets/westmint/src/constants.rs +++ b/parachains/runtimes/assets/westmint/src/constants.rs @@ -65,6 +65,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs index 3ab18192108..257d0da755b 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/constants.rs @@ -61,6 +61,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs index 8aafe22e4f5..388d23e6441 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/constants.rs @@ -61,6 +61,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs index 708a9894bac..86cf8d6f7d3 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs @@ -62,6 +62,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 028aa986110..640b1eb6c00 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -137,6 +137,7 @@ impl frame_support::weights::WeightToFee for WeightToFee { 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())) } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs b/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs index 6e105698403..e9709519827 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs @@ -75,6 +75,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/contracts/contracts-rococo/src/constants.rs b/parachains/runtimes/contracts/contracts-rococo/src/constants.rs index 40c72100d83..cec36633b33 100644 --- a/parachains/runtimes/contracts/contracts-rococo/src/constants.rs +++ b/parachains/runtimes/contracts/contracts-rococo/src/constants.rs @@ -62,6 +62,7 @@ pub mod fee { 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())) } } diff --git a/parachains/runtimes/testing/penpal/src/lib.rs b/parachains/runtimes/testing/penpal/src/lib.rs index ab4e0f4ccee..42610bbfcec 100644 --- a/parachains/runtimes/testing/penpal/src/lib.rs +++ b/parachains/runtimes/testing/penpal/src/lib.rs @@ -157,6 +157,7 @@ impl frame_support::weights::WeightToFee for WeightToFee { 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())) } } From cbac74217a7f90348a21f17336c92eef9467783f Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 17 Mar 2023 16:42:55 +0100 Subject: [PATCH 8/8] Fix imports Signed-off-by: Oliver Tale-Yazdi --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- .../runtimes/contracts/contracts-rococo/src/constants.rs | 9 ++++++--- parachains/runtimes/testing/penpal/src/lib.rs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 640b1eb6c00..6957edc8998 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -50,7 +50,7 @@ use frame_support::{ parameter_types, traits::{ConstU32, ConstU64, ConstU8, Everything}, weights::{ - ConstantMultiplier, FeePolynomial, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + ConstantMultiplier, FeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, PalletId, diff --git a/parachains/runtimes/contracts/contracts-rococo/src/constants.rs b/parachains/runtimes/contracts/contracts-rococo/src/constants.rs index cec36633b33..4598ddaa264 100644 --- a/parachains/runtimes/contracts/contracts-rococo/src/constants.rs +++ b/parachains/runtimes/contracts/contracts-rococo/src/constants.rs @@ -33,9 +33,12 @@ pub mod currency { /// Fee-related. pub mod fee { - use frame_support::weights::{ - constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + use frame_support::{ + pallet_prelude::Weight, + weights::{ + constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; diff --git a/parachains/runtimes/testing/penpal/src/lib.rs b/parachains/runtimes/testing/penpal/src/lib.rs index 42610bbfcec..b3cf2e5a654 100644 --- a/parachains/runtimes/testing/penpal/src/lib.rs +++ b/parachains/runtimes/testing/penpal/src/lib.rs @@ -38,7 +38,7 @@ use frame_support::{ parameter_types, traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, ConstU8, Everything}, weights::{ - constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial, Weight, + constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, PalletId,