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

Commit

Permalink
Revert "Properly set the max proof size weight on defaults and tests (#…
Browse files Browse the repository at this point in the history
…12383)"

This reverts commit 61b9a4d.
  • Loading branch information
ggwpez committed Sep 30, 2022
1 parent 952030c commit 40e113b
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 323 deletions.
7 changes: 2 additions & 5 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
})
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions frame/balances/src/tests_reentrancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 6 additions & 8 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ impl RegisteredChainExtension<Test> 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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
<Test as Config>::Schedule::get().limits.payload_len.encode(),
));
Expand Down Expand Up @@ -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,
<Test as Config>::Schedule::get().limits.payload_len.encode(),
));
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ impl Contains<RuntimeCall> 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;
Expand Down
9 changes: 6 additions & 3 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::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::<T>::SignedTooMuchWeight,
);

Expand Down Expand Up @@ -2340,8 +2342,9 @@ mod tests {
};

let mut active = 1;
while weight_with(active)
.all_lte(<Runtime as frame_system::Config>::BlockWeights::get().max_block) ||
// TODO: account for proof size weight
while weight_with(active).ref_time() <=
<Runtime as frame_system::Config>::BlockWeights::get().max_block.ref_time() ||
active == all_voters
{
active += 1;
Expand Down
7 changes: 2 additions & 5 deletions frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions frame/election-provider-multi-phase/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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!(
<Runtime as Config>::SignedMaxWeight::get(),
Weight::from_ref_time(40).set_proof_size(u64::MAX)
);
assert_eq!(<Runtime as Config>::SignedMaxWeight::get(), Weight::from_ref_time(40));

assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(raw.clone())));

<SignedMaxWeight>::set(Weight::from_ref_time(30).set_proof_size(u64::MAX));
<SignedMaxWeight>::set(Weight::from_ref_time(30));

// note: resubmitting the same solution is technically okay as long as the queue has
// space.
Expand Down
Loading

0 comments on commit 40e113b

Please sign in to comment.