Adding benchmarking for new frame_election_provider_support (#11149)

* First stab at adding benchmarking for
`election-provider-support` onchain

* Adding `BoundedPhragMMS` and fixing stuff

* Fixing node runtime

* Fixing tests

* Finalising all benchmarking stuff

* better comments

* Better benchmarking config

* Better `WeightInfo` and benchmarking

* Fixing tests

* Adding some documentation

* Fixing some typos

* Incorporating review feedback

* cleanup of rustdocs

* rustdoc changes

* changes after code review

* Fixing some errors.

* Fixing dependencies post merge

* Bringing back `UnboundedExecution`

* Better rustdoc and naming

* Cargo.toml formatting
This commit is contained in:
Georges
2022-04-15 11:15:01 +01:00
committed by GitHub
parent 7dca0e467c
commit ae75a371bf
18 changed files with 365 additions and 54 deletions
@@ -170,7 +170,7 @@ pub mod onchain;
pub mod traits;
#[cfg(feature = "std")]
use codec::{Decode, Encode};
use frame_support::{BoundedVec, RuntimeDebug};
use frame_support::{weights::Weight, BoundedVec, RuntimeDebug};
use sp_runtime::traits::Bounded;
use sp_std::{fmt::Debug, prelude::*};
@@ -195,6 +195,9 @@ pub use sp_arithmetic;
#[doc(hidden)]
pub use sp_std;
pub mod weights;
pub use weights::WeightInfo;
#[cfg(test)]
mod mock;
#[cfg(test)]
@@ -523,6 +526,12 @@ pub trait NposSolver {
targets: Vec<Self::AccountId>,
voters: Vec<(Self::AccountId, VoteWeight, impl IntoIterator<Item = Self::AccountId>)>,
) -> Result<ElectionResult<Self::AccountId, Self::Accuracy>, Self::Error>;
/// Measure the weight used in the calculation of the solver.
/// - `voters` is the number of voters.
/// - `targets` is the number of targets.
/// - `vote_degree` is the degree ie the maximum numbers of votes per voter.
fn weight<T: WeightInfo>(voters: u32, targets: u32, vote_degree: u32) -> Weight;
}
/// A wrapper for [`sp_npos_elections::seq_phragmen`] that implements [`NposSolver`]. See the
@@ -547,6 +556,10 @@ impl<
) -> Result<ElectionResult<Self::AccountId, Self::Accuracy>, Self::Error> {
sp_npos_elections::seq_phragmen(winners, targets, voters, Balancing::get())
}
fn weight<T: WeightInfo>(voters: u32, targets: u32, vote_degree: u32) -> Weight {
T::phragmen(voters, targets, vote_degree)
}
}
/// A wrapper for [`sp_npos_elections::phragmms()`] that implements [`NposSolver`]. See the
@@ -571,6 +584,10 @@ impl<
) -> Result<ElectionResult<Self::AccountId, Self::Accuracy>, Self::Error> {
sp_npos_elections::phragmms(winners, targets, voters, Balancing::get())
}
fn weight<T: WeightInfo>(voters: u32, targets: u32, vote_degree: u32) -> Weight {
T::phragmms(voters, targets, vote_degree)
}
}
/// A voter, at the level of abstraction of this crate.