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 2 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
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