@@ -251,8 +251,12 @@ where
251
251
weight = weight. saturating_add (
252
252
<frame_system:: Module < System > as OnInitialize < System :: BlockNumber > >:: on_initialize ( * block_number)
253
253
) ;
254
- weight = weight. saturating_add ( <AllModules as OnInitialize < System :: BlockNumber > >:: on_initialize ( * block_number) )
255
- . saturating_add ( <System :: BlockExecutionWeight as frame_support:: traits:: Get < _ > >:: get ( ) ) ;
254
+ weight = weight. saturating_add (
255
+ <AllModules as OnInitialize < System :: BlockNumber > >:: on_initialize ( * block_number)
256
+ ) ;
257
+ weight = weight. saturating_add (
258
+ <System :: BlockWeights as frame_support:: traits:: Get < _ > >:: get ( ) . base_block
259
+ ) ;
256
260
<frame_system:: Module :: < System > >:: register_extra_weight_unchecked ( weight , DispatchClass :: Mandatory ) ;
257
261
258
262
frame_system:: Module :: < System > :: note_finished_initialize ( ) ;
@@ -482,7 +486,7 @@ mod tests {
482
486
use super :: * ;
483
487
use sp_core:: H256 ;
484
488
use sp_runtime:: {
485
- generic:: { Era , DigestItem } , Perbill , DispatchError , testing:: { Digest , Header , Block } ,
489
+ generic:: { Era , DigestItem } , DispatchError , testing:: { Digest , Header , Block } ,
486
490
traits:: { Header as HeaderT , BlakeTwo256 , IdentityLookup } ,
487
491
transaction_validity:: {
488
492
InvalidTransaction , ValidTransaction , TransactionValidityError , UnknownTransaction
@@ -493,7 +497,9 @@ mod tests {
493
497
weights:: { Weight , RuntimeDbWeight , IdentityFee , WeightToFeePolynomial } ,
494
498
traits:: { Currency , LockIdentifier , LockableCurrency , WithdrawReasons } ,
495
499
} ;
496
- use frame_system:: { Call as SystemCall , ChainContext , LastRuntimeUpgradeInfo } ;
500
+ use frame_system:: {
501
+ Call as SystemCall , ChainContext , LastRuntimeUpgradeInfo ,
502
+ } ;
497
503
use pallet_transaction_payment:: CurrencyAdapter ;
498
504
use pallet_balances:: Call as BalancesCall ;
499
505
use hex_literal:: hex;
@@ -584,18 +590,22 @@ mod tests {
584
590
585
591
parameter_types ! {
586
592
pub const BlockHashCount : u64 = 250 ;
587
- pub const MaximumBlockWeight : Weight = 1024 ;
588
- pub const MaximumBlockLength : u32 = 2 * 1024 ;
589
- pub const AvailableBlockRatio : Perbill = Perbill :: one( ) ;
590
- pub const BlockExecutionWeight : Weight = 10 ;
591
- pub const ExtrinsicBaseWeight : Weight = 5 ;
593
+ pub BlockWeights : frame_system:: limits:: BlockWeights =
594
+ frame_system:: limits:: BlockWeights :: builder( )
595
+ . base_block( 10 )
596
+ . for_class( DispatchClass :: all( ) , |weights| weights. base_extrinsic = 5 )
597
+ . for_class( DispatchClass :: non_mandatory( ) , |weights| weights. max_total = 1024 . into( ) )
598
+ . build_or_panic( ) ;
592
599
pub const DbWeight : RuntimeDbWeight = RuntimeDbWeight {
593
600
read: 10 ,
594
601
write: 100 ,
595
602
} ;
596
603
}
597
604
impl frame_system:: Config for Runtime {
598
605
type BaseCallFilter = ( ) ;
606
+ type BlockWeights = BlockWeights ;
607
+ type BlockLength = ( ) ;
608
+ type DbWeight = ( ) ;
599
609
type Origin = Origin ;
600
610
type Index = u64 ;
601
611
type Call = Call ;
@@ -607,13 +617,6 @@ mod tests {
607
617
type Header = Header ;
608
618
type Event = Event ;
609
619
type BlockHashCount = BlockHashCount ;
610
- type MaximumBlockWeight = MaximumBlockWeight ;
611
- type DbWeight = DbWeight ;
612
- type BlockExecutionWeight = BlockExecutionWeight ;
613
- type ExtrinsicBaseWeight = ExtrinsicBaseWeight ;
614
- type MaximumExtrinsicWeight = MaximumBlockWeight ;
615
- type AvailableBlockRatio = AvailableBlockRatio ;
616
- type MaximumBlockLength = MaximumBlockLength ;
617
620
type Version = RuntimeVersion ;
618
621
type PalletInfo = PalletInfo ;
619
622
type AccountData = pallet_balances:: AccountData < Balance > ;
@@ -715,7 +718,8 @@ mod tests {
715
718
balances : vec ! [ ( 1 , 211 ) ] ,
716
719
} . assimilate_storage ( & mut t) . unwrap ( ) ;
717
720
let xt = TestXt :: new ( Call :: Balances ( BalancesCall :: transfer ( 2 , 69 ) ) , sign_extra ( 1 , 0 , 0 ) ) ;
718
- let weight = xt. get_dispatch_info ( ) . weight + <Runtime as frame_system:: Config >:: ExtrinsicBaseWeight :: get ( ) ;
721
+ let weight = xt. get_dispatch_info ( ) . weight +
722
+ <Runtime as frame_system:: Config >:: BlockWeights :: get ( ) . get ( DispatchClass :: Normal ) . base_extrinsic ;
719
723
let fee: Balance
720
724
= <Runtime as pallet_transaction_payment:: Config >:: WeightToFee :: calc ( & weight) ;
721
725
let mut t = sp_io:: TestExternalities :: new ( t) ;
@@ -749,7 +753,7 @@ mod tests {
749
753
header : Header {
750
754
parent_hash : [ 69u8 ; 32 ] . into ( ) ,
751
755
number : 1 ,
752
- state_root : hex ! ( "465a1569d309039bdf84b0479d28064ea29e6584584dc7d788904bb14489c6f6 " ) . into ( ) ,
756
+ state_root : hex ! ( "6a3ad91caba5b8ac15c325a36d7568adf6a7e49321865de7527b851d870343d4 " ) . into ( ) ,
753
757
extrinsics_root : hex ! ( "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314" ) . into ( ) ,
754
758
digest : Digest { logs : vec ! [ ] , } ,
755
759
} ,
@@ -817,9 +821,11 @@ mod tests {
817
821
let xt = TestXt :: new ( Call :: Balances ( BalancesCall :: transfer ( 33 , 0 ) ) , sign_extra ( 1 , 0 , 0 ) ) ;
818
822
let encoded = xt. encode ( ) ;
819
823
let encoded_len = encoded. len ( ) as Weight ;
820
- // on_initialize weight + block execution weight
821
- let base_block_weight = 175 + <Runtime as frame_system:: Config >:: BlockExecutionWeight :: get ( ) ;
822
- let limit = AvailableBlockRatio :: get ( ) * MaximumBlockWeight :: get ( ) - base_block_weight;
824
+ // on_initialize weight + base block execution weight
825
+ let block_weights = <Runtime as frame_system:: Config >:: BlockWeights :: get ( ) ;
826
+ let base_block_weight = 175 + block_weights. base_block ;
827
+ let limit = block_weights. get ( DispatchClass :: Normal ) . max_total . unwrap ( )
828
+ - base_block_weight;
823
829
let num_to_exhaust_block = limit / ( encoded_len + 5 ) ;
824
830
t. execute_with ( || {
825
831
Executive :: initialize_block ( & Header :: new (
@@ -861,7 +867,7 @@ mod tests {
861
867
let mut t = new_test_ext ( 1 ) ;
862
868
t. execute_with ( || {
863
869
// Block execution weight + on_initialize weight from custom module
864
- let base_block_weight = 175 + <Runtime as frame_system:: Config >:: BlockExecutionWeight :: get ( ) ;
870
+ let base_block_weight = 175 + <Runtime as frame_system:: Config >:: BlockWeights :: get ( ) . base_block ;
865
871
866
872
Executive :: initialize_block ( & Header :: new (
867
873
1 ,
@@ -879,7 +885,8 @@ mod tests {
879
885
assert ! ( Executive :: apply_extrinsic( x2. clone( ) ) . unwrap( ) . is_ok( ) ) ;
880
886
881
887
// default weight for `TestXt` == encoded length.
882
- let extrinsic_weight = len as Weight + <Runtime as frame_system:: Config >:: ExtrinsicBaseWeight :: get ( ) ;
888
+ let extrinsic_weight = len as Weight + <Runtime as frame_system:: Config >:: BlockWeights
889
+ :: get ( ) . get ( DispatchClass :: Normal ) . base_extrinsic ;
883
890
assert_eq ! (
884
891
<frame_system:: Module <Runtime >>:: block_weight( ) . total( ) ,
885
892
base_block_weight + 3 * extrinsic_weight,
@@ -945,8 +952,11 @@ mod tests {
945
952
Call :: System ( SystemCall :: remark ( vec ! [ 1u8 ] ) ) ,
946
953
sign_extra ( 1 , 0 , 0 ) ,
947
954
) ;
948
- let weight = xt. get_dispatch_info ( ) . weight
949
- + <Runtime as frame_system:: Config >:: ExtrinsicBaseWeight :: get ( ) ;
955
+ let weight = xt. get_dispatch_info ( ) . weight + <Runtime as frame_system:: Config >
956
+ :: BlockWeights
957
+ :: get ( )
958
+ . get ( DispatchClass :: Normal )
959
+ . base_extrinsic ;
950
960
let fee: Balance =
951
961
<Runtime as pallet_transaction_payment:: Config >:: WeightToFee :: calc ( & weight) ;
952
962
Executive :: initialize_block ( & Header :: new (
@@ -1106,7 +1116,7 @@ mod tests {
1106
1116
let runtime_upgrade_weight = <AllModules as OnRuntimeUpgrade >:: on_runtime_upgrade ( ) ;
1107
1117
let frame_system_on_initialize_weight = frame_system:: Module :: < Runtime > :: on_initialize ( block_number) ;
1108
1118
let on_initialize_weight = <AllModules as OnInitialize < u64 > >:: on_initialize ( block_number) ;
1109
- let base_block_weight = <Runtime as frame_system:: Config >:: BlockExecutionWeight :: get ( ) ;
1119
+ let base_block_weight = <Runtime as frame_system:: Config >:: BlockWeights :: get ( ) . base_block ;
1110
1120
1111
1121
// Weights are recorded correctly
1112
1122
assert_eq ! (
0 commit comments