@@ -40,7 +40,7 @@ use frame_support::{
40
40
traits:: Get ,
41
41
weights:: {
42
42
Weight , DispatchInfo , PostDispatchInfo , GetDispatchInfo , Pays , WeightToFeePolynomial ,
43
- WeightToFeeCoefficient ,
43
+ WeightToFeeCoefficient , DispatchClass ,
44
44
} ,
45
45
dispatch:: DispatchResult ,
46
46
} ;
@@ -158,14 +158,14 @@ impl<T, S, V, M> Convert<Multiplier, Multiplier> for TargetedFeeAdjustment<T, S,
158
158
let min_multiplier = M :: get ( ) ;
159
159
let previous = previous. max ( min_multiplier) ;
160
160
161
+ let weights = T :: BlockWeights :: get ( ) ;
161
162
// the computed ratio is only among the normal class.
162
- let normal_max_weight =
163
- <T as frame_system:: Config >:: AvailableBlockRatio :: get ( ) *
164
- <T as frame_system:: Config >:: MaximumBlockWeight :: get ( ) ;
165
- let normal_block_weight =
166
- <frame_system:: Module < T > >:: block_weight ( )
167
- . get ( frame_support:: weights:: DispatchClass :: Normal )
168
- . min ( normal_max_weight) ;
163
+ let normal_max_weight = weights. get ( DispatchClass :: Normal ) . max_total
164
+ . unwrap_or_else ( || weights. max_block ) ;
165
+ let current_block_weight = <frame_system:: Module < T > >:: block_weight ( ) ;
166
+ let normal_block_weight = * current_block_weight
167
+ . get ( DispatchClass :: Normal )
168
+ . min ( & normal_max_weight) ;
169
169
170
170
let s = S :: get ( ) ;
171
171
let v = V :: get ( ) ;
@@ -257,13 +257,13 @@ decl_module! {
257
257
258
258
fn integrity_test( ) {
259
259
// given weight == u64, we build multipliers from `diff` of two weight values, which can
260
- // at most be MaximumBlockWeight . Make sure that this can fit in a multiplier without
260
+ // at most be maximum block weight . Make sure that this can fit in a multiplier without
261
261
// loss.
262
262
use sp_std:: convert:: TryInto ;
263
263
assert!(
264
264
<Multiplier as sp_runtime:: traits:: Bounded >:: max_value( ) >=
265
265
Multiplier :: checked_from_integer(
266
- < T as frame_system :: Config > :: MaximumBlockWeight :: get( ) . try_into( ) . unwrap( )
266
+ T :: BlockWeights :: get( ) . max_block . try_into( ) . unwrap( )
267
267
) . unwrap( ) ,
268
268
) ;
269
269
@@ -272,9 +272,11 @@ decl_module! {
272
272
// that if we collapse to minimum, the trend will be positive with a weight value
273
273
// which is 1% more than the target.
274
274
let min_value = T :: FeeMultiplierUpdate :: min( ) ;
275
- let mut target =
276
- T :: FeeMultiplierUpdate :: target( ) *
277
- ( T :: AvailableBlockRatio :: get( ) * T :: MaximumBlockWeight :: get( ) ) ;
275
+ let mut target = T :: FeeMultiplierUpdate :: target( ) *
276
+ T :: BlockWeights :: get( ) . get( DispatchClass :: Normal ) . max_total. expect(
277
+ "Setting `max_total` for `Normal` dispatch class is not compatible with \
278
+ `transaction-payment` pallet."
279
+ ) ;
278
280
279
281
// add 1 percent;
280
282
let addition = target / 100 ;
@@ -285,7 +287,7 @@ decl_module! {
285
287
target += addition;
286
288
287
289
sp_io:: TestExternalities :: new_empty( ) . execute_with( || {
288
- <frame_system:: Module <T >>:: set_block_limits ( target, 0 ) ;
290
+ <frame_system:: Module <T >>:: set_block_consumed_resources ( target, 0 ) ;
289
291
let next = T :: FeeMultiplierUpdate :: convert( min_value) ;
290
292
assert!( next > min_value, "The minimum bound of the multiplier is too low. When \
291
293
block saturation is more than target by 1% and multiplier is minimal then \
@@ -357,7 +359,13 @@ impl<T: Config> Module<T> where
357
359
) -> BalanceOf < T > where
358
360
T :: Call : Dispatchable < Info =DispatchInfo > ,
359
361
{
360
- Self :: compute_fee_raw ( len, info. weight , tip, info. pays_fee )
362
+ Self :: compute_fee_raw (
363
+ len,
364
+ info. weight ,
365
+ tip,
366
+ info. pays_fee ,
367
+ info. class ,
368
+ )
361
369
}
362
370
363
371
/// Compute the actual post dispatch fee for a particular transaction.
@@ -372,14 +380,21 @@ impl<T: Config> Module<T> where
372
380
) -> BalanceOf < T > where
373
381
T :: Call : Dispatchable < Info =DispatchInfo , PostInfo =PostDispatchInfo > ,
374
382
{
375
- Self :: compute_fee_raw ( len, post_info. calc_actual_weight ( info) , tip, post_info. pays_fee ( info) )
383
+ Self :: compute_fee_raw (
384
+ len,
385
+ post_info. calc_actual_weight ( info) ,
386
+ tip,
387
+ post_info. pays_fee ( info) ,
388
+ info. class ,
389
+ )
376
390
}
377
391
378
392
fn compute_fee_raw (
379
393
len : u32 ,
380
394
weight : Weight ,
381
395
tip : BalanceOf < T > ,
382
396
pays_fee : Pays ,
397
+ class : DispatchClass ,
383
398
) -> BalanceOf < T > {
384
399
if pays_fee == Pays :: Yes {
385
400
let len = <BalanceOf < T > >:: from ( len) ;
@@ -394,7 +409,7 @@ impl<T: Config> Module<T> where
394
409
// final adjusted weight fee.
395
410
let adjusted_weight_fee = multiplier. saturating_mul_int ( unadjusted_weight_fee) ;
396
411
397
- let base_fee = Self :: weight_to_fee ( T :: ExtrinsicBaseWeight :: get ( ) ) ;
412
+ let base_fee = Self :: weight_to_fee ( T :: BlockWeights :: get ( ) . get ( class ) . base_extrinsic ) ;
398
413
base_fee
399
414
. saturating_add ( fixed_len_fee)
400
415
. saturating_add ( adjusted_weight_fee)
@@ -407,7 +422,7 @@ impl<T: Config> Module<T> where
407
422
fn weight_to_fee ( weight : Weight ) -> BalanceOf < T > {
408
423
// cap the weight to the maximum defined in runtime, otherwise it will be the
409
424
// `Bounded` maximum of its data type, which is not desired.
410
- let capped_weight = weight. min ( < T as frame_system :: Config > :: MaximumBlockWeight :: get ( ) ) ;
425
+ let capped_weight = weight. min ( T :: BlockWeights :: get ( ) . max_block ) ;
411
426
T :: WeightToFee :: calc ( & capped_weight)
412
427
}
413
428
}
@@ -471,8 +486,9 @@ impl<T: Config + Send + Sync> ChargeTransactionPayment<T> where
471
486
/// that the transaction which consumes more resources (either length or weight) with the same
472
487
/// `fee` ends up having lower priority.
473
488
fn get_priority ( len : usize , info : & DispatchInfoOf < T :: Call > , final_fee : BalanceOf < T > ) -> TransactionPriority {
474
- let weight_saturation = T :: MaximumBlockWeight :: get ( ) / info. weight . max ( 1 ) ;
475
- let len_saturation = T :: MaximumBlockLength :: get ( ) as u64 / ( len as u64 ) . max ( 1 ) ;
489
+ let weight_saturation = T :: BlockWeights :: get ( ) . max_block / info. weight . max ( 1 ) ;
490
+ let max_block_length = * T :: BlockLength :: get ( ) . max . get ( DispatchClass :: Normal ) ;
491
+ let len_saturation = max_block_length as u64 / ( len as u64 ) . max ( 1 ) ;
476
492
let coefficient: BalanceOf < T > = weight_saturation. min ( len_saturation) . saturated_into :: < BalanceOf < T > > ( ) ;
477
493
final_fee. saturating_mul ( coefficient) . saturated_into :: < TransactionPriority > ( )
478
494
}
@@ -571,6 +587,7 @@ mod tests {
571
587
traits:: { BlakeTwo256 , IdentityLookup } ,
572
588
Perbill ,
573
589
} ;
590
+ use std:: cell:: RefCell ;
574
591
use smallvec:: smallvec;
575
592
576
593
const CALL : & <Runtime as frame_system:: Config >:: Call =
@@ -598,18 +615,36 @@ mod tests {
598
615
pub enum Origin for Runtime { }
599
616
}
600
617
618
+ thread_local ! {
619
+ static EXTRINSIC_BASE_WEIGHT : RefCell <u64 > = RefCell :: new( 0 ) ;
620
+ }
621
+
622
+ pub struct BlockWeights ;
623
+ impl Get < frame_system:: limits:: BlockWeights > for BlockWeights {
624
+ fn get ( ) -> frame_system:: limits:: BlockWeights {
625
+ frame_system:: limits:: BlockWeights :: builder ( )
626
+ . base_block ( 0 )
627
+ . for_class ( DispatchClass :: all ( ) , |weights| {
628
+ weights. base_extrinsic = EXTRINSIC_BASE_WEIGHT . with ( |v| * v. borrow ( ) ) . into ( ) ;
629
+ } )
630
+ . for_class ( DispatchClass :: non_mandatory ( ) , |weights| {
631
+ weights. max_total = 1024 . into ( ) ;
632
+ } )
633
+ . build_or_panic ( )
634
+ }
635
+ }
636
+
601
637
parameter_types ! {
602
638
pub const BlockHashCount : u64 = 250 ;
603
- pub const MaximumBlockWeight : Weight = 1024 ;
604
- pub const MaximumBlockLength : u32 = 2 * 1024 ;
605
- pub const AvailableBlockRatio : Perbill = Perbill :: one( ) ;
606
- pub static ExtrinsicBaseWeight : u64 = 0 ;
607
639
pub static TransactionByteFee : u64 = 1 ;
608
640
pub static WeightToFee : u64 = 1 ;
609
641
}
610
642
611
643
impl frame_system:: Config for Runtime {
612
644
type BaseCallFilter = ( ) ;
645
+ type BlockWeights = BlockWeights ;
646
+ type BlockLength = ( ) ;
647
+ type DbWeight = ( ) ;
613
648
type Origin = Origin ;
614
649
type Index = u64 ;
615
650
type BlockNumber = u64 ;
@@ -621,13 +656,6 @@ mod tests {
621
656
type Header = Header ;
622
657
type Event = Event ;
623
658
type BlockHashCount = BlockHashCount ;
624
- type MaximumBlockWeight = MaximumBlockWeight ;
625
- type DbWeight = ( ) ;
626
- type BlockExecutionWeight = ( ) ;
627
- type ExtrinsicBaseWeight = ExtrinsicBaseWeight ;
628
- type MaximumExtrinsicWeight = MaximumBlockWeight ;
629
- type MaximumBlockLength = MaximumBlockLength ;
630
- type AvailableBlockRatio = AvailableBlockRatio ;
631
659
type Version = ( ) ;
632
660
type PalletInfo = ( ) ;
633
661
type AccountData = pallet_balances:: AccountData < u64 > ;
@@ -841,7 +869,7 @@ mod tests {
841
869
// fee will be proportional to what is the actual maximum weight in the runtime.
842
870
assert_eq ! (
843
871
Balances :: free_balance( & 1 ) ,
844
- ( 10000 - <Runtime as frame_system:: Config >:: MaximumBlockWeight :: get( ) ) as u64
872
+ ( 10000 - <Runtime as frame_system:: Config >:: BlockWeights :: get( ) . max_block ) as u64
845
873
) ;
846
874
} ) ;
847
875
}
@@ -939,7 +967,7 @@ mod tests {
939
967
partial_fee:
940
968
5 * 2 /* base * weight_fee */
941
969
+ len as u64 /* len * 1 */
942
- + info. weight. min( MaximumBlockWeight :: get( ) ) as u64 * 2 * 3 / 2 /* weight */
970
+ + info. weight. min( BlockWeights :: get( ) . max_block ) as u64 * 2 * 3 / 2 /* weight */
943
971
} ,
944
972
) ;
945
973
0 commit comments