mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 14:31:13 +00:00
Properly set the max proof size weight on defaults and tests (#12383)
* Properly set the max proof size weight on defaults and tests * cargo fmt * Set proper max proof size for contracts pallet tests * Properly set max proof size for node * Properly set max proof size for frame system mock * Update test expectations * Update test expectations * Properly set max proof size for balances mock * Update test expectations * Update test expectations * Properly set max proof size for democracy mock * Properly set max proof size for scheduler mock * Properly set max proof size for fast unstake mock * Properly set max proof size for tx payment mock * Properly set max proof size for elections phragmen mock * Properly set max proof size for node template
This commit is contained in:
@@ -1011,10 +1011,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,
|
||||
);
|
||||
|
||||
@@ -2342,9 +2340,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;
|
||||
|
||||
@@ -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};
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
@@ -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.
|
||||
|
||||
@@ -638,8 +638,7 @@ impl<T: MinerConfig> Miner<T> {
|
||||
};
|
||||
|
||||
let next_voters = |current_weight: Weight, voters: u32, step: u32| -> Result<u32, ()> {
|
||||
// TODO: account for proof size weight
|
||||
if current_weight.ref_time() < max_weight.ref_time() {
|
||||
if current_weight.all_lt(max_weight) {
|
||||
let next_voters = voters.checked_add(step);
|
||||
match next_voters {
|
||||
Some(voters) if voters < max_voters => Ok(voters),
|
||||
@@ -674,8 +673,7 @@ impl<T: MinerConfig> Miner<T> {
|
||||
|
||||
// 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.
|
||||
// TODO: account for proof size weight
|
||||
while voters < max_voters && weight_with(voters + 1).ref_time() < max_weight.ref_time() {
|
||||
while voters < max_voters && weight_with(voters + 1).all_lt(max_weight) {
|
||||
voters += 1;
|
||||
}
|
||||
while voters.checked_sub(1).is_some() && weight_with(voters).any_gt(max_weight) {
|
||||
@@ -683,9 +681,8 @@ impl<T: MinerConfig> Miner<T> {
|
||||
}
|
||||
|
||||
let final_decision = voters.min(size.voters);
|
||||
// TODO: account for proof size weight
|
||||
debug_assert!(
|
||||
weight_with(final_decision).ref_time() <= max_weight.ref_time(),
|
||||
weight_with(final_decision).all_lte(max_weight),
|
||||
"weight_with({}) <= {}",
|
||||
final_decision,
|
||||
max_weight,
|
||||
@@ -703,151 +700,346 @@ 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::<Runtime>::maximum_voter_for_weight(0, w, Weight::zero()), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::zero().set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(999).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1990)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1990).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1999).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2000).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2001).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2010).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2990)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2990).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2999).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3000).set_proof_size(u64::MAX)
|
||||
),
|
||||
3
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3333).set_proof_size(u64::MAX)
|
||||
),
|
||||
3
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(5500)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(5500).set_proof_size(u64::MAX)
|
||||
),
|
||||
5
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(7777)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(7777).set_proof_size(u64::MAX)
|
||||
),
|
||||
7
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(9999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(9999).set_proof_size(u64::MAX)
|
||||
),
|
||||
9
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(10_000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(10_000).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(10_999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(10_999).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(11_000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(11_000).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(22_000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(22_000).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
|
||||
let w = SolutionOrSnapshotSize { voters: 1, targets: 0 };
|
||||
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(0)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(0).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(999).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1990)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1990).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1999).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2010).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3333).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
|
||||
let w = SolutionOrSnapshotSize { voters: 2, targets: 0 };
|
||||
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(0)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(0).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(999).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1999).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2000).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2001).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2010).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3333).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
@@ -1131,7 +1323,7 @@ mod tests {
|
||||
#[test]
|
||||
fn miner_trims_weight() {
|
||||
ExtBuilder::default()
|
||||
.miner_weight(Weight::from_ref_time(100))
|
||||
.miner_weight(Weight::from_ref_time(100).set_proof_size(u64::MAX))
|
||||
.mock_weight_info(crate::mock::MockedWeightInfo::Basic)
|
||||
.build_and_execute(|| {
|
||||
roll_to(25);
|
||||
@@ -1149,7 +1341,7 @@ mod tests {
|
||||
assert_eq!(raw.solution.voter_count(), 5);
|
||||
|
||||
// now reduce the max weight
|
||||
<MinerMaxWeight>::set(Weight::from_ref_time(25));
|
||||
<MinerMaxWeight>::set(Weight::from_ref_time(25).set_proof_size(u64::MAX));
|
||||
|
||||
let (raw, witness) = MultiPhase::mine_solution().unwrap();
|
||||
let solution_weight = <Runtime as MinerConfig>::solution_weight(
|
||||
|
||||
Reference in New Issue
Block a user