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:
Keith Yeung
2022-09-29 23:48:10 +08:00
committed by GitHub
parent 7bea0c0175
commit a4fb1d7096
22 changed files with 323 additions and 107 deletions
@@ -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(