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

Properly set the max proof size weight on defaults and tests #12383

Merged
merged 16 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ 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, NORMAL_DISPATCH_RATIO);
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 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() * 101 / 100, || {
run_with_system_weight(target().set_ref_time(target().ref_time() * 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.
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);
/// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a general note, this will not work for Parachains. Parachains have the max proof size defined by the relay chain and this value could change any block (it isn't but it is a value that is changeable on the relay chain). So, we would need to have a dynamic way of getting the max proof size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkchr getting the weight of the pov from the validation data is a solution here right? Because, this "could" change from the relay side dynamically, or can we just assume that MAX_POV_SIZE from the primitives is always good to use statically?


parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
Expand Down
4 changes: 3 additions & 1 deletion frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ 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));
frame_system::limits::BlockWeights::simple_max(
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
);
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
Expand Down
4 changes: 3 additions & 1 deletion frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ 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));
frame_system::limits::BlockWeights::simple_max(
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
);
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
Expand Down
4 changes: 3 additions & 1 deletion frame/balances/src/tests_reentrancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ 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));
frame_system::limits::BlockWeights::simple_max(
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
);
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
Expand Down
14 changes: 8 additions & 6 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ impl RegisteredChainExtension<Test> for TempStorageExtension {

parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(2u64 * WEIGHT_PER_SECOND);
frame_system::limits::BlockWeights::simple_max(
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
);
pub static ExistentialDeposit: u64 = 1;
}
impl frame_system::Config for Test {
Expand Down Expand Up @@ -413,7 +415,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);
pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000).set_proof_size(u64::MAX);

pub struct ExtBuilder {
existential_deposit: u64,
Expand Down Expand Up @@ -628,7 +630,7 @@ fn deposit_event_max_value_limit() {
RuntimeOrigin::signed(ALICE),
addr.clone(),
0,
GAS_LIMIT * 2, // we are copying a huge buffer,
GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer,
None,
<Test as Config>::Schedule::get().limits.payload_len.encode(),
));
Expand Down Expand Up @@ -769,7 +771,7 @@ fn storage_max_value_limit() {
RuntimeOrigin::signed(ALICE),
addr.clone(),
0,
GAS_LIMIT * 2, // we are copying a huge buffer
GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer
None,
<Test as Config>::Schedule::get().limits.payload_len.encode(),
));
Expand Down Expand Up @@ -2543,7 +2545,7 @@ fn gas_estimation_nested_call_fixed_limit() {
ALICE,
addr_caller,
0,
Weight::from_ref_time(result.gas_required),
Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX),
Some(result.storage_deposit.charge_or_zero()),
input,
false,
Expand Down Expand Up @@ -2613,7 +2615,7 @@ fn gas_estimation_call_runtime() {
ALICE,
addr_caller,
0,
Weight::from_ref_time(result.gas_required),
Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX),
None,
call.encode(),
false,
Expand Down
4 changes: 3 additions & 1 deletion frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ 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));
frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(1_000_000).set_proof_size(u64::MAX),
);
}
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
Expand Down
9 changes: 3 additions & 6 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,8 @@ 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).ref_time() <
T::SignedMaxWeight::get().ref_time(),
Self::solution_weight_of(&raw_solution, size).all_lt(T::SignedMaxWeight::get()),
Error::<T>::SignedTooMuchWeight,
);

Expand Down Expand Up @@ -2338,9 +2336,8 @@ mod tests {
};

let mut active = 1;
// TODO: account for proof size weight
while weight_with(active).ref_time() <=
<Runtime as frame_system::Config>::BlockWeights::get().max_block.ref_time() ||
while weight_with(active)
.all_lte(<Runtime as frame_system::Config>::BlockWeights::get().max_block) ||
active == all_voters
{
active += 1;
Expand Down
7 changes: 5 additions & 2 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::Weight,
weights::{constants, Weight},
BoundedVec,
};
use multi_phase::unsigned::{IndexAssignmentOf, VoterOf};
Expand Down Expand Up @@ -227,7 +227,10 @@ 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(2u64 * frame_support::weights::constants::WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
::with_sensible_defaults(
Weight::from_components(2u64 * constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX),
NORMAL_DISPATCH_RATIO,
);
}

impl pallet_balances::Config for Runtime {
Expand Down
9 changes: 6 additions & 3 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))
.signed_weight(Weight::from_ref_time(40).set_proof_size(u64::MAX))
.mock_weight_info(MockedWeightInfo::Basic)
.build_and_execute(|| {
roll_to(15);
Expand All @@ -973,11 +973,14 @@ 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));
assert_eq!(
<Runtime as Config>::SignedMaxWeight::get(),
Weight::from_ref_time(40).set_proof_size(u64::MAX)
);

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

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

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