Skip to content

Commit b839b31

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 <5588131+kianenigma@users.noreply.github.com> * Rework the API a bit. * Fix compilation & tests. * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Add extra docs & rename few things. * Fix whitespace in ASCII art. * Update frame/system/src/limits.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * 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 <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org> Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
1 parent bc16d76 commit b839b31

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

benchmarking/src/mock.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ pub struct Test;
4747

4848
impl frame_system::Config for Test {
4949
type BaseCallFilter = ();
50+
type BlockWeights = ();
51+
type BlockLength = ();
52+
type DbWeight = ();
5053
type Origin = Origin;
5154
type Index = AccountIndex;
5255
type BlockNumber = BlockNumber;
@@ -58,13 +61,6 @@ impl frame_system::Config for Test {
5861
type Header = sp_runtime::testing::Header;
5962
type Event = ();
6063
type BlockHashCount = ();
61-
type MaximumBlockWeight = ();
62-
type DbWeight = ();
63-
type BlockExecutionWeight = ();
64-
type ExtrinsicBaseWeight = ();
65-
type MaximumExtrinsicWeight = ();
66-
type AvailableBlockRatio = ();
67-
type MaximumBlockLength = ();
6864
type Version = ();
6965
type PalletInfo = ();
7066
type AccountData = pallet_balances::AccountData<u64>;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ decl_module! {
549549
fn on_initialize(n: T::BlockNumber) -> Weight {
550550
if T::ShouldEndSession::should_end_session(n) {
551551
Self::rotate_session();
552-
T::MaximumBlockWeight::get()
552+
T::BlockWeights::get().max_block
553553
} else {
554554
// NOTE: the non-database part of the weight for `should_end_session(n)` is
555555
// included as weight for empty block, the database part is expected to be in

src/mock.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use super::*;
2121
use std::cell::RefCell;
22-
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
22+
use frame_support::{impl_outer_origin, parameter_types};
2323
use sp_core::{crypto::key_types::DUMMY, H256};
2424
use sp_runtime::{
2525
Perbill, impl_opaque_keys,
@@ -165,15 +165,17 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
165165
pub struct Test;
166166

167167
parameter_types! {
168-
pub const BlockHashCount: u64 = 250;
169-
pub const MaximumBlockWeight: Weight = 1024;
170-
pub const MaximumBlockLength: u32 = 2 * 1024;
171168
pub const MinimumPeriod: u64 = 5;
172-
pub const AvailableBlockRatio: Perbill = Perbill::one();
169+
pub const BlockHashCount: u64 = 250;
170+
pub BlockWeights: frame_system::limits::BlockWeights =
171+
frame_system::limits::BlockWeights::simple_max(1024);
173172
}
174173

175174
impl frame_system::Config for Test {
176175
type BaseCallFilter = ();
176+
type BlockWeights = ();
177+
type BlockLength = ();
178+
type DbWeight = ();
177179
type Origin = Origin;
178180
type Index = u64;
179181
type BlockNumber = u64;
@@ -185,13 +187,6 @@ impl frame_system::Config for Test {
185187
type Header = Header;
186188
type Event = ();
187189
type BlockHashCount = BlockHashCount;
188-
type MaximumBlockWeight = MaximumBlockWeight;
189-
type DbWeight = ();
190-
type BlockExecutionWeight = ();
191-
type ExtrinsicBaseWeight = ();
192-
type MaximumExtrinsicWeight = MaximumBlockWeight;
193-
type AvailableBlockRatio = AvailableBlockRatio;
194-
type MaximumBlockLength = MaximumBlockLength;
195190
type Version = ();
196191
type PalletInfo = ();
197192
type AccountData = ();

0 commit comments

Comments
 (0)