Skip to content

Commit 7c78199

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 3f0784d commit 7c78199

File tree

8 files changed

+671
-271
lines changed

8 files changed

+671
-271
lines changed

benches/bench.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,22 @@ impl_outer_event! {
5454

5555
frame_support::parameter_types! {
5656
pub const BlockHashCount: u64 = 250;
57-
pub const MaximumBlockWeight: Weight = 4 * 1024 * 1024;
58-
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
59-
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
57+
pub BlockWeights: frame_system::limits::BlockWeights =
58+
frame_system::limits::BlockWeights::with_sensible_defaults(
59+
4 * 1024 * 1024, Perbill::from_percent(75),
60+
);
61+
pub BlockLength: frame_system::limits::BlockLength =
62+
frame_system::limits::BlockLength::max_with_normal_ratio(
63+
4 * 1024 * 1024, Perbill::from_percent(75),
64+
);
6065
}
6166
#[derive(Clone, Eq, PartialEq)]
6267
pub struct Runtime;
6368
impl system::Config for Runtime {
6469
type BaseCallFilter = ();
70+
type BlockWeights = ();
71+
type BlockLength = BlockLength;
72+
type DbWeight = ();
6573
type Origin = Origin;
6674
type Index = u64;
6775
type BlockNumber = u64;
@@ -73,13 +81,6 @@ impl system::Config for Runtime {
7381
type Header = Header;
7482
type Event = Event;
7583
type BlockHashCount = BlockHashCount;
76-
type MaximumBlockWeight = MaximumBlockWeight;
77-
type DbWeight = ();
78-
type BlockExecutionWeight = ();
79-
type ExtrinsicBaseWeight = ();
80-
type MaximumExtrinsicWeight = MaximumBlockWeight;
81-
type MaximumBlockLength = MaximumBlockLength;
82-
type AvailableBlockRatio = AvailableBlockRatio;
8384
type Version = ();
8485
type PalletInfo = ();
8586
type AccountData = ();

benchmarking/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ use sp_std::prelude::*;
2525
use sp_core::{ChangesTrieConfiguration, storage::well_known_keys};
2626
use sp_runtime::traits::Hash;
2727
use frame_benchmarking::{benchmarks, whitelisted_caller};
28-
use frame_support::traits::Get;
29-
use frame_support::storage::{self, StorageMap};
28+
use frame_support::{
29+
storage::{self, StorageMap},
30+
traits::Get,
31+
};
3032
use frame_system::{Module as System, Call, RawOrigin, DigestItemOf, AccountInfo};
3133

3234
mod mock;
@@ -38,7 +40,7 @@ benchmarks! {
3840
_ { }
3941

4042
remark {
41-
let b in 0 .. T::MaximumBlockLength::get();
43+
let b in 0 .. T::BlockWeights::get().max_block as u32;
4244
let remark_message = vec![1; b as usize];
4345
let caller = whitelisted_caller();
4446
}: _(RawOrigin::Signed(caller), remark_message)

benchmarking/src/mock.rs

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

5353
impl frame_system::Config for Test {
5454
type BaseCallFilter = ();
55+
type BlockWeights = ();
56+
type BlockLength = ();
57+
type DbWeight = ();
5558
type Origin = Origin;
5659
type Index = AccountIndex;
5760
type BlockNumber = BlockNumber;
@@ -63,13 +66,6 @@ impl frame_system::Config for Test {
6366
type Header = sp_runtime::testing::Header;
6467
type Event = ();
6568
type BlockHashCount = ();
66-
type MaximumBlockWeight = ();
67-
type DbWeight = ();
68-
type BlockExecutionWeight = ();
69-
type ExtrinsicBaseWeight = ();
70-
type MaximumExtrinsicWeight = ();
71-
type AvailableBlockRatio = ();
72-
type MaximumBlockLength = ();
7369
type Version = ();
7470
type PalletInfo = ();
7571
type AccountData = ();

0 commit comments

Comments
 (0)