Skip to content

Commit b54b0aa

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 463d530 commit b54b0aa

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

fuzzer/src/mock.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ pub struct Test;
4545

4646
impl frame_system::Config for Test {
4747
type BaseCallFilter = ();
48-
type Origin = Origin;
48+
type BlockWeights = ();
49+
type BlockLength = ();
4950
type DbWeight = ();
50-
type BlockExecutionWeight = ();
51-
type ExtrinsicBaseWeight = ();
52-
type MaximumExtrinsicWeight = ();
51+
type Origin = Origin;
5352
type Index = AccountIndex;
5453
type BlockNumber = BlockNumber;
5554
type Call = Call;
@@ -60,9 +59,6 @@ impl frame_system::Config for Test {
6059
type Header = sp_runtime::testing::Header;
6160
type Event = ();
6261
type BlockHashCount = ();
63-
type MaximumBlockWeight = ();
64-
type AvailableBlockRatio = ();
65-
type MaximumBlockLength = ();
6662
type Version = ();
6763
type PalletInfo = ();
6864
type AccountData = pallet_balances::AccountData<u64>;

src/benchmarking.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,12 @@ benchmarks! {
521521
compact,
522522
score,
523523
size
524-
) = offchain_election::prepare_submission::<T>(assignments, winners, false, T::MaximumBlockWeight::get()).unwrap();
524+
) = offchain_election::prepare_submission::<T>(
525+
assignments,
526+
winners,
527+
false,
528+
T::BlockWeights::get().max_block,
529+
).unwrap();
525530

526531
assert_eq!(
527532
winners.len(), compact.unique_targets().len(),
@@ -589,7 +594,12 @@ benchmarks! {
589594
compact,
590595
score,
591596
size
592-
) = offchain_election::prepare_submission::<T>(assignments, winners, false, T::MaximumBlockWeight::get()).unwrap();
597+
) = offchain_election::prepare_submission::<T>(
598+
assignments,
599+
winners,
600+
false,
601+
T::BlockWeights::get().max_block,
602+
).unwrap();
593603

594604
assert_eq!(
595605
winners.len(), compact.unique_targets().len(),

src/mock.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ pub struct Test;
129129

130130
parameter_types! {
131131
pub const BlockHashCount: u64 = 250;
132-
pub const MaximumBlockWeight: Weight = frame_support::weights::constants::WEIGHT_PER_SECOND * 2;
133-
pub const MaximumBlockLength: u32 = 2 * 1024;
134-
pub const AvailableBlockRatio: Perbill = Perbill::one();
132+
pub BlockWeights: frame_system::limits::BlockWeights =
133+
frame_system::limits::BlockWeights::simple_max(
134+
frame_support::weights::constants::WEIGHT_PER_SECOND * 2
135+
);
135136
pub const MaxLocks: u32 = 1024;
136137
pub static SessionsPerEra: SessionIndex = 3;
137138
pub static ExistentialDeposit: Balance = 0;
@@ -143,6 +144,9 @@ parameter_types! {
143144

144145
impl frame_system::Config for Test {
145146
type BaseCallFilter = ();
147+
type BlockWeights = ();
148+
type BlockLength = ();
149+
type DbWeight = RocksDbWeight;
146150
type Origin = Origin;
147151
type Index = AccountIndex;
148152
type BlockNumber = BlockNumber;
@@ -154,13 +158,6 @@ impl frame_system::Config for Test {
154158
type Header = Header;
155159
type Event = MetaEvent;
156160
type BlockHashCount = BlockHashCount;
157-
type MaximumBlockWeight = MaximumBlockWeight;
158-
type DbWeight = RocksDbWeight;
159-
type BlockExecutionWeight = ();
160-
type ExtrinsicBaseWeight = ();
161-
type MaximumExtrinsicWeight = MaximumBlockWeight;
162-
type AvailableBlockRatio = AvailableBlockRatio;
163-
type MaximumBlockLength = MaximumBlockLength;
164161
type Version = ();
165162
type PalletInfo = ();
166163
type AccountData = pallet_balances::AccountData<Balance>;
@@ -235,7 +232,7 @@ parameter_types! {
235232
pub const MaxNominatorRewardedPerValidator: u32 = 64;
236233
pub const UnsignedPriority: u64 = 1 << 20;
237234
pub const MinSolutionScoreBump: Perbill = Perbill::zero();
238-
pub const OffchainSolutionWeightLimit: Weight = MaximumBlockWeight::get();
235+
pub OffchainSolutionWeightLimit: Weight = BlockWeights::get().max_block;
239236
}
240237

241238
thread_local! {

src/testing_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub fn get_seq_phragmen_solution<T: Config>(
301301
assignments,
302302
winners,
303303
do_reduce,
304-
T::MaximumBlockWeight::get(),
304+
T::BlockWeights::get().max_block,
305305
)
306306
.unwrap()
307307
}

0 commit comments

Comments
 (0)