Skip to content

Commit beae7ba

Browse files
tomusdrwkianenigmashawntabrizignunicorngui1117
authored
Streamline frame_system weight parametrization (#6629)
* Basic weights builder. * Fixing WiP * Make the tests work. * Fix weights in node/runtime. * WiP. * Update pallets with new weights parameters. * Validate returns a Result now. * Count mandatory weight separately. * DRY * BREAKING: Updating state root, because of the left-over weight-tracking stuff * Update tests affected by Mandatory tracking. * Fixing tests. * Fix defaults for simple_max * Update frame/system/src/weights.rs Co-authored-by: Kian Paimani <[email protected]> * Rework the API a bit. * Fix compilation & tests. * Apply suggestions from code review Co-authored-by: Kian Paimani <[email protected]> * Add extra docs & rename few things. * Fix whitespace in ASCII art. * Update frame/system/src/limits.rs Co-authored-by: Kian Paimani <[email protected]> * Fix max_extrinsic calculations. * Fix conflicts. * Fix compilation. * Fix new code. * re-remove generic asset * Fix usage. * Update state root. * Update proxy. * Fix tests. * Move weights validity to integrity_test * Remove redundant BlockWeights. * Add all/non_mandatory comment * Add test. * Remove fn block_weights * Make the macro prettier. * Fix some docs. * Make max_total behave more predictabily. * Add BlockWeights to metadata. * fix balances test * Fix utility test. Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Benjamin Kampmann <[email protected]> Co-authored-by: thiolliere <[email protected]>
1 parent 709b1d2 commit beae7ba

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

benchmarking/src/mock.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ type BlockNumber = u64;
3737
type Balance = u64;
3838

3939
parameter_types! {
40-
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
40+
pub BlockWeights: frame_system::limits::BlockWeights =
41+
frame_system::limits::BlockWeights::simple_max(2 * WEIGHT_PER_SECOND);
4142
}
4243

4344
impl frame_system::Config for Test {
4445
type BaseCallFilter = ();
46+
type BlockWeights = ();
47+
type BlockLength = ();
48+
type DbWeight = ();
4549
type Origin = Origin;
4650
type Index = AccountIndex;
4751
type BlockNumber = BlockNumber;
@@ -53,18 +57,11 @@ impl frame_system::Config for Test {
5357
type Header = sp_runtime::testing::Header;
5458
type Event = Event;
5559
type BlockHashCount = ();
56-
type MaximumBlockWeight = MaximumBlockWeight;
57-
type DbWeight = ();
58-
type AvailableBlockRatio = ();
59-
type MaximumBlockLength = ();
6060
type Version = ();
6161
type PalletInfo = ();
6262
type AccountData = pallet_balances::AccountData<u64>;
6363
type OnNewAccount = ();
6464
type OnKilledAccount = (Balances,);
65-
type BlockExecutionWeight = ();
66-
type ExtrinsicBaseWeight = ();
67-
type MaximumExtrinsicWeight = ();
6865
type SystemWeightInfo = ();
6966
}
7067
parameter_types! {
@@ -184,7 +181,7 @@ impl pallet_im_online::Config for Test {
184181
}
185182

186183
parameter_types! {
187-
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
184+
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * BlockWeights::get().max_block;
188185
}
189186

190187
impl pallet_offences::Config for Test {

src/mock.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ pub fn set_offence_weight(new: Weight) {
9191
pub struct Runtime;
9292
parameter_types! {
9393
pub const BlockHashCount: u64 = 250;
94-
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
95-
pub const MaximumBlockLength: u32 = 2 * 1024;
96-
pub const AvailableBlockRatio: Perbill = Perbill::one();
94+
pub BlockWeights: frame_system::limits::BlockWeights =
95+
frame_system::limits::BlockWeights::simple_max(2 * WEIGHT_PER_SECOND);
9796
}
9897
impl frame_system::Config for Runtime {
9998
type BaseCallFilter = ();
99+
type BlockWeights = ();
100+
type BlockLength = ();
101+
type DbWeight = RocksDbWeight;
100102
type Origin = Origin;
101103
type Index = u64;
102104
type BlockNumber = u64;
@@ -108,13 +110,6 @@ impl frame_system::Config for Runtime {
108110
type Header = Header;
109111
type Event = TestEvent;
110112
type BlockHashCount = BlockHashCount;
111-
type MaximumBlockWeight = MaximumBlockWeight;
112-
type DbWeight = RocksDbWeight;
113-
type BlockExecutionWeight = ();
114-
type ExtrinsicBaseWeight = ();
115-
type MaximumExtrinsicWeight = MaximumBlockWeight;
116-
type MaximumBlockLength = MaximumBlockLength;
117-
type AvailableBlockRatio = AvailableBlockRatio;
118113
type Version = ();
119114
type PalletInfo = ();
120115
type AccountData = ();
@@ -124,7 +119,8 @@ impl frame_system::Config for Runtime {
124119
}
125120

126121
parameter_types! {
127-
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
122+
pub OffencesWeightSoftLimit: Weight =
123+
Perbill::from_percent(60) * BlockWeights::get().max_block;
128124
}
129125

130126
impl Config for Runtime {

0 commit comments

Comments
 (0)