mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Parachains should charge for proof size weight (#2326)
* Generalize trait requirement Use the trait directly instead of something that will have a blanket implementation for it. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Charge for proof size weight Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix doc comments Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Fix docs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update lock file Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix imports Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Docs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix imports Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
38944d85c4
commit
c52062b869
@@ -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,
|
||||
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
||||
},
|
||||
PalletId,
|
||||
};
|
||||
@@ -149,13 +150,26 @@ 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<Balance> = RefTimeToFee::polynomial().into();
|
||||
let proof_poly: FeePolynomial<Balance> = 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<Self::Balance> {
|
||||
// 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 +179,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<Self::Balance> {
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user