-
Notifications
You must be signed in to change notification settings - Fork 2.6k
remove the uselsss weight return type from election provider API #9569
Changes from 6 commits
1873a7a
bda35d5
101b5e8
b71433c
87c2416
5707bce
56796ac
293c076
e6eb8b0
924b884
d3f4cc5
ca0568b
1ce23e6
731c4b2
1dfaee2
faa09b5
779bb5f
c1962c8
e5a0e12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,8 +151,6 @@ fn solution_with_size<T: Config>( | |
} | ||
|
||
fn set_up_data_provider<T: Config>(v: u32, t: u32) { | ||
// number of votes in snapshot. | ||
|
||
T::DataProvider::clear(); | ||
log!( | ||
info, | ||
|
@@ -192,37 +190,22 @@ frame_benchmarking::benchmarks! { | |
} | ||
|
||
on_initialize_open_signed { | ||
// NOTE: this benchmark currently doesn't have any components because the length of a db | ||
// read/write is not captured. Otherwise, it is quite influenced by how much data | ||
// `T::ElectionDataProvider` is reading and passing on. | ||
assert!(<MultiPhase<T>>::snapshot().is_none()); | ||
assert!(<MultiPhase<T>>::current_phase().is_off()); | ||
}: { | ||
<MultiPhase<T>>::on_initialize_open_signed().unwrap(); | ||
<MultiPhase<T>>::on_initialize_open_signed(); | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} verify { | ||
assert!(<MultiPhase<T>>::snapshot().is_some()); | ||
assert!(<MultiPhase<T>>::snapshot().is_none()); | ||
assert!(<MultiPhase<T>>::current_phase().is_signed()); | ||
} | ||
|
||
on_initialize_open_unsigned_with_snapshot { | ||
on_initialize_open_unsigned { | ||
assert!(<MultiPhase<T>>::snapshot().is_none()); | ||
assert!(<MultiPhase<T>>::current_phase().is_off()); | ||
}: { | ||
<MultiPhase<T>>::on_initialize_open_unsigned(true, true, 1u32.into()).unwrap(); | ||
} verify { | ||
assert!(<MultiPhase<T>>::snapshot().is_some()); | ||
assert!(<MultiPhase<T>>::current_phase().is_unsigned()); | ||
} | ||
|
||
on_initialize_open_unsigned_without_snapshot { | ||
// need to assume signed phase was open before | ||
<MultiPhase<T>>::on_initialize_open_signed().unwrap(); | ||
assert!(<MultiPhase<T>>::snapshot().is_some()); | ||
assert!(<MultiPhase<T>>::current_phase().is_signed()); | ||
}: { | ||
<MultiPhase<T>>::on_initialize_open_unsigned(false, true, 1u32.into()).unwrap(); | ||
<MultiPhase<T>>::on_initialize_open_unsigned(true, 1u32.into()) | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} verify { | ||
assert!(<MultiPhase<T>>::snapshot().is_some()); | ||
assert!(<MultiPhase<T>>::snapshot().is_none()); | ||
assert!(<MultiPhase<T>>::current_phase().is_unsigned()); | ||
} | ||
|
||
|
@@ -259,30 +242,51 @@ frame_benchmarking::benchmarks! { | |
assert_eq!(T::Currency::reserved_balance(&receiver), 0u32.into()); | ||
} | ||
|
||
create_snapshot_internal { | ||
// number of votes in snapshot. Fixed to maximum. | ||
let v = T::BenchmarkingConfig::SNAPSHOT_MAXIMUM_VOTERS; | ||
// number of targets in snapshot. Fixed to maximum. | ||
let t = T::BenchmarkingConfig::MAXIMUM_TARGETS; | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// we don't directly need the data-provider to be populated, but it is just easy to use it. | ||
set_up_data_provider::<T>(v, t); | ||
let targets = T::DataProvider::targets(None).unwrap(); | ||
let voters = T::DataProvider::voters(None).unwrap(); | ||
let desired_targets = T::DataProvider::desired_targets().unwrap(); | ||
assert!(<MultiPhase<T>>::snapshot().is_none()); | ||
}: { | ||
<MultiPhase::<T>>::create_snapshot_internal(targets, voters, desired_targets) | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} verify { | ||
assert!(<MultiPhase<T>>::snapshot().is_some()); | ||
assert_eq!(<MultiPhase<T>>::snapshot_metadata().unwrap().voters, v + t); | ||
assert_eq!(<MultiPhase<T>>::snapshot_metadata().unwrap().targets, t); | ||
} | ||
|
||
// a call to `<Pallet as ElectionProvider>::elect` where we only return the queued solution. | ||
elect_queued { | ||
// number of votes in snapshot. | ||
let v in (T::BenchmarkingConfig::VOTERS[0]) .. T::BenchmarkingConfig::VOTERS[1]; | ||
// number of targets in snapshot. | ||
let t in (T::BenchmarkingConfig::TARGETS[0]) .. T::BenchmarkingConfig::TARGETS[1]; | ||
// number of assignments, i.e. solution.len(). This means the active nominators, thus must be | ||
// a subset of `v` component. | ||
// a subset of `v`. | ||
let a in (T::BenchmarkingConfig::ACTIVE_VOTERS[0]) .. T::BenchmarkingConfig::ACTIVE_VOTERS[1]; | ||
// number of desired targets. Must be a subset of `t` component. | ||
// number of desired targets. Must be a subset of `t`. | ||
let d in (T::BenchmarkingConfig::DESIRED_TARGETS[0]) .. T::BenchmarkingConfig::DESIRED_TARGETS[1]; | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// number of votes in snapshot. Not dominant. | ||
let v = T::BenchmarkingConfig::VOTERS[1]; | ||
// number of targets in snapshot. Not dominant. | ||
let t = T::BenchmarkingConfig::TARGETS[1]; | ||
|
||
let witness = SolutionOrSnapshotSize { voters: v, targets: t }; | ||
let raw_solution = solution_with_size::<T>(witness, a, d)?; | ||
let ready_solution = | ||
<MultiPhase<T>>::feasibility_check(raw_solution, ElectionCompute::Signed).unwrap(); | ||
<CurrentPhase<T>>::put(Phase::Signed); | ||
// assume a queued solution is stored, regardless of where it comes from. | ||
<QueuedSolution<T>>::put(ready_solution); | ||
|
||
// these are set by the `solution_with_size` function. | ||
assert!(<DesiredTargets<T>>::get().is_some()); | ||
assert!(<Snapshot<T>>::get().is_some()); | ||
assert!(<SnapshotMetadata<T>>::get().is_some()); | ||
<CurrentPhase<T>>::put(Phase::Signed); | ||
// assume a queued solution is stored, regardless of where it comes from. | ||
<QueuedSolution<T>>::put(ready_solution); | ||
}: { | ||
assert_ok!(<MultiPhase<T> as ElectionProvider<T::AccountId, T::BlockNumber>>::elect()); | ||
} verify { | ||
|
@@ -303,7 +307,8 @@ frame_benchmarking::benchmarks! { | |
..Default::default() | ||
}; | ||
|
||
MultiPhase::<T>::on_initialize_open_signed().expect("should be ok to start signed phase"); | ||
<MultiPhase<T>>::create_snapshot().unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not have all these unwraps be a little more descriptive about what went wrong? either with an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless if the
I will look into the second option, though my opinion is still that unwrap is fine in benchmark setup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the help of |
||
MultiPhase::<T>::on_initialize_open_signed(); | ||
<Round<T>>::put(1); | ||
|
||
let mut signed_submissions = SignedSubmissions::<T>::get(); | ||
|
@@ -407,7 +412,6 @@ frame_benchmarking::benchmarks! { | |
// number of targets in snapshot. Fixed to maximum. | ||
let t = T::BenchmarkingConfig::MAXIMUM_TARGETS; | ||
|
||
T::DataProvider::clear(); | ||
set_up_data_provider::<T>(v, t); | ||
let now = frame_system::Pallet::<T>::block_number(); | ||
<CurrentPhase<T>>::put(Phase::Unsigned((true, now))); | ||
|
@@ -430,7 +434,6 @@ frame_benchmarking::benchmarks! { | |
// number of targets in snapshot. Fixed to maximum. | ||
let t = T::BenchmarkingConfig::MAXIMUM_TARGETS; | ||
|
||
T::DataProvider::clear(); | ||
set_up_data_provider::<T>(v, t); | ||
assert!(<MultiPhase<T>>::snapshot().is_none()); | ||
}: { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this note is still relevant?
Could update benchmarks in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the past this benchmark created the snapshot as well, and therefore it was a function of the byte length. Now, it is not doing that anymore, therefore byte length is irrelevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that the removal of these comments seem like mistakes, but they are (hopefully) exactly all signs of reduction of complexity: we no longer need to care about these details in this pallet. Whoever is the implementer of
T::DataProvider
will record its own appropriate weight.