From 40e113b26005663322373d4c14973d8aedb3f613 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 30 Sep 2022 20:56:21 +0200 Subject: [PATCH] Revert "Properly set the max proof size weight on defaults and tests (#12383)" This reverts commit 61b9a4d1a8a9bf39c1d89a8dd02f82785c10860c. --- bin/node-template/runtime/src/lib.rs | 7 +- bin/node/runtime/src/impls.rs | 2 +- bin/node/runtime/src/lib.rs | 4 +- frame/balances/src/tests_composite.rs | 4 +- frame/balances/src/tests_local.rs | 4 +- frame/balances/src/tests_reentrancy.rs | 4 +- frame/contracts/src/tests.rs | 14 +- frame/democracy/src/tests.rs | 4 +- .../election-provider-multi-phase/src/lib.rs | 9 +- .../election-provider-multi-phase/src/mock.rs | 7 +- .../src/signed.rs | 9 +- .../src/unsigned.rs | 292 +++--------------- frame/elections-phragmen/src/lib.rs | 4 +- frame/executive/src/lib.rs | 5 +- frame/fast-unstake/src/mock.rs | 4 +- frame/grandpa/src/tests.rs | 3 +- frame/scheduler/src/mock.rs | 4 +- frame/system/src/extensions/check_weight.rs | 20 +- frame/system/src/limits.rs | 24 +- frame/system/src/mock.rs | 2 +- .../asset-tx-payment/src/tests.rs | 2 +- frame/transaction-payment/src/lib.rs | 2 +- 22 files changed, 107 insertions(+), 323 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 1d0e18d31bf80..f801068b10fda 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -139,11 +139,8 @@ parameter_types! { pub const BlockHashCount: BlockNumber = 2400; pub const Version: RuntimeVersion = VERSION; /// We allow for 2 seconds of compute with a 6 second average block time. - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::with_sensible_defaults( - (2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX), - NORMAL_DISPATCH_RATIO, - ); + pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights + ::with_sensible_defaults(2u64 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); pub const SS58Prefix: u8 = 42; diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index 0f9ed6e275196..fb2f3cec65290 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -224,7 +224,7 @@ mod multiplier_tests { fn multiplier_can_grow_from_zero() { // if the min is too small, then this will not change, and we are doomed forever. // the weight is 1/100th bigger than target. - run_with_system_weight(target().set_ref_time(target().ref_time() * 101 / 100), || { + run_with_system_weight(target() * 101 / 100, || { let next = runtime_multiplier_update(min_multiplier()); assert!(next > min_multiplier(), "{:?} !>= {:?}", next, min_multiplier()); }) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 4fa4049e22682..832b193d2a06c 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -170,8 +170,8 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10); /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used /// by Operational extrinsics. const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -/// We allow for 2 seconds of compute with a 6 second average block time, with maximum proof size. -const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2).set_proof_size(u64::MAX); +/// We allow for 2 seconds of compute with a 6 second average block time. +const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2); parameter_types! { pub const BlockHashCount: BlockNumber = 2400; diff --git a/frame/balances/src/tests_composite.rs b/frame/balances/src/tests_composite.rs index f8a8fdd1851d4..1e38d611773d4 100644 --- a/frame/balances/src/tests_composite.rs +++ b/frame/balances/src/tests_composite.rs @@ -47,9 +47,7 @@ frame_support::construct_runtime!( parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024)); pub static ExistentialDeposit: u64 = 0; } impl frame_system::Config for Test { diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index 152a5da37410f..e080eafb66067 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -48,9 +48,7 @@ frame_support::construct_runtime!( parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024)); pub static ExistentialDeposit: u64 = 0; } impl frame_system::Config for Test { diff --git a/frame/balances/src/tests_reentrancy.rs b/frame/balances/src/tests_reentrancy.rs index 90363140000e8..fa2eb0e488e7d 100644 --- a/frame/balances/src/tests_reentrancy.rs +++ b/frame/balances/src/tests_reentrancy.rs @@ -51,9 +51,7 @@ frame_support::construct_runtime!( parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024)); pub static ExistentialDeposit: u64 = 0; } impl frame_system::Config for Test { diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index e5893c3dbd112..a56e4f5564845 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -279,9 +279,7 @@ impl RegisteredChainExtension for TempStorageExtension { parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - (2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(2u64 * WEIGHT_PER_SECOND); pub static ExistentialDeposit: u64 = 1; } impl frame_system::Config for Test { @@ -415,7 +413,7 @@ pub const BOB: AccountId32 = AccountId32::new([2u8; 32]); pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]); pub const DJANGO: AccountId32 = AccountId32::new([4u8; 32]); -pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000).set_proof_size(u64::MAX); +pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000); pub struct ExtBuilder { existential_deposit: u64, @@ -630,7 +628,7 @@ fn deposit_event_max_value_limit() { RuntimeOrigin::signed(ALICE), addr.clone(), 0, - GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer, + GAS_LIMIT * 2, // we are copying a huge buffer, None, ::Schedule::get().limits.payload_len.encode(), )); @@ -771,7 +769,7 @@ fn storage_max_value_limit() { RuntimeOrigin::signed(ALICE), addr.clone(), 0, - GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer + GAS_LIMIT * 2, // we are copying a huge buffer None, ::Schedule::get().limits.payload_len.encode(), )); @@ -2545,7 +2543,7 @@ fn gas_estimation_nested_call_fixed_limit() { ALICE, addr_caller, 0, - Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX), + Weight::from_ref_time(result.gas_required), Some(result.storage_deposit.charge_or_zero()), input, false, @@ -2615,7 +2613,7 @@ fn gas_estimation_call_runtime() { ALICE, addr_caller, 0, - Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX), + Weight::from_ref_time(result.gas_required), None, call.encode(), false, diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 03d7216fd5aaa..17b35ee3c38cd 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -78,9 +78,7 @@ impl Contains for BaseFilter { parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - Weight::from_ref_time(1_000_000).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1_000_000)); } impl frame_system::Config for Test { type BaseCallFilter = BaseFilter; diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index fb17bd25ea541..649aec30c58b3 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -1011,8 +1011,10 @@ pub mod pallet { // unlikely to ever return an error: if phase is signed, snapshot will exist. let size = Self::snapshot_metadata().ok_or(Error::::MissingSnapshotMetadata)?; + // TODO: account for proof size weight ensure!( - Self::solution_weight_of(&raw_solution, size).all_lt(T::SignedMaxWeight::get()), + Self::solution_weight_of(&raw_solution, size).ref_time() < + T::SignedMaxWeight::get().ref_time(), Error::::SignedTooMuchWeight, ); @@ -2340,8 +2342,9 @@ mod tests { }; let mut active = 1; - while weight_with(active) - .all_lte(::BlockWeights::get().max_block) || + // TODO: account for proof size weight + while weight_with(active).ref_time() <= + ::BlockWeights::get().max_block.ref_time() || active == all_voters { active += 1; diff --git a/frame/election-provider-multi-phase/src/mock.rs b/frame/election-provider-multi-phase/src/mock.rs index d3082be0cf750..c1c53a3980676 100644 --- a/frame/election-provider-multi-phase/src/mock.rs +++ b/frame/election-provider-multi-phase/src/mock.rs @@ -26,7 +26,7 @@ pub use frame_support::{assert_noop, assert_ok, pallet_prelude::GetDefault}; use frame_support::{ bounded_vec, parameter_types, traits::{ConstU32, Hooks}, - weights::{constants, Weight}, + weights::Weight, BoundedVec, }; use multi_phase::unsigned::{IndexAssignmentOf, VoterOf}; @@ -227,10 +227,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); parameter_types! { pub const ExistentialDeposit: u64 = 1; pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights - ::with_sensible_defaults( - Weight::from_components(2u64 * constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX), - NORMAL_DISPATCH_RATIO, - ); + ::with_sensible_defaults(2u64 * frame_support::weights::constants::WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); } impl pallet_balances::Config for Runtime { diff --git a/frame/election-provider-multi-phase/src/signed.rs b/frame/election-provider-multi-phase/src/signed.rs index 2e01d99be0a42..1cf071e6796f1 100644 --- a/frame/election-provider-multi-phase/src/signed.rs +++ b/frame/election-provider-multi-phase/src/signed.rs @@ -957,7 +957,7 @@ mod tests { #[test] fn cannot_consume_too_much_future_weight() { ExtBuilder::default() - .signed_weight(Weight::from_ref_time(40).set_proof_size(u64::MAX)) + .signed_weight(Weight::from_ref_time(40)) .mock_weight_info(MockedWeightInfo::Basic) .build_and_execute(|| { roll_to(15); @@ -973,14 +973,11 @@ mod tests { // default solution will have 5 edges (5 * 5 + 10) assert_eq!(solution_weight, Weight::from_ref_time(35)); assert_eq!(raw.solution.voter_count(), 5); - assert_eq!( - ::SignedMaxWeight::get(), - Weight::from_ref_time(40).set_proof_size(u64::MAX) - ); + assert_eq!(::SignedMaxWeight::get(), Weight::from_ref_time(40)); assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(raw.clone()))); - ::set(Weight::from_ref_time(30).set_proof_size(u64::MAX)); + ::set(Weight::from_ref_time(30)); // note: resubmitting the same solution is technically okay as long as the queue has // space. diff --git a/frame/election-provider-multi-phase/src/unsigned.rs b/frame/election-provider-multi-phase/src/unsigned.rs index 025ff832bb08a..281ac37421174 100644 --- a/frame/election-provider-multi-phase/src/unsigned.rs +++ b/frame/election-provider-multi-phase/src/unsigned.rs @@ -638,7 +638,8 @@ impl Miner { }; let next_voters = |current_weight: Weight, voters: u32, step: u32| -> Result { - if current_weight.all_lt(max_weight) { + // TODO: account for proof size weight + if current_weight.ref_time() < max_weight.ref_time() { let next_voters = voters.checked_add(step); match next_voters { Some(voters) if voters < max_voters => Ok(voters), @@ -673,7 +674,8 @@ impl Miner { // Time to finish. We might have reduced less than expected due to rounding error. Increase // one last time if we have any room left, the reduce until we are sure we are below limit. - while voters < max_voters && weight_with(voters + 1).all_lt(max_weight) { + // TODO: account for proof size weight + while voters < max_voters && weight_with(voters + 1).ref_time() < max_weight.ref_time() { voters += 1; } while voters.checked_sub(1).is_some() && weight_with(voters).any_gt(max_weight) { @@ -681,8 +683,9 @@ impl Miner { } let final_decision = voters.min(size.voters); + // TODO: account for proof size weight debug_assert!( - weight_with(final_decision).all_lte(max_weight), + weight_with(final_decision).ref_time() <= max_weight.ref_time(), "weight_with({}) <= {}", final_decision, max_weight, @@ -700,346 +703,151 @@ mod max_weight { fn find_max_voter_binary_search_works() { let w = SolutionOrSnapshotSize { voters: 10, targets: 0 }; MockWeightInfo::set(crate::mock::MockedWeightInfo::Complex); + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::zero()), 0); + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0); + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::zero().set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(999).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1001).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1990).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1990)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1999).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2001).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2010).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2990).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2990)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2999).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2999)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(3000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(3000)), 3 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(3333).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)), 3 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(5500).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(5500)), 5 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(7777).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(7777)), 7 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(9999).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(9999)), 9 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(10_000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(10_000)), 10 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(10_999).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(10_999)), 10 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(11_000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(11_000)), 10 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(22_000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(22_000)), 10 ); let w = SolutionOrSnapshotSize { voters: 1, targets: 0 }; + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(0)), 0); + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0); + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(0).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(999).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1001).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1990).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1990)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1999).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2001).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2010).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(3333).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)), 1 ); let w = SolutionOrSnapshotSize { voters: 2, targets: 0 }; + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(0)), 0); + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0); + assert_eq!(Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(0).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(999).set_proof_size(u64::MAX) - ), - 0 - ); - assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1001).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(1999).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)), 1 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2000).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2001).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(2010).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)), 2 ); assert_eq!( - Miner::::maximum_voter_for_weight( - 0, - w, - Weight::from_ref_time(3333).set_proof_size(u64::MAX) - ), + Miner::::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)), 2 ); } @@ -1323,7 +1131,7 @@ mod tests { #[test] fn miner_trims_weight() { ExtBuilder::default() - .miner_weight(Weight::from_ref_time(100).set_proof_size(u64::MAX)) + .miner_weight(Weight::from_ref_time(100)) .mock_weight_info(crate::mock::MockedWeightInfo::Basic) .build_and_execute(|| { roll_to(25); @@ -1341,7 +1149,7 @@ mod tests { assert_eq!(raw.solution.voter_count(), 5); // now reduce the max weight - ::set(Weight::from_ref_time(25).set_proof_size(u64::MAX)); + ::set(Weight::from_ref_time(25)); let (raw, witness) = MultiPhase::mine_solution().unwrap(); let solution_weight = ::solution_weight( diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 165a8fcab429b..0616087d975e8 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -1174,9 +1174,7 @@ mod tests { parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024)); } impl frame_system::Config for Test { diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index b7884efccf685..014c7a2bc02a6 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -459,7 +459,8 @@ where let max_weight = >::get().max_block; let remaining_weight = max_weight.saturating_sub(weight.total()); - if remaining_weight.all_gt(Weight::zero()) { + // TODO: account for proof size weight + if remaining_weight.ref_time() > 0 { let used_weight = >::on_idle( block_number, remaining_weight, @@ -767,7 +768,7 @@ mod tests { frame_system::limits::BlockWeights::builder() .base_block(Weight::from_ref_time(10)) .for_class(DispatchClass::all(), |weights| weights.base_extrinsic = Weight::from_ref_time(5)) - .for_class(DispatchClass::non_mandatory(), |weights| weights.max_total = Weight::from_ref_time(1024).set_proof_size(u64::MAX).into()) + .for_class(DispatchClass::non_mandatory(), |weights| weights.max_total = Weight::from_ref_time(1024).into()) .build_or_panic(); pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 10, diff --git a/frame/fast-unstake/src/mock.rs b/frame/fast-unstake/src/mock.rs index 71fc2d4ba905a..dc2c694d52956 100644 --- a/frame/fast-unstake/src/mock.rs +++ b/frame/fast-unstake/src/mock.rs @@ -32,9 +32,7 @@ pub type T = Runtime; parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - (2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(2u64 * WEIGHT_PER_SECOND); } impl frame_system::Config for Runtime { diff --git a/frame/grandpa/src/tests.rs b/frame/grandpa/src/tests.rs index 626decd12821e..5d2ebdf29cb6b 100644 --- a/frame/grandpa/src/tests.rs +++ b/frame/grandpa/src/tests.rs @@ -856,7 +856,8 @@ fn valid_equivocation_reports_dont_pay_fees() { .get_dispatch_info(); // it should have non-zero weight and the fee has to be paid. - assert!(info.weight.any_gt(Weight::zero())); + // TODO: account for proof size weight + assert!(info.weight.ref_time() > 0); assert_eq!(info.pays_fee, Pays::Yes); // report the equivocation. diff --git a/frame/scheduler/src/mock.rs b/frame/scheduler/src/mock.rs index 6aaad13e48183..6f6667590a6c3 100644 --- a/frame/scheduler/src/mock.rs +++ b/frame/scheduler/src/mock.rs @@ -118,9 +118,7 @@ impl Contains for BaseFilter { parameter_types! { pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - Weight::from_ref_time(2_000_000_000_000).set_proof_size(u64::MAX), - ); + frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(2_000_000_000_000)); } impl system::Config for Test { type BaseCallFilter = BaseFilter; diff --git a/frame/system/src/extensions/check_weight.rs b/frame/system/src/extensions/check_weight.rs index 5c3b80f59bfa8..15a88913cd337 100644 --- a/frame/system/src/extensions/check_weight.rs +++ b/frame/system/src/extensions/check_weight.rs @@ -310,7 +310,7 @@ mod tests { check(|max, len| { assert_ok!(CheckWeight::::do_pre_dispatch(max, len)); assert_eq!(System::block_weight().total(), Weight::MAX); - assert!(System::block_weight().total().ref_time() > block_weight_limit().ref_time()); + assert!(System::block_weight().total().all_gt(block_weight_limit())); }); check(|max, len| { assert_ok!(CheckWeight::::do_validate(max, len)); @@ -367,7 +367,7 @@ mod tests { new_test_ext().execute_with(|| { System::register_extra_weight_unchecked(Weight::MAX, DispatchClass::Normal); assert_eq!(System::block_weight().total(), Weight::MAX); - assert!(System::block_weight().total().ref_time() > block_weight_limit().ref_time()); + assert!(System::block_weight().total().all_gt(block_weight_limit())); }); } @@ -392,8 +392,8 @@ mod tests { assert_ok!(CheckWeight::::do_pre_dispatch(&max_normal, len)); assert_eq!(System::block_weight().total(), Weight::from_ref_time(768)); assert_ok!(CheckWeight::::do_pre_dispatch(&rest_operational, len)); - assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX)); - assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0)); + assert_eq!(block_weight_limit(), Weight::from_ref_time(1024)); + assert_eq!(System::block_weight().total(), block_weight_limit()); // Checking single extrinsic should not take current block weight into account. assert_eq!(CheckWeight::::check_extrinsic_weight(&rest_operational), Ok(())); }); @@ -417,8 +417,8 @@ mod tests { // Extra 20 here from block execution + base extrinsic weight assert_eq!(System::block_weight().total(), Weight::from_ref_time(266)); assert_ok!(CheckWeight::::do_pre_dispatch(&max_normal, len)); - assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX)); - assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0)); + assert_eq!(block_weight_limit(), Weight::from_ref_time(1024)); + assert_eq!(System::block_weight().total(), block_weight_limit()); }); } @@ -669,7 +669,7 @@ mod tests { assert_ok!(CheckWeight::::do_pre_dispatch(&max_normal, len)); assert_eq!(System::block_weight().total(), Weight::from_ref_time(768)); assert_ok!(CheckWeight::::do_pre_dispatch(&mandatory, len)); - assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX)); + assert_eq!(block_weight_limit(), Weight::from_ref_time(1024)); assert_eq!(System::block_weight().total(), Weight::from_ref_time(1024 + 768)); assert_eq!(CheckWeight::::check_extrinsic_weight(&mandatory), Ok(())); }); @@ -682,11 +682,11 @@ mod tests { .base_block(Weight::zero()) .for_class(DispatchClass::non_mandatory(), |w| { w.base_extrinsic = Weight::zero(); - w.max_total = Some(Weight::from_ref_time(20).set_proof_size(u64::MAX)); + w.max_total = Some(Weight::from_ref_time(20)); }) .for_class(DispatchClass::Mandatory, |w| { w.base_extrinsic = Weight::zero(); - w.reserved = Some(Weight::from_ref_time(5).set_proof_size(u64::MAX)); + w.reserved = Some(Weight::from_ref_time(5)); w.max_total = None; }) .build_or_panic(); @@ -695,7 +695,7 @@ mod tests { DispatchClass::Operational => Weight::from_ref_time(10), DispatchClass::Mandatory => Weight::zero(), }); - assert_eq!(maximum_weight.max_block, all_weight.total().set_proof_size(u64::MAX)); + assert_eq!(maximum_weight.max_block, all_weight.total()); // fits into reserved let mandatory1 = DispatchInfo { diff --git a/frame/system/src/limits.rs b/frame/system/src/limits.rs index 07ad240afe159..cfc1d261baa01 100644 --- a/frame/system/src/limits.rs +++ b/frame/system/src/limits.rs @@ -207,10 +207,7 @@ pub struct BlockWeights { impl Default for BlockWeights { fn default() -> Self { - Self::with_sensible_defaults( - Weight::from_components(constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX), - DEFAULT_NORMAL_RATIO, - ) + Self::with_sensible_defaults(1u64 * constants::WEIGHT_PER_SECOND, DEFAULT_NORMAL_RATIO) } } @@ -227,6 +224,7 @@ impl BlockWeights { } let mut error = ValidationErrors::default(); + // TODO: account for proof size weight in the assertions below for class in DispatchClass::all() { let weights = self.per_class.get(*class); let max_for_class = or_max(weights.max_total); @@ -235,18 +233,16 @@ impl BlockWeights { // Make sure that if total is set it's greater than base_block && // base_for_class error_assert!( - (max_for_class.all_gt(self.base_block) && max_for_class.all_gt(base_for_class)) - || max_for_class == Weight::zero(), + (max_for_class.ref_time() > self.base_block.ref_time() && max_for_class.ref_time() > base_for_class.ref_time()) + || max_for_class.ref_time() == 0, &mut error, "[{:?}] {:?} (total) has to be greater than {:?} (base block) & {:?} (base extrinsic)", class, max_for_class, self.base_block, base_for_class, ); // Max extrinsic can't be greater than max_for_class. error_assert!( - weights - .max_extrinsic - .unwrap_or(Weight::zero()) - .all_lte(max_for_class.saturating_sub(base_for_class)), + weights.max_extrinsic.unwrap_or(Weight::zero()).ref_time() <= + max_for_class.saturating_sub(base_for_class).ref_time(), &mut error, "[{:?}] {:?} (max_extrinsic) can't be greater than {:?} (max for class)", class, @@ -255,14 +251,14 @@ impl BlockWeights { ); // Max extrinsic should not be 0 error_assert!( - weights.max_extrinsic.unwrap_or_else(Weight::max_value).all_gt(Weight::zero()), + weights.max_extrinsic.unwrap_or_else(Weight::max_value).ref_time() > 0, &mut error, "[{:?}] {:?} (max_extrinsic) must not be 0. Check base cost and average initialization cost.", class, weights.max_extrinsic, ); // Make sure that if reserved is set it's greater than base_for_class. error_assert!( - reserved.all_gt(base_for_class) || reserved == Weight::zero(), + reserved.ref_time() > base_for_class.ref_time() || reserved.ref_time() == 0, &mut error, "[{:?}] {:?} (reserved) has to be greater than {:?} (base extrinsic) if set", class, @@ -271,7 +267,7 @@ impl BlockWeights { ); // Make sure max block is greater than max_total if it's set. error_assert!( - self.max_block.all_gte(weights.max_total.unwrap_or(Weight::zero())), + self.max_block.ref_time() >= weights.max_total.unwrap_or(Weight::zero()).ref_time(), &mut error, "[{:?}] {:?} (max block) has to be greater than {:?} (max for class)", class, @@ -280,7 +276,7 @@ impl BlockWeights { ); // Make sure we can fit at least one extrinsic. error_assert!( - self.max_block.all_gt(base_for_class + self.base_block), + self.max_block.ref_time() > (base_for_class + self.base_block).ref_time(), &mut error, "[{:?}] {:?} (max block) must fit at least one extrinsic {:?} (base weight)", class, diff --git a/frame/system/src/mock.rs b/frame/system/src/mock.rs index d31a1b08667e5..b6fc121612050 100644 --- a/frame/system/src/mock.rs +++ b/frame/system/src/mock.rs @@ -41,7 +41,7 @@ frame_support::construct_runtime!( ); const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -const MAX_BLOCK_WEIGHT: Weight = Weight::from_ref_time(1024).set_proof_size(u64::MAX); +const MAX_BLOCK_WEIGHT: Weight = Weight::from_ref_time(1024); parameter_types! { pub Version: RuntimeVersion = RuntimeVersion { diff --git a/frame/transaction-payment/asset-tx-payment/src/tests.rs b/frame/transaction-payment/asset-tx-payment/src/tests.rs index e775f3aa92990..cdf7d17898145 100644 --- a/frame/transaction-payment/asset-tx-payment/src/tests.rs +++ b/frame/transaction-payment/asset-tx-payment/src/tests.rs @@ -71,7 +71,7 @@ impl Get for BlockWeights { weights.base_extrinsic = ExtrinsicBaseWeight::get().into(); }) .for_class(DispatchClass::non_mandatory(), |weights| { - weights.max_total = Weight::from_ref_time(1024).set_proof_size(u64::MAX).into(); + weights.max_total = Weight::from_ref_time(1024).into(); }) .build_or_panic() } diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 80297d1a0d362..1ad6a2b3b3b6f 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -889,7 +889,7 @@ mod tests { weights.base_extrinsic = ExtrinsicBaseWeight::get().into(); }) .for_class(DispatchClass::non_mandatory(), |weights| { - weights.max_total = Weight::from_ref_time(1024).set_proof_size(u64::MAX).into(); + weights.max_total = Weight::from_ref_time(1024).into(); }) .build_or_panic() }