@@ -38,8 +38,8 @@ use dc_primitives::*;
3838use frame_support:: {
3939 sp_runtime:: Perbill ,
4040 weights:: {
41- constants:: ExtrinsicBaseWeight , WeightToFeeCoefficient , WeightToFeeCoefficients ,
42- WeightToFeePolynomial ,
41+ constants:: ExtrinsicBaseWeight , Weight , WeightToFee as WeightToFeeT ,
42+ WeightToFeeCoefficient , WeightToFeeCoefficients , WeightToFeePolynomial ,
4343 } ,
4444} ;
4545
@@ -64,7 +64,21 @@ macro_rules! fast_runtime_or_not {
6464/// - Setting it to `0` will essentially disable the weight fee.
6565/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
6666pub struct WeightToFee ;
67- impl WeightToFeePolynomial for WeightToFee {
67+ impl WeightToFeeT for WeightToFee {
68+ type Balance = Balance ;
69+
70+ fn weight_to_fee ( weight : & Weight ) -> Self :: Balance {
71+ let time_poly: FeePolynomial < Balance > = RefTimeToFee :: polynomial ( ) . into ( ) ;
72+ let proof_poly: FeePolynomial < Balance > = ProofSizeToFee :: polynomial ( ) . into ( ) ;
73+
74+ // Take the maximum instead of the sum to charge by the more scarce resource.
75+ time_poly. eval ( weight. ref_time ( ) ) . max ( proof_poly. eval ( weight. proof_size ( ) ) )
76+ }
77+ }
78+
79+ /// Maps the reference time component of `Weight` to a fee.
80+ pub struct RefTimeToFee ;
81+ impl WeightToFeePolynomial for RefTimeToFee {
6882 type Balance = Balance ;
6983
7084 fn polynomial ( ) -> WeightToFeeCoefficients < Self :: Balance > {
@@ -80,6 +94,25 @@ impl WeightToFeePolynomial for WeightToFee {
8094 }
8195}
8296
97+ /// Maps the proof size component of `Weight` to a fee.
98+ pub struct ProofSizeToFee ;
99+ impl WeightToFeePolynomial for ProofSizeToFee {
100+ type Balance = Balance ;
101+
102+ fn polynomial ( ) -> WeightToFeeCoefficients < Self :: Balance > {
103+ // Map 1MB proof to 1 UNIT.
104+ let p = UNIT ;
105+ let q = 10_000_000 ;
106+
107+ smallvec ! [ WeightToFeeCoefficient {
108+ degree: 1 ,
109+ negative: false ,
110+ coeff_frac: Perbill :: from_rational( p % q, q) ,
111+ coeff_integer: p / q,
112+ } ]
113+ }
114+ }
115+
83116pub struct DealWithFees < R > ( sp_std:: marker:: PhantomData < R > ) ;
84117impl < R > frame_support:: traits:: OnUnbalanced < pallet_balances:: NegativeImbalance < R > >
85118 for DealWithFees < R >
0 commit comments