-
Notifications
You must be signed in to change notification settings - Fork 372
Parachains should charge for proof size weight #2326
Changes from 6 commits
c5ae80d
7855684
afedfa8
3a0d538
2c70c68
7550fdb
dbdf7e4
b6ca4b5
cbac742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<Balance> = RefTimeToFee::polynomial().into(); | ||
| let proof_poly: FeePolynomial<Balance> = 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<Self::Balance> { | ||
| // 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<Self::Balance> { | ||
| // Map 10kb proof to 1 CENT. | ||
| let p = super::currency::CENTS; | ||
| let q = 10_000; | ||
|
Comment on lines
+94
to
+96
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose we don't have a reference on the Relay Chain.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, since the relay chain has There are going to be changes in Substrate soon that increase the proof size of everything (until we have https://github.com/paritytech/substrate/issues/13501), so to prevent accidental fuckups i added the tests that 1K transfers fit in a block. |
||
|
|
||
| smallvec![WeightToFeeCoefficient { | ||
| degree: 1, | ||
| negative: false, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be simplified by implementing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we could do a simple maximum norm. In the long run i would rather make the traits 2D weight compatible in Substrate, so we wont need it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now it is fine or? Since this targets 0.9.38.1
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah nah, you would be confused if it is addition, or max or what. I suppose we can provide some nice helpers at he substrate layer though: Or even a more generic: I think you can see where I am going with this. Just an idea
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah fine for now. Perhaps a follow-up issue that you can mentor? |
||
| 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(); | ||
|
|
||
| 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 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()); | ||
|
|
||
| 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, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.