mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23: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
1782170e08
commit
91b3512427
@@ -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,46 @@ 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<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 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 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());
|
||||
|
||||
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<Self::Balance> {
|
||||
// Map 10kb proof to 1 CENT.
|
||||
let p = super::currency::CENTS;
|
||||
let q = 10_000;
|
||||
|
||||
smallvec![WeightToFeeCoefficient {
|
||||
degree: 1,
|
||||
negative: false,
|
||||
|
||||
Reference in New Issue
Block a user