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 5 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
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/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
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