Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 61b9a4d

Browse files
authored
Properly set the max proof size weight on defaults and tests (#12383)
* Properly set the max proof size weight on defaults and tests * cargo fmt * Set proper max proof size for contracts pallet tests * Properly set max proof size for node * Properly set max proof size for frame system mock * Update test expectations * Update test expectations * Properly set max proof size for balances mock * Update test expectations * Update test expectations * Properly set max proof size for democracy mock * Properly set max proof size for scheduler mock * Properly set max proof size for fast unstake mock * Properly set max proof size for tx payment mock * Properly set max proof size for elections phragmen mock * Properly set max proof size for node template
1 parent 427fd09 commit 61b9a4d

File tree

22 files changed

+323
-107
lines changed

22 files changed

+323
-107
lines changed

bin/node-template/runtime/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ parameter_types! {
139139
pub const BlockHashCount: BlockNumber = 2400;
140140
pub const Version: RuntimeVersion = VERSION;
141141
/// We allow for 2 seconds of compute with a 6 second average block time.
142-
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
143-
::with_sensible_defaults(2u64 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
142+
pub BlockWeights: frame_system::limits::BlockWeights =
143+
frame_system::limits::BlockWeights::with_sensible_defaults(
144+
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
145+
NORMAL_DISPATCH_RATIO,
146+
);
144147
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
145148
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
146149
pub const SS58Prefix: u8 = 42;

bin/node/runtime/src/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ mod multiplier_tests {
224224
fn multiplier_can_grow_from_zero() {
225225
// if the min is too small, then this will not change, and we are doomed forever.
226226
// the weight is 1/100th bigger than target.
227-
run_with_system_weight(target() * 101 / 100, || {
227+
run_with_system_weight(target().set_ref_time(target().ref_time() * 101 / 100), || {
228228
let next = runtime_multiplier_update(min_multiplier());
229229
assert!(next > min_multiplier(), "{:?} !>= {:?}", next, min_multiplier());
230230
})

bin/node/runtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
170170
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
171171
/// by Operational extrinsics.
172172
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
173-
/// We allow for 2 seconds of compute with a 6 second average block time.
174-
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);
173+
/// We allow for 2 seconds of compute with a 6 second average block time, with maximum proof size.
174+
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2).set_proof_size(u64::MAX);
175175

176176
parameter_types! {
177177
pub const BlockHashCount: BlockNumber = 2400;

frame/balances/src/tests_composite.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ frame_support::construct_runtime!(
4747

4848
parameter_types! {
4949
pub BlockWeights: frame_system::limits::BlockWeights =
50-
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
50+
frame_system::limits::BlockWeights::simple_max(
51+
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
52+
);
5153
pub static ExistentialDeposit: u64 = 0;
5254
}
5355
impl frame_system::Config for Test {

frame/balances/src/tests_local.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ frame_support::construct_runtime!(
4848

4949
parameter_types! {
5050
pub BlockWeights: frame_system::limits::BlockWeights =
51-
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
51+
frame_system::limits::BlockWeights::simple_max(
52+
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
53+
);
5254
pub static ExistentialDeposit: u64 = 0;
5355
}
5456
impl frame_system::Config for Test {

frame/balances/src/tests_reentrancy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ frame_support::construct_runtime!(
5151

5252
parameter_types! {
5353
pub BlockWeights: frame_system::limits::BlockWeights =
54-
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
54+
frame_system::limits::BlockWeights::simple_max(
55+
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
56+
);
5557
pub static ExistentialDeposit: u64 = 0;
5658
}
5759
impl frame_system::Config for Test {

frame/contracts/src/tests.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ impl RegisteredChainExtension<Test> for TempStorageExtension {
279279

280280
parameter_types! {
281281
pub BlockWeights: frame_system::limits::BlockWeights =
282-
frame_system::limits::BlockWeights::simple_max(2u64 * WEIGHT_PER_SECOND);
282+
frame_system::limits::BlockWeights::simple_max(
283+
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
284+
);
283285
pub static ExistentialDeposit: u64 = 1;
284286
}
285287
impl frame_system::Config for Test {
@@ -413,7 +415,7 @@ pub const BOB: AccountId32 = AccountId32::new([2u8; 32]);
413415
pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]);
414416
pub const DJANGO: AccountId32 = AccountId32::new([4u8; 32]);
415417

416-
pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000);
418+
pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000).set_proof_size(u64::MAX);
417419

418420
pub struct ExtBuilder {
419421
existential_deposit: u64,
@@ -628,7 +630,7 @@ fn deposit_event_max_value_limit() {
628630
RuntimeOrigin::signed(ALICE),
629631
addr.clone(),
630632
0,
631-
GAS_LIMIT * 2, // we are copying a huge buffer,
633+
GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer,
632634
None,
633635
<Test as Config>::Schedule::get().limits.payload_len.encode(),
634636
));
@@ -769,7 +771,7 @@ fn storage_max_value_limit() {
769771
RuntimeOrigin::signed(ALICE),
770772
addr.clone(),
771773
0,
772-
GAS_LIMIT * 2, // we are copying a huge buffer
774+
GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer
773775
None,
774776
<Test as Config>::Schedule::get().limits.payload_len.encode(),
775777
));
@@ -2543,7 +2545,7 @@ fn gas_estimation_nested_call_fixed_limit() {
25432545
ALICE,
25442546
addr_caller,
25452547
0,
2546-
Weight::from_ref_time(result.gas_required),
2548+
Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX),
25472549
Some(result.storage_deposit.charge_or_zero()),
25482550
input,
25492551
false,
@@ -2613,7 +2615,7 @@ fn gas_estimation_call_runtime() {
26132615
ALICE,
26142616
addr_caller,
26152617
0,
2616-
Weight::from_ref_time(result.gas_required),
2618+
Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX),
26172619
None,
26182620
call.encode(),
26192621
false,

frame/democracy/src/tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ impl Contains<RuntimeCall> for BaseFilter {
7878

7979
parameter_types! {
8080
pub BlockWeights: frame_system::limits::BlockWeights =
81-
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1_000_000));
81+
frame_system::limits::BlockWeights::simple_max(
82+
Weight::from_ref_time(1_000_000).set_proof_size(u64::MAX),
83+
);
8284
}
8385
impl frame_system::Config for Test {
8486
type BaseCallFilter = BaseFilter;

frame/election-provider-multi-phase/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,8 @@ pub mod pallet {
10111011
// unlikely to ever return an error: if phase is signed, snapshot will exist.
10121012
let size = Self::snapshot_metadata().ok_or(Error::<T>::MissingSnapshotMetadata)?;
10131013

1014-
// TODO: account for proof size weight
10151014
ensure!(
1016-
Self::solution_weight_of(&raw_solution, size).ref_time() <
1017-
T::SignedMaxWeight::get().ref_time(),
1015+
Self::solution_weight_of(&raw_solution, size).all_lt(T::SignedMaxWeight::get()),
10181016
Error::<T>::SignedTooMuchWeight,
10191017
);
10201018

@@ -2342,9 +2340,8 @@ mod tests {
23422340
};
23432341

23442342
let mut active = 1;
2345-
// TODO: account for proof size weight
2346-
while weight_with(active).ref_time() <=
2347-
<Runtime as frame_system::Config>::BlockWeights::get().max_block.ref_time() ||
2343+
while weight_with(active)
2344+
.all_lte(<Runtime as frame_system::Config>::BlockWeights::get().max_block) ||
23482345
active == all_voters
23492346
{
23502347
active += 1;

frame/election-provider-multi-phase/src/mock.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use frame_support::{assert_noop, assert_ok, pallet_prelude::GetDefault};
2626
use frame_support::{
2727
bounded_vec, parameter_types,
2828
traits::{ConstU32, Hooks},
29-
weights::Weight,
29+
weights::{constants, Weight},
3030
BoundedVec,
3131
};
3232
use multi_phase::unsigned::{IndexAssignmentOf, VoterOf};
@@ -227,7 +227,10 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
227227
parameter_types! {
228228
pub const ExistentialDeposit: u64 = 1;
229229
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
230-
::with_sensible_defaults(2u64 * frame_support::weights::constants::WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
230+
::with_sensible_defaults(
231+
Weight::from_components(2u64 * constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX),
232+
NORMAL_DISPATCH_RATIO,
233+
);
231234
}
232235

233236
impl pallet_balances::Config for Runtime {

0 commit comments

Comments
 (0)