remove the uselsss weight return type from election provider API (#9569)

* remove the uselsss weight return type from election provider API

* fix everything, should be ready for final benchmark

* simplify on_init a bit furhter

* cargo run --quiet --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

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

* remove unwraps

* fmt

* Update lock file

* whitelist block weight

* cargo run --quiet --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

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

* fix warning

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
This commit is contained in:
Kian Paimani
2021-08-19 08:45:54 +01:00
committed by GitHub
parent 354b77fb88
commit 7a32c3504d
22 changed files with 552 additions and 556 deletions
@@ -80,7 +80,6 @@
//! ```rust
//! # use frame_election_provider_support::{*, data_provider};
//! # use sp_npos_elections::{Support, Assignment};
//! # use frame_support::weights::Weight;
//!
//! type AccountId = u64;
//! type Balance = u64;
@@ -101,16 +100,16 @@
//!
//! impl<T: Config> ElectionDataProvider<AccountId, BlockNumber> for Module<T> {
//! const MAXIMUM_VOTES_PER_VOTER: u32 = 1;
//! fn desired_targets() -> data_provider::Result<(u32, Weight)> {
//! Ok((1, 0))
//! fn desired_targets() -> data_provider::Result<u32> {
//! Ok(1)
//! }
//! fn voters(maybe_max_len: Option<usize>)
//! -> data_provider::Result<(Vec<(AccountId, VoteWeight, Vec<AccountId>)>, Weight)>
//! -> data_provider::Result<Vec<(AccountId, VoteWeight, Vec<AccountId>)>>
//! {
//! Ok((Default::default(), 0))
//! Ok(Default::default())
//! }
//! fn targets(maybe_max_len: Option<usize>) -> data_provider::Result<(Vec<AccountId>, Weight)> {
//! Ok((vec![10, 20, 30], 0))
//! fn targets(maybe_max_len: Option<usize>) -> data_provider::Result<Vec<AccountId>> {
//! Ok(vec![10, 20, 30])
//! }
//! fn next_election_prediction(now: BlockNumber) -> BlockNumber {
//! 0
@@ -132,12 +131,10 @@
//! type Error = &'static str;
//! type DataProvider = T::DataProvider;
//!
//! fn elect() -> Result<(Supports<AccountId>, Weight), Self::Error> {
//! fn elect() -> Result<Supports<AccountId>, Self::Error> {
//! Self::DataProvider::targets(None)
//! .map_err(|_| "failed to elect")
//! .map(|(t, weight)| {
//! (vec![(t[0], Support::default())], weight)
//! })
//! .map(|t| vec![(t[0], Support::default())])
//! }
//! }
//! }
@@ -164,7 +161,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
pub mod onchain;
use frame_support::weights::Weight;
use sp_std::{fmt::Debug, prelude::*};
/// Re-export some type as they are used in the interface.
@@ -189,9 +185,9 @@ pub trait ElectionDataProvider<AccountId, BlockNumber> {
/// If `maybe_max_len` is `Some(v)` then the resulting vector MUST NOT be longer than `v` items
/// long.
///
/// It is assumed that this function will only consume a notable amount of weight, when it
/// returns `Ok(_)`.
fn targets(maybe_max_len: Option<usize>) -> data_provider::Result<(Vec<AccountId>, Weight)>;
/// This should be implemented as a self-weighing function. The implementor should register its
/// appropriate weight at the end of execution with the system pallet directly.
fn targets(maybe_max_len: Option<usize>) -> data_provider::Result<Vec<AccountId>>;
/// All possible voters for the election.
///
@@ -200,14 +196,17 @@ pub trait ElectionDataProvider<AccountId, BlockNumber> {
/// If `maybe_max_len` is `Some(v)` then the resulting vector MUST NOT be longer than `v` items
/// long.
///
/// It is assumed that this function will only consume a notable amount of weight, when it
/// returns `Ok(_)`.
/// This should be implemented as a self-weighing function. The implementor should register its
/// appropriate weight at the end of execution with the system pallet directly.
fn voters(
maybe_max_len: Option<usize>,
) -> data_provider::Result<(Vec<(AccountId, VoteWeight, Vec<AccountId>)>, Weight)>;
) -> data_provider::Result<Vec<(AccountId, VoteWeight, Vec<AccountId>)>>;
/// The number of targets to elect.
fn desired_targets() -> data_provider::Result<(u32, Weight)>;
///
/// This should be implemented as a self-weighing function. The implementor should register its
/// appropriate weight at the end of execution with the system pallet directly.
fn desired_targets() -> data_provider::Result<u32>;
/// Provide a best effort prediction about when the next election is about to happen.
///
@@ -249,15 +248,15 @@ pub trait ElectionDataProvider<AccountId, BlockNumber> {
#[cfg(feature = "std")]
impl<AccountId, BlockNumber> ElectionDataProvider<AccountId, BlockNumber> for () {
const MAXIMUM_VOTES_PER_VOTER: u32 = 0;
fn targets(_maybe_max_len: Option<usize>) -> data_provider::Result<(Vec<AccountId>, Weight)> {
fn targets(_maybe_max_len: Option<usize>) -> data_provider::Result<Vec<AccountId>> {
Ok(Default::default())
}
fn voters(
_maybe_max_len: Option<usize>,
) -> data_provider::Result<(Vec<(AccountId, VoteWeight, Vec<AccountId>)>, Weight)> {
) -> data_provider::Result<Vec<(AccountId, VoteWeight, Vec<AccountId>)>> {
Ok(Default::default())
}
fn desired_targets() -> data_provider::Result<(u32, Weight)> {
fn desired_targets() -> data_provider::Result<u32> {
Ok(Default::default())
}
fn next_election_prediction(now: BlockNumber) -> BlockNumber {
@@ -280,7 +279,10 @@ pub trait ElectionProvider<AccountId, BlockNumber> {
/// Elect a new set of winners.
///
/// The result is returned in a target major format, namely as vector of supports.
fn elect() -> Result<(Supports<AccountId>, Weight), Self::Error>;
///
/// This should be implemented as a self-weighing function. The implementor should register its
/// appropriate weight at the end of execution with the system pallet directly.
fn elect() -> Result<Supports<AccountId>, Self::Error>;
}
#[cfg(feature = "std")]
@@ -288,7 +290,7 @@ impl<AccountId, BlockNumber> ElectionProvider<AccountId, BlockNumber> for () {
type Error = &'static str;
type DataProvider = ();
fn elect() -> Result<(Supports<AccountId>, Weight), Self::Error> {
fn elect() -> Result<Supports<AccountId>, Self::Error> {
Err("<() as ElectionProvider> cannot do anything.")
}
}