Make election benchmarks more *memory-aware* (#9286)

* Make benchmarks a bit better with mem

* Make election benchmarks more *memory-aware*

* Fix a few errors

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Manually fix the weights

* Update lock file

* remove dupe

* Fix tests

* cargo update pwasm

Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
Kian Paimani
2021-07-09 21:55:31 +02:00
committed by GitHub
parent 9fc86cb55f
commit 3850a43323
11 changed files with 356 additions and 148 deletions
@@ -191,8 +191,8 @@
//! portion of the bond).
//!
//! **Conditionally open unsigned phase**: Currently, the unsigned phase is always opened. This is
//! useful because an honest validator will run substrate OCW code, which should be good enough to trump
//! a mediocre or malicious signed submission (assuming in the absence of honest signed bots).
//! useful because an honest validator will run substrate OCW code, which should be good enough to
//! trump a mediocre or malicious signed submission (assuming in the absence of honest signed bots).
//! If there are signed submissions, they can be checked against an absolute measure (e.g. PJR),
//! then we can only open the unsigned phase in extreme conditions (i.e. "no good signed solution
//! received") to spare some work for the active validators.
@@ -308,6 +308,12 @@ pub trait BenchmarkingConfig {
const ACTIVE_VOTERS: [u32; 2];
/// Range of desired targets.
const DESIRED_TARGETS: [u32; 2];
/// Maximum number of voters expected. This is used only for memory-benchmarking of snapshot.
const SNAPSHOT_MAXIMUM_VOTERS: u32;
/// Maximum number of voters expected. This is used only for memory-benchmarking of miner.
const MINER_MAXIMUM_VOTERS: u32;
/// Maximum number of targets expected. This is used only for memory-benchmarking.
const MAXIMUM_TARGETS: u32;
}
impl BenchmarkingConfig for () {
@@ -315,6 +321,9 @@ impl BenchmarkingConfig for () {
const TARGETS: [u32; 2] = [1000, 1600];
const ACTIVE_VOTERS: [u32; 2] = [1000, 3000];
const DESIRED_TARGETS: [u32; 2] = [400, 800];
const SNAPSHOT_MAXIMUM_VOTERS: u32 = 10_000;
const MINER_MAXIMUM_VOTERS: u32 = 10_000;
const MAXIMUM_TARGETS: u32 = 2_000;
}
/// Current phase of the pallet.
@@ -1063,7 +1072,7 @@ pub mod pallet {
let _ = Self::unsigned_pre_dispatch_checks(solution)
.map_err(|err| {
log!(error, "unsigned transaction validation failed due to {:?}", err);
log!(debug, "unsigned transaction validation failed due to {:?}", err);
err
})
.map_err(dispatch_error_to_invalid)?;
@@ -1201,8 +1210,9 @@ impl<T: Config> Pallet<T> {
/// Internal logic of the offchain worker, to be executed only when the offchain lock is
/// acquired with success.
fn do_synchronized_offchain_worker(now: T::BlockNumber) {
log!(trace, "lock for offchain worker acquired.");
match Self::current_phase() {
let current_phase = Self::current_phase();
log!(trace, "lock for offchain worker acquired. Phase = {:?}", current_phase);
match current_phase {
Phase::Unsigned((true, opened)) if opened == now => {
// Mine a new solution, cache it, and attempt to submit it
let initial_output = Self::ensure_offchain_repeat_frequency(now).and_then(|_| {
@@ -1453,11 +1463,20 @@ impl<T: Config> Pallet<T> {
.map_err(Into::into),
FallbackStrategy::Nothing => Err(ElectionError::NoFallbackConfigured),
},
|ReadySolution { supports, compute, .. }| Ok((
supports,
T::WeightInfo::elect_queued(),
compute
)),
|ReadySolution { supports, compute, .. }| {
// defensive-only: snapshot must always exist by this point.
let metadata = Self::snapshot_metadata().unwrap_or_default();
let desired = supports.len() as u32;
let active_voters = supports
.iter()
.map(|(_, x)| x)
.fold(Zero::zero(), |acc, next| acc + next.voters.len() as u32);
Ok((
supports,
T::WeightInfo::elect_queued(metadata.voters, metadata.targets, active_voters, desired),
compute
))
},
)
.map(|(supports, weight, compute)| {
Self::deposit_event(Event::ElectionFinalized(Some(compute)));