Move Staking Weights to T::WeightInfo (#7007)

* Fix the benchmarks

* Migrate staking to weightInfo

* Fix global benchmarks

* re-calculate the submit solution weight.

* Fix some refund.

* Get rid of all the extra parameters.

* Fix staking tests.

* new values from the bench machine.

* Fix some grumbles

* better macro

* Some better doc

* Move to interpreted wasm

* Make it work temporarily

* Final fix of default ones.

* Fix payout benchmarks

* Fix payout stuff

* One last fix

* use benchmarking machine for numbers

* update weight docs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Kian Paimani
2020-09-16 14:25:31 +02:00
committed by GitHub
parent 7a075a990f
commit 83bde4c1e6
8 changed files with 660 additions and 378 deletions
+53 -8
View File
@@ -3615,7 +3615,7 @@ mod offchain_election {
// A validator index which is out of bound
ExtBuilder::default()
.offchain_election_ext()
.validator_count(4)
.validator_count(2)
.has_stakers(false)
.build()
.execute_with(|| {
@@ -3627,7 +3627,7 @@ mod offchain_election {
let (mut compact, winners, score) = prepare_submission_with(true, 2, |_| {});
// index 4 doesn't exist.
compact.votes1.push((3, 4));
compact.votes1.iter_mut().for_each(|(_, vidx)| if *vidx == 1 { *vidx = 4 });
// The error type sadly cannot be more specific now.
assert_noop!(
@@ -3689,11 +3689,17 @@ mod offchain_election {
assert_eq!(Staking::snapshot_nominators().unwrap().len(), 5 + 4);
assert_eq!(Staking::snapshot_validators().unwrap().len(), 4);
let (compact, winners, score) = prepare_submission_with(true, 2, |a| {
a.iter_mut()
.find(|x| x.who == 5)
// all 3 cannot be among the winners. Although, all of them are validator
// candidates.
.map(|x| x.distribution = vec![(21, 50), (41, 30), (31, 20)]);
// swap all 11 and 41s in the distribution with non-winners. Note that it is
// important that the count of winners and the count of unique targets remain
// valid.
a.iter_mut().for_each(| StakedAssignment { who, distribution } |
distribution.iter_mut().for_each(|(t, _)| {
if *t == 41 { *t = 31 } else { *t = 21 }
// if it is self vote, correct that.
if *who == 41 { *who = 31 }
if *who == 11 { *who = 21 }
})
);
});
assert_noop!(
@@ -3703,7 +3709,46 @@ mod offchain_election {
compact,
score,
),
Error::<Test>::OffchainElectionBogusEdge,
Error::<Test>::OffchainElectionBogusNomination,
);
})
}
#[test]
fn offchain_election_unique_target_count_is_checked() {
// Number of unique targets and and winners.len must match.
ExtBuilder::default()
.offchain_election_ext()
.validator_count(2) // we select only 2.
.has_stakers(false)
.build()
.execute_with(|| {
build_offchain_election_test_ext();
run_to_block(12);
assert_eq!(Staking::snapshot_nominators().unwrap().len(), 5 + 4);
assert_eq!(Staking::snapshot_validators().unwrap().len(), 4);
let (compact, winners, score) = prepare_submission_with(true, 2, |a| {
a.iter_mut()
.find(|x| x.who == 5)
// just add any new target.
.map(|x| {
// old value.
assert_eq!(x.distribution, vec![(41, 100)]);
// new value.
x.distribution = vec![(21, 50), (41, 50)]
});
});
assert_noop!(
submit_solution(
Origin::signed(10),
winners,
compact,
score,
),
Error::<Test>::OffchainElectionBogusWinnerCount,
);
})
}