From b714023c939cbbfaf329ad03d607fcbf188dbfd3 Mon Sep 17 00:00:00 2001 From: gpestana Date: Mon, 31 Oct 2022 08:14:56 +0100 Subject: [PATCH 01/34] Abstracts elections-phragmen pallet to use NposSolver --- Cargo.lock | 1 + frame/elections-phragmen/Cargo.toml | 1 + frame/elections-phragmen/src/lib.rs | 123 +++++++++++++++++----------- 3 files changed, 75 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b87f45508dfc9..ab62039eae66c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5487,6 +5487,7 @@ name = "pallet-elections-phragmen" version = "5.0.0-dev" dependencies = [ "frame-benchmarking", + "frame-election-provider-support", "frame-support", "frame-system", "log", diff --git a/frame/elections-phragmen/Cargo.toml b/frame/elections-phragmen/Cargo.toml index 2d71a6bed39df..7851483c0c232 100644 --- a/frame/elections-phragmen/Cargo.toml +++ b/frame/elections-phragmen/Cargo.toml @@ -24,6 +24,7 @@ frame-system = { version = "4.0.0-dev", default-features = false, path = "../sys sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } sp-npos-elections = { version = "4.0.0-dev", default-features = false, path = "../../primitives/npos-elections" } +frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" } sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" } diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 165a8fcab429b..e6c726698e87f 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! # Phragmén Election Module. +//! # Generic Election Module. //! -//! An election module based on sequential phragmen. +//! An election module based on a generic election algorithm. //! //! ### Term and Round //! @@ -99,6 +99,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use codec::{Decode, Encode}; +use frame_election_provider_support::NposSolver; use frame_support::{ traits::{ defensive_prelude::*, ChangeMembers, Contains, ContainsLengthBound, Currency, @@ -111,7 +112,7 @@ use scale_info::TypeInfo; use sp_npos_elections::{ElectionResult, ExtendedBalance}; use sp_runtime::{ traits::{Saturating, StaticLookup, Zero}, - DispatchError, Perbill, RuntimeDebug, + DispatchError, RuntimeDebug, }; use sp_std::{cmp::Ordering, prelude::*}; @@ -197,7 +198,7 @@ pub mod pallet { pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// Identifier for the elections-phragmen pallet's lock + /// Identifier for the elections pallet's lock #[pallet::constant] type PalletId: Get; @@ -250,7 +251,7 @@ pub mod pallet { #[pallet::constant] type TermDuration: Get; - /// The maximum number of candidates in a phragmen election. + /// The maximum number of candidates in an election. /// /// Warning: The election happens onchain, and this value will determine /// the size of the election. When this limit is reached no more @@ -258,13 +259,19 @@ pub mod pallet { #[pallet::constant] type MaxCandidates: Get; - /// The maximum number of voters to allow in a phragmen election. + /// The maximum number of voters to allow in an election. /// /// Warning: This impacts the size of the election which is run onchain. /// When the limit is reached the new voters are ignored. #[pallet::constant] type MaxVoters: Get; + /// Something that will calculate the result of elections. + type ElectionSolver: NposSolver; + + /// Weight information for the `ElectionSolver`. + type SolverWeightInfo: frame_election_provider_support::WeightInfo; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } @@ -277,7 +284,7 @@ pub mod pallet { fn on_initialize(n: T::BlockNumber) -> Weight { let term_duration = T::TermDuration::get(); if !term_duration.is_zero() && (n % term_duration).is_zero() { - Self::do_phragmen() + Self::do_election() } else { Weight::zero() } @@ -486,8 +493,8 @@ pub mod pallet { /// the outgoing member is slashed. /// /// If a runner-up is available, then the best runner-up will be removed and replaces the - /// outgoing member. Otherwise, if `rerun_election` is `true`, a new phragmen election is - /// started, else, nothing happens. + /// outgoing member. Otherwise, if `rerun_election` is `true`, a new election is started, + /// else, nothing happens. /// /// If `slash_bond` is set to true, the bond of the member being removed is slashed. Else, /// it is returned. @@ -498,7 +505,7 @@ pub mod pallet { /// /// # /// If we have a replacement, we use a small weight. Else, since this is a root call and - /// will go into phragmen, we assume full block for now. + /// will go into the `NposSolver` election, we assume full block for now. /// # #[pallet::weight(if *rerun_election { T::WeightInfo::remove_member_without_replacement() @@ -518,7 +525,7 @@ pub mod pallet { Self::deposit_event(Event::MemberKicked { member: who }); if rerun_election { - Self::do_phragmen(); + Self::do_election(); } // no refund needed. @@ -695,7 +702,7 @@ pub mod pallet { Members::::mutate(|members| { match members.binary_search_by(|m| m.who.cmp(member)) { Ok(_) => { - panic!("Duplicate member in elections-phragmen genesis: {}", member) + panic!("Duplicate member in elections genesis: {}", member) }, Err(pos) => members.insert( pos, @@ -784,7 +791,7 @@ impl Pallet { // overlap. This can never happen. If so, it seems like our intended replacement // is already a member, so not much more to do. log::error!( - target: "runtime::elections-phragmen", + target: "runtime::elections", "A member seems to also be a runner-up.", ); } @@ -890,11 +897,12 @@ impl Pallet { debug_assert!(_remainder.is_zero()); } - /// Run the phragmen election with all required side processes and state updates, if election - /// succeeds. Else, it will emit an `ElectionError` event. + /// Run an election with all required side processes and state updates, if election + /// succeeds. Else, it will emit an `ElectionError` event. The election algorithm is defined + /// by the implementor of `Self::NposSolver`. /// /// Calls the appropriate [`ChangeMembers`] function variant internally. - fn do_phragmen() -> Weight { + fn do_election() -> Weight { let desired_seats = T::DesiredMembers::get() as usize; let desired_runners_up = T::DesiredRunnersUp::get() as usize; let num_to_elect = desired_runners_up + desired_seats; @@ -908,7 +916,7 @@ impl Pallet { return T::DbWeight::get().reads(3) } - // All of the new winners that come out of phragmen will thus have a deposit recorded. + // All of the new winners that come out of the election will thus have a deposit recorded. let candidate_ids = candidates_and_deposit.iter().map(|(x, _)| x).cloned().collect::>(); @@ -933,7 +941,7 @@ impl Pallet { Ok(_) => (), Err(_) => { log::error!( - target: "runtime::elections-phragmen", + target: "runtime::elections", "Failed to run election. Number of voters exceeded", ); Self::deposit_event(Event::ElectionError); @@ -941,7 +949,7 @@ impl Pallet { }, } - // used for phragmen. + // used for elections. let voters_and_votes = voters_and_stakes .iter() .cloned() @@ -951,12 +959,14 @@ impl Pallet { }) .collect::>(); - let weight_candidates = candidates_and_deposit.len() as u32; - let weight_voters = voters_and_votes.len() as u32; - let weight_edges = num_edges; - let _ = - sp_npos_elections::seq_phragmen(num_to_elect, candidate_ids, voters_and_votes, None) - .map(|ElectionResult:: { winners, assignments: _ }| { + let num_candidates = candidates_and_deposit.len() as u32; + let num_voters = voters_and_votes.len() as u32; + let _ = T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) + .map( + |ElectionResult::::Accuracy> { + winners, + assignments: _, + }| { // this is already sorted by id. let old_members_ids_sorted = >::take() .into_iter() @@ -1059,7 +1069,7 @@ impl Pallet { // write final values to storage. let deposit_of_candidate = |x: &T::AccountId| -> BalanceOf { // defensive-only. This closure is used against the new members and new - // runners-up, both of which are phragmen winners and thus must have + // runners-up, both of which are election winners and thus must have // deposit. candidates_and_deposit .iter() @@ -1095,17 +1105,18 @@ impl Pallet { Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id }); >::mutate(|v| *v += 1); - }) - .map_err(|e| { - log::error!( - target: "runtime::elections-phragmen", - "Failed to run election [{:?}].", - e, - ); - Self::deposit_event(Event::ElectionError); - }); + }, + ) + .map_err(|e| { + log::error!( + target: "runtime::elections", + "Failed to run election [{:?}].", + e, + ); + Self::deposit_event(Event::ElectionError); + }); - T::WeightInfo::election_phragmen(weight_candidates, weight_voters, weight_edges) + T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) } } @@ -1156,7 +1167,8 @@ impl ContainsLengthBound for Pallet { #[cfg(test)] mod tests { use super::*; - use crate as elections_phragmen; + use crate as elections; + use frame_election_provider_support::SequentialPhragmen; use frame_support::{ assert_noop, assert_ok, dispatch::DispatchResultWithPostInfo, @@ -1168,7 +1180,7 @@ mod tests { use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, + BuildStorage, Perbill, }; use substrate_test_utils::assert_eq_uvec; @@ -1274,13 +1286,13 @@ mod tests { } parameter_types! { - pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; - pub const PhragmenMaxVoters: u32 = 1000; - pub const PhragmenMaxCandidates: u32 = 100; + pub const ElectionsPalletId: LockIdentifier = *b"elects__"; + pub const MaxVoters: u32 = 1000; + pub const MaxCandidates: u32 = 100; } impl Config for Test { - type PalletId = ElectionsPhragmenPalletId; + type PalletId = ElectionsPalletId; type RuntimeEvent = RuntimeEvent; type Currency = Balances; type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; @@ -1295,8 +1307,21 @@ mod tests { type LoserCandidate = (); type KickedMember = (); type WeightInfo = (); - type MaxVoters = PhragmenMaxVoters; - type MaxCandidates = PhragmenMaxCandidates; + type MaxVoters = MaxVoters; + type MaxCandidates = MaxCandidates; + type ElectionSolver = SequentialPhragmen; + type SolverWeightInfo = NposWeightInfo; + } + + pub struct NposWeightInfo; + impl frame_election_provider_support::WeightInfo for NposWeightInfo { + fn phragmen(_v: u32, _t: u32, _d: u32) -> Weight { + Weight::zero() + } + + fn phragmms(_v: u32, _t: u32, _d: u32) -> Weight { + Weight::zero() + } } pub type Block = sp_runtime::generic::Block; @@ -1311,7 +1336,7 @@ mod tests { { System: frame_system::{Pallet, Call, Event}, Balances: pallet_balances::{Pallet, Call, Event, Config}, - Elections: elections_phragmen::{Pallet, Call, Event, Config}, + Elections: elections::{Pallet, Call, Event, Config}, } ); @@ -1372,9 +1397,7 @@ mod tests { (6, 60 * self.balance_factor), ], }, - elections: elections_phragmen::GenesisConfig:: { - members: self.genesis_members, - }, + elections: elections::GenesisConfig:: { members: self.genesis_members }, } .build_storage() .unwrap() @@ -1432,7 +1455,7 @@ mod tests { .get(0) .cloned() .map(|lock| { - assert_eq!(lock.id, ElectionsPhragmenPalletId::get()); + assert_eq!(lock.id, ElectionsPalletId::get()); lock.amount }) .unwrap_or_default() @@ -1623,7 +1646,7 @@ mod tests { } #[test] - #[should_panic = "Duplicate member in elections-phragmen genesis: 2"] + #[should_panic = "Duplicate member in elections genesis: 2"] fn genesis_members_cannot_be_duplicate() { ExtBuilder::default() .desired_members(3) From 452292f7a36db967216e4396560e0a2fc540059a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Tue, 8 Nov 2022 23:17:22 +0100 Subject: [PATCH 02/34] Update frame/elections-phragmen/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/elections-phragmen/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index e6c726698e87f..f5e128e55a2a6 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -269,7 +269,7 @@ pub mod pallet { /// Something that will calculate the result of elections. type ElectionSolver: NposSolver; - /// Weight information for the `ElectionSolver`. + /// Weight information for the [`Config::ElectionSolver`]. type SolverWeightInfo: frame_election_provider_support::WeightInfo; /// Weight information for extrinsics in this pallet. From bf8d1c27ac765199cb1db20d9f097ebab6c1bff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Tue, 8 Nov 2022 23:17:39 +0100 Subject: [PATCH 03/34] Update frame/elections-phragmen/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/elections-phragmen/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index f5e128e55a2a6..732b33c37a3fd 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -899,7 +899,7 @@ impl Pallet { /// Run an election with all required side processes and state updates, if election /// succeeds. Else, it will emit an `ElectionError` event. The election algorithm is defined - /// by the implementor of `Self::NposSolver`. + /// by the implementor of `Self::ElectionSolver`. /// /// Calls the appropriate [`ChangeMembers`] function variant internally. fn do_election() -> Weight { From 5fa443efa39a0cbeecabb115f782fb5fef122acd Mon Sep 17 00:00:00 2001 From: gpestana Date: Wed, 9 Nov 2022 00:01:03 +0100 Subject: [PATCH 04/34] changes the name of the pallet; adds changelog --- Cargo.lock | 6 +++--- bin/node/runtime/Cargo.toml | 8 ++++---- frame/elections-phragmen/CHANGELOG.md | 11 +++++++++++ frame/elections-phragmen/Cargo.toml | 4 ++-- frame/elections-phragmen/README.md | 6 +++--- utils/frame/remote-externalities/Cargo.toml | 2 +- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab62039eae66c..36d3247a60dea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3390,7 +3390,7 @@ dependencies = [ "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", - "pallet-elections-phragmen", + "pallet-elections", "pallet-fast-unstake", "pallet-gilt", "pallet-grandpa", @@ -5483,7 +5483,7 @@ dependencies = [ ] [[package]] -name = "pallet-elections-phragmen" +name = "pallet-elections" version = "5.0.0-dev" dependencies = [ "frame-benchmarking", @@ -7336,7 +7336,7 @@ dependencies = [ "env_logger", "frame-support", "log", - "pallet-elections-phragmen", + "pallet-elections", "parity-scale-codec", "serde", "serde_json", diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 39364961d57e2..1bc0c0756cf2d 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -66,7 +66,7 @@ pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, pa pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" } pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" } pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true } -pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" } +pallet-elections = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" } pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" } pallet-gilt = { version = "4.0.0-dev", default-features = false, path = "../../../frame/gilt" } pallet-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../frame/grandpa" } @@ -140,7 +140,7 @@ std = [ "pallet-contracts-primitives/std", "pallet-conviction-voting/std", "pallet-democracy/std", - "pallet-elections-phragmen/std", + "pallet-elections/std", "pallet-fast-unstake/std", "frame-executive/std", "pallet-gilt/std", @@ -219,7 +219,7 @@ runtime-benchmarks = [ "pallet-democracy/runtime-benchmarks", "pallet-election-provider-multi-phase/runtime-benchmarks", "pallet-election-provider-support-benchmarking/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", + "pallet-elections/runtime-benchmarks", "pallet-fast-unstake/runtime-benchmarks", "pallet-gilt/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", @@ -272,7 +272,7 @@ try-runtime = [ "pallet-conviction-voting/try-runtime", "pallet-democracy/try-runtime", "pallet-election-provider-multi-phase/try-runtime", - "pallet-elections-phragmen/try-runtime", + "pallet-elections/try-runtime", "pallet-fast-unstake/try-runtime", "pallet-gilt/try-runtime", "pallet-grandpa/try-runtime", diff --git a/frame/elections-phragmen/CHANGELOG.md b/frame/elections-phragmen/CHANGELOG.md index 231de1d2e475e..5d7b1a5c53ad9 100644 --- a/frame/elections-phragmen/CHANGELOG.md +++ b/frame/elections-phragmen/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this crate will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this crate adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [5.0.0] - UNRELEASED + +### Added + +### Changed +\[**Needs Migration**\] Generalized the pallet to use `NposSolver` instead of hard coding the phragmen algorithm; Changed the name of the pallet to `pallet-elections`. + +### Fixed + +### Security + ## [4.0.0] - UNRELEASED ### Added diff --git a/frame/elections-phragmen/Cargo.toml b/frame/elections-phragmen/Cargo.toml index 7851483c0c232..a5bba64b9faf3 100644 --- a/frame/elections-phragmen/Cargo.toml +++ b/frame/elections-phragmen/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "pallet-elections-phragmen" +name = "pallet-elections" version = "5.0.0-dev" authors = ["Parity Technologies "] edition = "2021" license = "Apache-2.0" homepage = "https://substrate.io" repository = "https://github.com/paritytech/substrate/" -description = "FRAME pallet based on seq-Phragmén election method." +description = "FRAME pallet for generic elections." readme = "README.md" [package.metadata.docs.rs] diff --git a/frame/elections-phragmen/README.md b/frame/elections-phragmen/README.md index 26b3f260da563..0f27bdd189110 100644 --- a/frame/elections-phragmen/README.md +++ b/frame/elections-phragmen/README.md @@ -1,6 +1,6 @@ -# Phragmén Election Module. +# Generic Elections Module. -An election module based on sequential phragmen. +A generic elections module. ### Term and Round @@ -60,7 +60,7 @@ being re-elected at the end of each round. ### Module Information -- [`election_sp_phragmen::Config`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/trait.Config.html) +- [`elections::Config`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/trait.Config.html) - [`Call`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/enum.Call.html) - [`Module`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/struct.Module.html) diff --git a/utils/frame/remote-externalities/Cargo.toml b/utils/frame/remote-externalities/Cargo.toml index 3d7471bf4d680..d70d1f1a2b7ac 100644 --- a/utils/frame/remote-externalities/Cargo.toml +++ b/utils/frame/remote-externalities/Cargo.toml @@ -28,7 +28,7 @@ substrate-rpc-client = { path = "../rpc/client" } [dev-dependencies] tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] } frame-support = { version = "4.0.0-dev", path = "../../../frame/support" } -pallet-elections-phragmen = { version = "5.0.0-dev", path = "../../../frame/elections-phragmen" } +pallet-elections = { version = "5.0.0-dev", path = "../../../frame/elections-phragmen" } [features] remote-test = ["frame-support"] From f71c095df12ec86192afcd95eda4fc457f2a938e Mon Sep 17 00:00:00 2001 From: gpestana Date: Wed, 9 Nov 2022 00:04:36 +0100 Subject: [PATCH 05/34] update changelog --- frame/elections-phragmen/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/elections-phragmen/CHANGELOG.md b/frame/elections-phragmen/CHANGELOG.md index 5d7b1a5c53ad9..bc21e888ab83a 100644 --- a/frame/elections-phragmen/CHANGELOG.md +++ b/frame/elections-phragmen/CHANGELOG.md @@ -9,7 +9,7 @@ and this crate adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h ### Added ### Changed -\[**Needs Migration**\] Generalized the pallet to use `NposSolver` instead of hard coding the phragmen algorithm; Changed the name of the pallet to `pallet-elections`. +\[**Needs Migration**\] Generalized the pallet to use `NposSolver` instead of hard coding the phragmen algorithm; Changed the name of the pallet to `pallet-elections` and the pallet's lock ID. ### Fixed From e37206c731a43378257c9bf6ef10f7661dac71ec Mon Sep 17 00:00:00 2001 From: gpestana Date: Wed, 9 Nov 2022 08:58:17 +0100 Subject: [PATCH 06/34] Adds weight testing --- frame/elections-phragmen/src/lib.rs | 39 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 732b33c37a3fd..f7b42eb00fa76 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -502,11 +502,6 @@ pub mod pallet { /// The dispatch origin of this call must be root. /// /// Note that this does not affect the designated block number of the next election. - /// - /// # - /// If we have a replacement, we use a small weight. Else, since this is a root call and - /// will go into the `NposSolver` election, we assume full block for now. - /// # #[pallet::weight(if *rerun_election { T::WeightInfo::remove_member_without_replacement() } else { @@ -1168,7 +1163,7 @@ impl ContainsLengthBound for Pallet { mod tests { use super::*; use crate as elections; - use frame_election_provider_support::SequentialPhragmen; + use frame_election_provider_support::{weights::SubstrateWeight, SequentialPhragmen}; use frame_support::{ assert_noop, assert_ok, dispatch::DispatchResultWithPostInfo, @@ -1310,18 +1305,7 @@ mod tests { type MaxVoters = MaxVoters; type MaxCandidates = MaxCandidates; type ElectionSolver = SequentialPhragmen; - type SolverWeightInfo = NposWeightInfo; - } - - pub struct NposWeightInfo; - impl frame_election_provider_support::WeightInfo for NposWeightInfo { - fn phragmen(_v: u32, _t: u32, _d: u32) -> Weight { - Weight::zero() - } - - fn phragmms(_v: u32, _t: u32, _d: u32) -> Weight { - Weight::zero() - } + type SolverWeightInfo = SubstrateWeight; } pub type Block = sp_runtime::generic::Block; @@ -3241,4 +3225,23 @@ mod tests { assert_ok!(Elections::clean_defunct_voters(RuntimeOrigin::root(), 4, 2)); }) } + + #[test] + fn verify_weights() { + ExtBuilder::default().build_and_execute(|| { + assert_eq!(Elections::on_initialize(System::block_number()), Weight::zero()); + + assert_ok!(submit_candidacy(RuntimeOrigin::signed(4))); + assert_ok!(submit_candidacy(RuntimeOrigin::signed(5))); + assert_ok!(vote(RuntimeOrigin::signed(4), vec![4], 40)); + assert_ok!(vote(RuntimeOrigin::signed(5), vec![5], 50)); + + System::set_block_number(5); + + let election_weight = Elections::on_initialize(System::block_number()); + let expected_weight: Weight = <() as WeightInfo>::election_phragmen(2, 2, 2); + + assert_eq!(expected_weight, election_weight); + }) + } } From f7e970db1b3e0b00247d4697b85e2d7be055751d Mon Sep 17 00:00:00 2001 From: gpestana Date: Wed, 9 Nov 2022 13:17:53 +0100 Subject: [PATCH 07/34] Adds log macro_rules --- frame/elections-phragmen/src/lib.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index f7b42eb00fa76..2013176dc2ebd 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -126,6 +126,19 @@ pub mod migrations; /// The maximum votes allowed per voter. pub const MAXIMUM_VOTE: usize = 16; +pub(crate) const LOG_TARGET: &str = "runtime::elections"; + +// logging helper. +#[macro_export] +macro_rules! log { + ($level:tt, $patter:expr $(, $values:expr)* $(,)?) => { + log::$level!( + target: crate::LOG_TARGET, + concat!("[{:?}] 🗳️ ", $patter), >::block_number() $(, $values)* + ) + }; +} + type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; type NegativeImbalanceOf = <::Currency as Currency< @@ -785,10 +798,7 @@ impl Pallet { } else { // overlap. This can never happen. If so, it seems like our intended replacement // is already a member, so not much more to do. - log::error!( - target: "runtime::elections", - "A member seems to also be a runner-up.", - ); + log!(warn, "A member seems to also be a runner-up."); } next_best }); @@ -1098,16 +1108,13 @@ impl Pallet { // clean candidates. >::kill(); + log!(info, "New term election successful."); Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id }); >::mutate(|v| *v += 1); }, ) .map_err(|e| { - log::error!( - target: "runtime::elections", - "Failed to run election [{:?}].", - e, - ); + log!(warn, "Failed to run election [{:?}].", e); Self::deposit_event(Event::ElectionError); }); From 7b86c86f261fb1550801ea01074534f2314f4325 Mon Sep 17 00:00:00 2001 From: gpestana Date: Wed, 9 Nov 2022 13:23:46 +0100 Subject: [PATCH 08/34] renames elections-phragment dir to elections --- bin/node/runtime/Cargo.toml | 2 +- frame/{elections-phragmen => elections}/CHANGELOG.md | 0 frame/{elections-phragmen => elections}/Cargo.toml | 0 frame/{elections-phragmen => elections}/README.md | 0 frame/{elections-phragmen => elections}/src/benchmarking.rs | 0 frame/{elections-phragmen => elections}/src/lib.rs | 0 frame/{elections-phragmen => elections}/src/migrations/mod.rs | 0 frame/{elections-phragmen => elections}/src/migrations/v3.rs | 0 frame/{elections-phragmen => elections}/src/migrations/v4.rs | 0 frame/{elections-phragmen => elections}/src/migrations/v5.rs | 0 frame/{elections-phragmen => elections}/src/weights.rs | 0 utils/frame/remote-externalities/Cargo.toml | 2 +- 12 files changed, 2 insertions(+), 2 deletions(-) rename frame/{elections-phragmen => elections}/CHANGELOG.md (100%) rename frame/{elections-phragmen => elections}/Cargo.toml (100%) rename frame/{elections-phragmen => elections}/README.md (100%) rename frame/{elections-phragmen => elections}/src/benchmarking.rs (100%) rename frame/{elections-phragmen => elections}/src/lib.rs (100%) rename frame/{elections-phragmen => elections}/src/migrations/mod.rs (100%) rename frame/{elections-phragmen => elections}/src/migrations/v3.rs (100%) rename frame/{elections-phragmen => elections}/src/migrations/v4.rs (100%) rename frame/{elections-phragmen => elections}/src/migrations/v5.rs (100%) rename frame/{elections-phragmen => elections}/src/weights.rs (100%) diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 1bc0c0756cf2d..babbacd866a0e 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -66,7 +66,7 @@ pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, pa pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" } pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" } pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true } -pallet-elections = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" } +pallet-elections = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections" } pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" } pallet-gilt = { version = "4.0.0-dev", default-features = false, path = "../../../frame/gilt" } pallet-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../frame/grandpa" } diff --git a/frame/elections-phragmen/CHANGELOG.md b/frame/elections/CHANGELOG.md similarity index 100% rename from frame/elections-phragmen/CHANGELOG.md rename to frame/elections/CHANGELOG.md diff --git a/frame/elections-phragmen/Cargo.toml b/frame/elections/Cargo.toml similarity index 100% rename from frame/elections-phragmen/Cargo.toml rename to frame/elections/Cargo.toml diff --git a/frame/elections-phragmen/README.md b/frame/elections/README.md similarity index 100% rename from frame/elections-phragmen/README.md rename to frame/elections/README.md diff --git a/frame/elections-phragmen/src/benchmarking.rs b/frame/elections/src/benchmarking.rs similarity index 100% rename from frame/elections-phragmen/src/benchmarking.rs rename to frame/elections/src/benchmarking.rs diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections/src/lib.rs similarity index 100% rename from frame/elections-phragmen/src/lib.rs rename to frame/elections/src/lib.rs diff --git a/frame/elections-phragmen/src/migrations/mod.rs b/frame/elections/src/migrations/mod.rs similarity index 100% rename from frame/elections-phragmen/src/migrations/mod.rs rename to frame/elections/src/migrations/mod.rs diff --git a/frame/elections-phragmen/src/migrations/v3.rs b/frame/elections/src/migrations/v3.rs similarity index 100% rename from frame/elections-phragmen/src/migrations/v3.rs rename to frame/elections/src/migrations/v3.rs diff --git a/frame/elections-phragmen/src/migrations/v4.rs b/frame/elections/src/migrations/v4.rs similarity index 100% rename from frame/elections-phragmen/src/migrations/v4.rs rename to frame/elections/src/migrations/v4.rs diff --git a/frame/elections-phragmen/src/migrations/v5.rs b/frame/elections/src/migrations/v5.rs similarity index 100% rename from frame/elections-phragmen/src/migrations/v5.rs rename to frame/elections/src/migrations/v5.rs diff --git a/frame/elections-phragmen/src/weights.rs b/frame/elections/src/weights.rs similarity index 100% rename from frame/elections-phragmen/src/weights.rs rename to frame/elections/src/weights.rs diff --git a/utils/frame/remote-externalities/Cargo.toml b/utils/frame/remote-externalities/Cargo.toml index d70d1f1a2b7ac..739bbc2d933a8 100644 --- a/utils/frame/remote-externalities/Cargo.toml +++ b/utils/frame/remote-externalities/Cargo.toml @@ -28,7 +28,7 @@ substrate-rpc-client = { path = "../rpc/client" } [dev-dependencies] tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] } frame-support = { version = "4.0.0-dev", path = "../../../frame/support" } -pallet-elections = { version = "5.0.0-dev", path = "../../../frame/elections-phragmen" } +pallet-elections = { version = "5.0.0-dev", path = "../../../frame/elections" } [features] remote-test = ["frame-support"] From e21f6aeacdcc561f1d932636b4e99c7e73da362c Mon Sep 17 00:00:00 2001 From: gpestana Date: Sun, 13 Nov 2022 19:35:08 +0100 Subject: [PATCH 09/34] weights rename --- Cargo.toml | 1 + frame/elections/src/lib.rs | 2 +- frame/elections/src/weights.rs | 14 +++++++------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab8fbd816b004..87cdb1b9d07e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,7 @@ members = [ "frame/democracy", "frame/fast-unstake", "frame/try-runtime", + "frame/elections" "frame/election-provider-multi-phase", "frame/election-provider-support", "frame/election-provider-support/benchmarking", diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 2013176dc2ebd..bdb2196bb6258 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -3246,7 +3246,7 @@ mod tests { System::set_block_number(5); let election_weight = Elections::on_initialize(System::block_number()); - let expected_weight: Weight = <() as WeightInfo>::election_phragmen(2, 2, 2); + let expected_weight: Weight = <() as WeightInfo>::election(2, 2, 2); assert_eq!(expected_weight, election_weight); }) diff --git a/frame/elections/src/weights.rs b/frame/elections/src/weights.rs index ddc55b08750d5..e3e2870615706 100644 --- a/frame/elections/src/weights.rs +++ b/frame/elections/src/weights.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Autogenerated weights for pallet_elections_phragmen +//! Autogenerated weights for pallet_elections //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev //! DATE: 2022-11-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` @@ -29,7 +29,7 @@ // --chain=dev // --steps=50 // --repeat=20 -// --pallet=pallet_elections_phragmen +// --pallet=pallet_elections // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -45,7 +45,7 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; -/// Weight functions needed for pallet_elections_phragmen. +/// Weight functions needed for pallet_elections. pub trait WeightInfo { fn vote_equal(v: u32, ) -> Weight; fn vote_more(v: u32, ) -> Weight; @@ -58,10 +58,10 @@ pub trait WeightInfo { fn remove_member_without_replacement() -> Weight; fn remove_member_with_replacement() -> Weight; fn clean_defunct_voters(v: u32, d: u32, ) -> Weight; - fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight; + fn election(c: u32, v: u32, e: u32, ) -> Weight; } -/// Weights for pallet_elections_phragmen using the Substrate node and recommended hardware. +/// Weights for pallet_elections using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: Elections Candidates (r:1 w:0) @@ -200,7 +200,7 @@ impl WeightInfo for SubstrateWeight { /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight { + fn election(c: u32, v: u32, e: u32, ) -> Weight { // Minimum execution time: 22_034_317 nanoseconds. Weight::from_ref_time(22_110_020_000 as u64) // Standard Error: 235_528 @@ -353,7 +353,7 @@ impl WeightInfo for () { /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight { + fn election(c: u32, v: u32, e: u32, ) -> Weight { // Minimum execution time: 22_034_317 nanoseconds. Weight::from_ref_time(22_110_020_000 as u64) // Standard Error: 235_528 From e9c3daf1f050b034442fee9c6d95d43ce65a1eed Mon Sep 17 00:00:00 2001 From: gpestana Date: Mon, 14 Nov 2022 08:41:43 +0100 Subject: [PATCH 10/34] fixes typo in cargo toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 87cdb1b9d07e2..30b5f432db200 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,7 +91,7 @@ members = [ "frame/democracy", "frame/fast-unstake", "frame/try-runtime", - "frame/elections" + "frame/elections", "frame/election-provider-multi-phase", "frame/election-provider-support", "frame/election-provider-support/benchmarking", From 5d947afa1ec9699fe363bb1df0da2d41cf2e09fe Mon Sep 17 00:00:00 2001 From: gpestana Date: Tue, 15 Nov 2022 10:51:01 +0000 Subject: [PATCH 11/34] pre/post solve weight scafolding --- frame/elections/src/lib.rs | 9 +++++++++ frame/elections/src/weights.rs | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index bdb2196bb6258..b211746594297 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -964,6 +964,13 @@ impl Pallet { }) .collect::>(); + let pre_solve_weight = T::WeightInfo::pre_election( + voters_and_stakes.len() as u32, + candidate_ids.len() as u32, + num_edges, + ); + let mut post_election_weight: Weight = Weight::zero(); + let num_candidates = candidates_and_deposit.len() as u32; let num_voters = voters_and_votes.len() as u32; let _ = T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) @@ -1119,6 +1126,8 @@ impl Pallet { }); T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) + .saturating_add(pre_solve_weight) + .saturating_sub(post_election_weight) } } diff --git a/frame/elections/src/weights.rs b/frame/elections/src/weights.rs index e3e2870615706..07869852cc761 100644 --- a/frame/elections/src/weights.rs +++ b/frame/elections/src/weights.rs @@ -59,6 +59,10 @@ pub trait WeightInfo { fn remove_member_with_replacement() -> Weight; fn clean_defunct_voters(v: u32, d: u32, ) -> Weight; fn election(c: u32, v: u32, e: u32, ) -> Weight; + + // TODO(gpestana): generate from benchmarks + fn pre_election(c: u32, v: u32, e: u32) -> Weight; + fn post_election(c: u32, v: u32, e: u32) -> Weight; } /// Weights for pallet_elections using the Substrate node and recommended hardware. @@ -213,6 +217,14 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(6 as u64)) .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(c as u64))) } + + // TODO(gpestana): generate from benchmarks + fn pre_election(_c: u32, _v: u32, _e: u32) -> Weight { + Weight::zero() + } + fn post_election(_c: u32, _v: u32, _e: u32) -> Weight { + Weight::zero() + } } // For backwards compatibility and tests @@ -366,4 +378,12 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(6 as u64)) .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(c as u64))) } + + // TODO(gpestana): generate from benchmarks + fn pre_election(_c: u32, _v: u32, _e: u32) -> Weight { + Weight::zero() + } + fn post_election(_c: u32, _v: u32, _e: u32) -> Weight { + Weight::zero() + } } From ecd7b63b080efe6e1727a1b624fa26739fc7df5e Mon Sep 17 00:00:00 2001 From: gpestana Date: Tue, 15 Nov 2022 11:31:53 +0000 Subject: [PATCH 12/34] refactor do_post_election --- frame/elections/src/lib.rs | 308 +++++++++++++++++++------------------ 1 file changed, 155 insertions(+), 153 deletions(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index b211746594297..4e7a43466d653 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -928,7 +928,6 @@ impl Pallet { // helper closures to deal with balance/stake. let total_issuance = T::Currency::total_issuance(); let to_votes = |b: BalanceOf| T::CurrencyToVote::to_vote(b, total_issuance); - let to_balance = |e: ExtendedBalance| T::CurrencyToVote::to_currency(e, total_issuance); let mut num_edges: u32 = 0; @@ -969,165 +968,168 @@ impl Pallet { candidate_ids.len() as u32, num_edges, ); - let mut post_election_weight: Weight = Weight::zero(); let num_candidates = candidates_and_deposit.len() as u32; let num_voters = voters_and_votes.len() as u32; - let _ = T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) - .map( - |ElectionResult::::Accuracy> { - winners, - assignments: _, - }| { - // this is already sorted by id. - let old_members_ids_sorted = >::take() - .into_iter() - .map(|m| m.who) - .collect::>(); - // this one needs a sort by id. - let mut old_runners_up_ids_sorted = >::take() - .into_iter() - .map(|r| r.who) - .collect::>(); - old_runners_up_ids_sorted.sort(); - - // filter out those who end up with no backing stake. - let mut new_set_with_stake = winners - .into_iter() - .filter_map( - |(m, b)| if b.is_zero() { None } else { Some((m, to_balance(b))) }, - ) - .collect::)>>(); - - // OPTIMIZATION NOTE: we could bail out here if `new_set.len() == 0`. There - // isn't much left to do. Yet, re-arranging the code would require duplicating - // the slashing of exposed candidates, cleaning any previous members, and so on. - // For now, in favor of readability and veracity, we keep it simple. - - // split new set into winners and runners up. - let split_point = desired_seats.min(new_set_with_stake.len()); - let mut new_members_sorted_by_id = - new_set_with_stake.drain(..split_point).collect::>(); - new_members_sorted_by_id.sort_by(|i, j| i.0.cmp(&j.0)); - - // all the rest will be runners-up - new_set_with_stake.reverse(); - let new_runners_up_sorted_by_rank = new_set_with_stake; - let mut new_runners_up_ids_sorted = new_runners_up_sorted_by_rank - .iter() - .map(|(r, _)| r.clone()) - .collect::>(); - new_runners_up_ids_sorted.sort(); - - // Now we select a prime member using a [Borda - // count](https://en.wikipedia.org/wiki/Borda_count). We weigh everyone's vote for - // that new member by a multiplier based on the order of the votes. i.e. the - // first person a voter votes for gets a 16x multiplier, the next person gets a - // 15x multiplier, an so on... (assuming `MAXIMUM_VOTE` = 16) - let mut prime_votes = new_members_sorted_by_id - .iter() - .map(|c| (&c.0, BalanceOf::::zero())) - .collect::>(); - for (_, stake, votes) in voters_and_stakes.into_iter() { - for (vote_multiplier, who) in - votes.iter().enumerate().map(|(vote_position, who)| { - ((MAXIMUM_VOTE - vote_position) as u32, who) - }) { - if let Ok(i) = prime_votes.binary_search_by_key(&who, |k| k.0) { - prime_votes[i].1 = prime_votes[i] - .1 - .saturating_add(stake.saturating_mul(vote_multiplier.into())); - } - } - } - // We then select the new member with the highest weighted stake. In the case of - // a tie, the last person in the list with the tied score is selected. This is - // the person with the "highest" account id based on the sort above. - let prime = prime_votes.into_iter().max_by_key(|x| x.1).map(|x| x.0.clone()); - - // new_members_sorted_by_id is sorted by account id. - let new_members_ids_sorted = new_members_sorted_by_id - .iter() - .map(|(m, _)| m.clone()) - .collect::>(); - - // report member changes. We compute diff because we need the outgoing list. - let (incoming, outgoing) = T::ChangeMembers::compute_members_diff_sorted( - &new_members_ids_sorted, - &old_members_ids_sorted, - ); - T::ChangeMembers::change_members_sorted( - &incoming, - &outgoing, - &new_members_ids_sorted, - ); - T::ChangeMembers::set_prime(prime); - - // All candidates/members/runners-up who are no longer retaining a position as a - // seat holder will lose their bond. - candidates_and_deposit.iter().for_each(|(c, d)| { - if new_members_ids_sorted.binary_search(c).is_err() && - new_runners_up_ids_sorted.binary_search(c).is_err() - { - let (imbalance, _) = T::Currency::slash_reserved(c, *d); - T::LoserCandidate::on_unbalanced(imbalance); - Self::deposit_event(Event::CandidateSlashed { - candidate: c.clone(), - amount: *d, - }); - } - }); + let post_election_weight = + T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) + .map( + |ElectionResult::< + T::AccountId, + ::Accuracy, + > { + winners, + assignments: _, + }| { + Self::do_post_election( + winners, + candidates_and_deposit, + voters_and_stakes, + desired_seats, + ); + T::WeightInfo::post_election(1, 1, 1) // TODO(gpestana): finish + }, + ) + .map_err(|e| { + log!(warn, "Failed to run election [{:?}].", e); + Self::deposit_event(Event::ElectionError); + }); - // write final values to storage. - let deposit_of_candidate = |x: &T::AccountId| -> BalanceOf { - // defensive-only. This closure is used against the new members and new - // runners-up, both of which are election winners and thus must have - // deposit. - candidates_and_deposit - .iter() - .find_map(|(c, d)| if c == x { Some(*d) } else { None }) - .defensive_unwrap_or_default() - }; - // fetch deposits from the one recorded one. This will make sure that a - // candidate who submitted candidacy before a change to candidacy deposit will - // have the correct amount recorded. - >::put( - new_members_sorted_by_id - .iter() - .map(|(who, stake)| SeatHolder { - deposit: deposit_of_candidate(who), - who: who.clone(), - stake: *stake, - }) - .collect::>(), - ); - >::put( - new_runners_up_sorted_by_rank - .into_iter() - .map(|(who, stake)| SeatHolder { - deposit: deposit_of_candidate(&who), - who, - stake, - }) - .collect::>(), - ); + T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) + .saturating_add(pre_solve_weight) + .saturating_sub(post_election_weight.unwrap()) // TODO(unwrap()) + } - // clean candidates. - >::kill(); + fn do_post_election( + winners: Vec<(T::AccountId, u128)>, + candidates_and_deposit: Vec<(T::AccountId, BalanceOf)>, + voters_and_stakes: Vec<(T::AccountId, BalanceOf, Vec)>, + desired_seats: usize, + ) { + let total_issuance = T::Currency::total_issuance(); + let to_balance = |e: ExtendedBalance| T::CurrencyToVote::to_currency(e, total_issuance); - log!(info, "New term election successful."); - Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id }); - >::mutate(|v| *v += 1); - }, - ) - .map_err(|e| { - log!(warn, "Failed to run election [{:?}].", e); - Self::deposit_event(Event::ElectionError); - }); + // this is already sorted by id. + let old_members_ids_sorted = + >::take().into_iter().map(|m| m.who).collect::>(); + // this one needs a sort by id. + let mut old_runners_up_ids_sorted = + >::take().into_iter().map(|r| r.who).collect::>(); + old_runners_up_ids_sorted.sort(); - T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) - .saturating_add(pre_solve_weight) - .saturating_sub(post_election_weight) + // filter out those who end up with no backing stake. + let mut new_set_with_stake = winners + .into_iter() + .filter_map(|(m, b)| if b.is_zero() { None } else { Some((m, to_balance(b))) }) + .collect::)>>(); + + // OPTIMIZATION NOTE: we could bail out here if `new_set.len() == 0`. There + // isn't much left to do. Yet, re-arranging the code would require duplicating + // the slashing of exposed candidates, cleaning any previous members, and so on. + // For now, in favor of readability and veracity, we keep it simple. + + // split new set into winners and runners up. + let split_point = desired_seats.min(new_set_with_stake.len()); + let mut new_members_sorted_by_id = + new_set_with_stake.drain(..split_point).collect::>(); + new_members_sorted_by_id.sort_by(|i, j| i.0.cmp(&j.0)); + + // all the rest will be runners-up + new_set_with_stake.reverse(); + let new_runners_up_sorted_by_rank = new_set_with_stake; + let mut new_runners_up_ids_sorted = + new_runners_up_sorted_by_rank.iter().map(|(r, _)| r.clone()).collect::>(); + new_runners_up_ids_sorted.sort(); + + // Now we select a prime member using a [Borda + // count](https://en.wikipedia.org/wiki/Borda_count). We weigh everyone's vote for + // that new member by a multiplier based on the order of the votes. i.e. the + // first person a voter votes for gets a 16x multiplier, the next person gets a + // 15x multiplier, an so on... (assuming `MAXIMUM_VOTE` = 16) + let mut prime_votes = new_members_sorted_by_id + .iter() + .map(|c| (&c.0, BalanceOf::::zero())) + .collect::>(); + for (_, stake, votes) in voters_and_stakes.into_iter() { + for (vote_multiplier, who) in votes + .iter() + .enumerate() + .map(|(vote_position, who)| ((MAXIMUM_VOTE - vote_position) as u32, who)) + { + if let Ok(i) = prime_votes.binary_search_by_key(&who, |k| k.0) { + prime_votes[i].1 = prime_votes[i] + .1 + .saturating_add(stake.saturating_mul(vote_multiplier.into())); + } + } + } + // We then select the new member with the highest weighted stake. In the case of + // a tie, the last person in the list with the tied score is selected. This is + // the person with the "highest" account id based on the sort above. + let prime = prime_votes.into_iter().max_by_key(|x| x.1).map(|x| x.0.clone()); + + // new_members_sorted_by_id is sorted by account id. + let new_members_ids_sorted = new_members_sorted_by_id + .iter() + .map(|(m, _)| m.clone()) + .collect::>(); + + // report member changes. We compute diff because we need the outgoing list. + let (incoming, outgoing) = T::ChangeMembers::compute_members_diff_sorted( + &new_members_ids_sorted, + &old_members_ids_sorted, + ); + T::ChangeMembers::change_members_sorted(&incoming, &outgoing, &new_members_ids_sorted); + T::ChangeMembers::set_prime(prime); + + // All candidates/members/runners-up who are no longer retaining a position as a + // seat holder will lose their bond. + candidates_and_deposit.iter().for_each(|(c, d)| { + if new_members_ids_sorted.binary_search(c).is_err() && + new_runners_up_ids_sorted.binary_search(c).is_err() + { + let (imbalance, _) = T::Currency::slash_reserved(c, *d); + T::LoserCandidate::on_unbalanced(imbalance); + Self::deposit_event(Event::CandidateSlashed { candidate: c.clone(), amount: *d }); + } + }); + + // write final values to storage. + let deposit_of_candidate = |x: &T::AccountId| -> BalanceOf { + // defensive-only. This closure is used against the new members and new + // runners-up, both of which are election winners and thus must have + // deposit. + candidates_and_deposit + .iter() + .find_map(|(c, d)| if c == x { Some(*d) } else { None }) + .defensive_unwrap_or_default() + }; + // fetch deposits from the one recorded one. This will make sure that a + // candidate who submitted candidacy before a change to candidacy deposit will + // have the correct amount recorded. + >::put( + new_members_sorted_by_id + .iter() + .map(|(who, stake)| SeatHolder { + deposit: deposit_of_candidate(who), + who: who.clone(), + stake: *stake, + }) + .collect::>(), + ); + >::put( + new_runners_up_sorted_by_rank + .into_iter() + .map(|(who, stake)| SeatHolder { deposit: deposit_of_candidate(&who), who, stake }) + .collect::>(), + ); + + // clean candidates. + >::kill(); + + log!(info, "New term election successful."); + Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id }); + >::mutate(|v| *v += 1); } } From 090aa90de87773ba6976463b3bb6dcb4e540bae7 Mon Sep 17 00:00:00 2001 From: gpestana Date: Tue, 15 Nov 2022 18:22:41 +0000 Subject: [PATCH 13/34] refactors into pre and post election solve for independent benchmarking --- frame/elections/src/lib.rs | 128 +++++++++++++++++++++++-------------- 1 file changed, 81 insertions(+), 47 deletions(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 4e7a43466d653..bac01026195cd 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -109,12 +109,12 @@ use frame_support::{ weights::Weight, }; use scale_info::TypeInfo; -use sp_npos_elections::{ElectionResult, ExtendedBalance}; +use sp_npos_elections::{ElectionResult, ExtendedBalance, VoteWeight}; use sp_runtime::{ traits::{Saturating, StaticLookup, Zero}, DispatchError, RuntimeDebug, }; -use sp_std::{cmp::Ordering, prelude::*}; +use sp_std::{cmp::Ordering, iter::IntoIterator, prelude::*}; mod benchmarking; pub mod weights; @@ -188,6 +188,17 @@ pub struct SeatHolder { pub deposit: Balance, } +/// The results of running the pre-election step. +#[derive(Debug, Clone)] +pub struct PreElectionResults { + pub num_to_elect: usize, + pub candidate_ids: Vec, + pub candidates_and_deposit: Vec<(T::AccountId, BalanceOf)>, + pub voters_and_stakes: Vec<(T::AccountId, BalanceOf, Vec)>, + pub voters_and_votes: Vec<(T::AccountId, VoteWeight, Vec)>, + pub num_edges: u32, +} + pub use pallet::*; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; @@ -908,6 +919,62 @@ impl Pallet { /// /// Calls the appropriate [`ChangeMembers`] function variant internally. fn do_election() -> Weight { + let pre_election_results = match Self::do_pre_solve_election() { + Ok(results) => results, + Err(event) => match event { + Event::EmptyTerm => { + Self::deposit_event(event); + return T::DbWeight::get().reads(3) + }, + Event::ElectionError => { + Self::deposit_event(event); + log::error!( + target: "runtime:elections", + "Failed to run election. Number of voters exceeded", + ); + let max_voters = ::MaxVoters::get() as usize; + return T::DbWeight::get().reads(3 + max_voters as u64) + }, + _ => unreachable!("should not happen"), + }, + }; + + let num_candidates = pre_election_results.candidates_and_deposit.len() as u32; + let num_voters = pre_election_results.voters_and_votes.len() as u32; + let num_edges = pre_election_results.num_edges; + + let _ = T::ElectionSolver::solve( + pre_election_results.num_to_elect, + pre_election_results.candidate_ids, + pre_election_results.voters_and_votes, + ) + .map( + |ElectionResult::::Accuracy> { + winners, + assignments: _, + }| { + Self::do_post_solve_election( + winners, + pre_election_results.candidates_and_deposit, + pre_election_results.voters_and_stakes, + ); + }, + ) + .map_err(|e| { + log!(warn, "Failed to run election [{:?}].", e); + Self::deposit_event(Event::ElectionError); + }); + + // TODO(gpestana): pull pre/post weights from WeightInfo after benchmarking + let pre_solve_weight = Weight::zero(); + let post_solve_weight = Weight::zero(); + + T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) + .saturating_add(pre_solve_weight) + .saturating_sub(post_solve_weight) + } + + fn do_pre_solve_election() -> Result, Event> { let desired_seats = T::DesiredMembers::get() as usize; let desired_runners_up = T::DesiredRunnersUp::get() as usize; let num_to_elect = desired_runners_up + desired_seats; @@ -918,7 +985,7 @@ impl Pallet { if candidates_and_deposit.len().is_zero() { Self::deposit_event(Event::EmptyTerm); - return T::DbWeight::get().reads(3) + return Err(Event::EmptyTerm) } // All of the new winners that come out of the election will thus have a deposit recorded. @@ -934,6 +1001,7 @@ impl Pallet { let max_voters = ::MaxVoters::get() as usize; // used for prime election. let mut voters_and_stakes = Vec::new(); + match Voting::::iter().try_for_each(|(voter, Voter { stake, votes, .. })| { if voters_and_stakes.len() < max_voters { voters_and_stakes.push((voter, stake, votes)); @@ -943,14 +1011,7 @@ impl Pallet { } }) { Ok(_) => (), - Err(_) => { - log::error!( - target: "runtime::elections", - "Failed to run election. Number of voters exceeded", - ); - Self::deposit_event(Event::ElectionError); - return T::DbWeight::get().reads(3 + max_voters as u64) - }, + Err(_) => return Err(Event::ElectionError), } // used for elections. @@ -963,49 +1024,22 @@ impl Pallet { }) .collect::>(); - let pre_solve_weight = T::WeightInfo::pre_election( - voters_and_stakes.len() as u32, - candidate_ids.len() as u32, + Ok(PreElectionResults { + num_to_elect, + candidate_ids, + candidates_and_deposit, + voters_and_stakes, + voters_and_votes, num_edges, - ); - - let num_candidates = candidates_and_deposit.len() as u32; - let num_voters = voters_and_votes.len() as u32; - let post_election_weight = - T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) - .map( - |ElectionResult::< - T::AccountId, - ::Accuracy, - > { - winners, - assignments: _, - }| { - Self::do_post_election( - winners, - candidates_and_deposit, - voters_and_stakes, - desired_seats, - ); - T::WeightInfo::post_election(1, 1, 1) // TODO(gpestana): finish - }, - ) - .map_err(|e| { - log!(warn, "Failed to run election [{:?}].", e); - Self::deposit_event(Event::ElectionError); - }); - - T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) - .saturating_add(pre_solve_weight) - .saturating_sub(post_election_weight.unwrap()) // TODO(unwrap()) + }) } - fn do_post_election( + fn do_post_solve_election( winners: Vec<(T::AccountId, u128)>, candidates_and_deposit: Vec<(T::AccountId, BalanceOf)>, voters_and_stakes: Vec<(T::AccountId, BalanceOf, Vec)>, - desired_seats: usize, ) { + let desired_seats = T::DesiredMembers::get() as usize; let total_issuance = T::Currency::total_issuance(); let to_balance = |e: ExtendedBalance| T::CurrencyToVote::to_currency(e, total_issuance); From 1e2ef466bc2df189e85b77d05deb8458bef5d4d4 Mon Sep 17 00:00:00 2001 From: gpestana Date: Tue, 15 Nov 2022 18:41:40 +0000 Subject: [PATCH 14/34] deconstructs PreElectionResults struct --- frame/elections/CHANGELOG.md | 2 +- frame/elections/src/lib.rs | 55 +++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/frame/elections/CHANGELOG.md b/frame/elections/CHANGELOG.md index bc21e888ab83a..b173557be6feb 100644 --- a/frame/elections/CHANGELOG.md +++ b/frame/elections/CHANGELOG.md @@ -9,7 +9,7 @@ and this crate adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h ### Added ### Changed -\[**Needs Migration**\] Generalized the pallet to use `NposSolver` instead of hard coding the phragmen algorithm; Changed the name of the pallet to `pallet-elections` and the pallet's lock ID. +Generalized the pallet to use `NposSolver` instead of hard coding the phragmen algorithm; Changed the name of the pallet from `pallet-elections-phragmen` to `pallet-elections` ### Fixed diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index bac01026195cd..6b22b3164b6cc 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -919,7 +919,14 @@ impl Pallet { /// /// Calls the appropriate [`ChangeMembers`] function variant internally. fn do_election() -> Weight { - let pre_election_results = match Self::do_pre_solve_election() { + let PreElectionResults { + num_to_elect, + candidate_ids, + candidates_and_deposit, + voters_and_stakes, + voters_and_votes, + num_edges, + } = match Self::do_pre_solve_election() { Ok(results) => results, Err(event) => match event { Event::EmptyTerm => { @@ -939,31 +946,27 @@ impl Pallet { }, }; - let num_candidates = pre_election_results.candidates_and_deposit.len() as u32; - let num_voters = pre_election_results.voters_and_votes.len() as u32; - let num_edges = pre_election_results.num_edges; - - let _ = T::ElectionSolver::solve( - pre_election_results.num_to_elect, - pre_election_results.candidate_ids, - pre_election_results.voters_and_votes, - ) - .map( - |ElectionResult::::Accuracy> { - winners, - assignments: _, - }| { - Self::do_post_solve_election( - winners, - pre_election_results.candidates_and_deposit, - pre_election_results.voters_and_stakes, - ); - }, - ) - .map_err(|e| { - log!(warn, "Failed to run election [{:?}].", e); - Self::deposit_event(Event::ElectionError); - }); + let num_candidates = candidates_and_deposit.len() as u32; + let num_voters = voters_and_votes.len() as u32; + let num_edges = num_edges; + + let _ = T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) + .map( + |ElectionResult::::Accuracy> { + winners, + assignments: _, + }| { + Self::do_post_solve_election( + winners, + candidates_and_deposit, + voters_and_stakes, + ); + }, + ) + .map_err(|e| { + log!(warn, "Failed to run election [{:?}].", e); + Self::deposit_event(Event::ElectionError); + }); // TODO(gpestana): pull pre/post weights from WeightInfo after benchmarking let pre_solve_weight = Weight::zero(); From d4b8c4ede93924e7987a957a980ff0dfdbfba597 Mon Sep 17 00:00:00 2001 From: gpestana Date: Wed, 16 Nov 2022 14:37:13 +0000 Subject: [PATCH 15/34] updates benchmarking pre and post election solve; mock weights --- bin/node/runtime/src/lib.rs | 17 +++-- frame/elections/src/benchmarking.rs | 103 +++++++++++----------------- frame/elections/src/lib.rs | 52 +++++++------- 3 files changed, 77 insertions(+), 95 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index eab40634ff241..16522bd589af7 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -24,7 +24,8 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_election_provider_support::{ - onchain, BalancingConfig, ElectionDataProvider, SequentialPhragmen, VoteWeight, + onchain, weights::SubstrateWeight, BalancingConfig, ElectionDataProvider, SequentialPhragmen, + VoteWeight, }; use frame_support::{ construct_runtime, @@ -999,15 +1000,15 @@ parameter_types! { pub const DesiredRunnersUp: u32 = 7; pub const MaxVoters: u32 = 10 * 1000; pub const MaxCandidates: u32 = 1000; - pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; + pub const ElectionsPalletId: LockIdentifier = *b"phrelect"; } // Make sure that there are no more than `MaxMembers` members elected via elections-phragmen. const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get()); -impl pallet_elections_phragmen::Config for Runtime { +impl pallet_elections::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type PalletId = ElectionsPhragmenPalletId; + type PalletId = ElectionsPalletId; type Currency = Balances; type ChangeMembers = Council; // NOTE: this implies that council's genesis members cannot be set directly and must come from @@ -1024,7 +1025,9 @@ impl pallet_elections_phragmen::Config for Runtime { type TermDuration = TermDuration; type MaxVoters = MaxVoters; type MaxCandidates = MaxCandidates; - type WeightInfo = pallet_elections_phragmen::weights::SubstrateWeight; + type ElectionSolver = SequentialPhragmen; + type SolverWeightInfo = SubstrateWeight; + type WeightInfo = pallet_elections::weights::SubstrateWeight; } parameter_types! { @@ -1638,7 +1641,7 @@ construct_runtime!( Democracy: pallet_democracy, Council: pallet_collective::, TechnicalCommittee: pallet_collective::, - Elections: pallet_elections_phragmen, + Elections: pallet_elections, TechnicalMembership: pallet_membership::, Grandpa: pallet_grandpa, Treasury: pallet_treasury, @@ -1763,7 +1766,7 @@ mod benches { [pallet_democracy, Democracy] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] [pallet_election_provider_support_benchmarking, EPSBench::] - [pallet_elections_phragmen, Elections] + [pallet_elections, Elections] [pallet_fast_unstake, FastUnstake] [pallet_gilt, Gilt] [pallet_grandpa, Grandpa] diff --git a/frame/elections/src/benchmarking.rs b/frame/elections/src/benchmarking.rs index 06ac8d7c60162..4baed5b25bf9c 100644 --- a/frame/elections/src/benchmarking.rs +++ b/frame/elections/src/benchmarking.rs @@ -15,14 +15,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Elections-Phragmen pallet benchmarking. +//! Elections pallet benchmarking. #![cfg(feature = "runtime-benchmarks")] use super::*; use frame_benchmarking::{account, benchmarks, whitelist, BenchmarkError, BenchmarkResult}; -use frame_support::{dispatch::DispatchResultWithPostInfo, traits::OnInitialize}; +use frame_support::dispatch::DispatchResultWithPostInfo; use frame_system::RawOrigin; use crate::Pallet as Elections; @@ -37,7 +37,7 @@ fn endowed_account(name: &'static str, index: u32) -> T::AccountId { let amount = default_stake::(T::MaxVoters::get()) * BalanceOf::::from(BALANCE_FACTOR); let _ = T::Currency::make_free_balance_be(&account, amount); // important to increase the total issuance since T::CurrencyToVote will need it to be sane for - // phragmen to work. + // the election to work. T::Currency::issue(amount); account @@ -122,7 +122,7 @@ fn distribute_voters( fn fill_seats_up_to(m: u32) -> Result, &'static str> { let _ = submit_candidates_with_self_vote::(m, "fill_seats_up_to")?; assert_eq!(>::candidates().len() as u32, m, "wrong number of candidates."); - >::do_phragmen(); + >::do_election(); assert_eq!(>::candidates().len(), 0, "some candidates remaining."); assert_eq!( >::members().len() + >::runners_up().len(), @@ -382,11 +382,11 @@ benchmarks! { assert_eq!(>::iter().count() as u32, 0); } - election_phragmen { - // This is just to focus on phragmen in the context of this module. We always select 20 - // members, this is hard-coded in the runtime and cannot be trivially changed at this stage. - // Yet, change the number of voters, candidates and edge per voter to see the impact. Note - // that we give all candidates a self vote to make sure they are all considered. + pre_solve_election { + // We always select 20 members, this is hard-coded in the runtime and cannot be trivially + // changed at this stage. Yet, change the number of voters, candidates and edge per voter + // to see the impact. Note that we give all candidates a self vote to make sure they are + // all considered. let c in 1 .. T::MaxCandidates::get(); let v in 1 .. T::MaxVoters::get(); let e in (T::MaxVoters::get()) .. T::MaxVoters::get() as u32 * MAXIMUM_VOTE as u32; @@ -404,75 +404,50 @@ benchmarks! { let all_candidates = submit_candidates_with_self_vote::(c, "candidates")?; let _ = distribute_voters::(all_candidates, v.saturating_sub(c), votes_per_voter as usize)?; }: { - >::on_initialize(T::TermDuration::get()); + >::do_pre_solve_election().unwrap(); } - verify { - assert_eq!(>::members().len() as u32, T::DesiredMembers::get().min(c)); - assert_eq!( - >::runners_up().len() as u32, - T::DesiredRunnersUp::get().min(c.saturating_sub(T::DesiredMembers::get())), - ); - #[cfg(test)] - { - // reset members in between benchmark tests. - use crate::tests::MEMBERS; - MEMBERS.with(|m| *m.borrow_mut() = vec![]); - } - } - - #[extra] - election_phragmen_c_e { + post_solve_election { + // We always select 20 members, this is hard-coded in the runtime and cannot be trivially + // changed at this stage. Yet, change the number of voters, candidates and edge per voter + // to see the impact. Note that we give all candidates a self vote to make sure they are + // all considered. let c in 1 .. T::MaxCandidates::get(); - let e in (T::MaxVoters::get()) .. T::MaxVoters::get() * MAXIMUM_VOTE as u32; - let fixed_v = T::MaxVoters::get(); + let v in 1 .. T::MaxVoters::get(); + let e in (T::MaxVoters::get()) .. T::MaxVoters::get() as u32 * MAXIMUM_VOTE as u32; clean::(); - let votes_per_voter = e / fixed_v; + // so we have a situation with v and e. we want e to basically always be in the range of `e + // -> e * MAXIMUM_VOTE`, but we cannot express that now with the benchmarks. So what we do + // is: when c is being iterated, v, and e are max and fine. when v is being iterated, e is + // being set to max and this is a problem. In these cases, we cap e to a lower value, namely + // v * MAXIMUM_VOTE. when e is being iterated, v is at max, and again fine. all in all, + // votes_per_voter can never be more than MAXIMUM_VOTE. Note that this might cause `v` to be + // an overestimate. + let votes_per_voter = (e / v).min(MAXIMUM_VOTE as u32); let all_candidates = submit_candidates_with_self_vote::(c, "candidates")?; - let _ = distribute_voters::( - all_candidates, - fixed_v - c, - votes_per_voter as usize, - )?; - }: { - >::on_initialize(T::TermDuration::get()); - } - verify { - assert_eq!(>::members().len() as u32, T::DesiredMembers::get().min(c)); - assert_eq!( - >::runners_up().len() as u32, - T::DesiredRunnersUp::get().min(c.saturating_sub(T::DesiredMembers::get())), - ); - - #[cfg(test)] - { - // reset members in between benchmark tests. - use crate::tests::MEMBERS; - MEMBERS.with(|m| *m.borrow_mut() = vec![]); - } - } - - #[extra] - election_phragmen_v { - let v in 4 .. 16; - let fixed_c = T::MaxCandidates::get() / 10; - let fixed_e = 64; - clean::(); + let _ = distribute_voters::(all_candidates, v.saturating_sub(c), votes_per_voter as usize)?; - let votes_per_voter = fixed_e / v; + let pre_election_result = >::do_pre_solve_election().unwrap(); + let election_result = T::ElectionSolver::solve( + pre_election_result.num_to_elect, + pre_election_result.candidate_ids, + pre_election_result.voters_and_votes, + ).unwrap(); - let all_candidates = submit_candidates_with_self_vote::(fixed_c, "candidates")?; - let _ = distribute_voters::(all_candidates, v, votes_per_voter as usize)?; }: { - >::on_initialize(T::TermDuration::get()); + >::do_post_solve_election( + election_result.winners, + pre_election_result.candidates_and_deposit, + pre_election_result.voters_and_stakes, + ); } verify { - assert_eq!(>::members().len() as u32, T::DesiredMembers::get().min(fixed_c)); + assert_eq!(>::members().len() as u32, T::DesiredMembers::get().min(c)); assert_eq!( >::runners_up().len() as u32, - T::DesiredRunnersUp::get().min(fixed_c.saturating_sub(T::DesiredMembers::get())), + T::DesiredRunnersUp::get().min(c.saturating_sub(T::DesiredMembers::get())), ); #[cfg(test)] diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 6b22b3164b6cc..77f644d9ec947 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -950,31 +950,32 @@ impl Pallet { let num_voters = voters_and_votes.len() as u32; let num_edges = num_edges; - let _ = T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) - .map( - |ElectionResult::::Accuracy> { - winners, - assignments: _, - }| { - Self::do_post_solve_election( - winners, - candidates_and_deposit, - voters_and_stakes, - ); - }, - ) - .map_err(|e| { - log!(warn, "Failed to run election [{:?}].", e); - Self::deposit_event(Event::ElectionError); - }); + let election_result = + T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) + .map( + |ElectionResult::< + T::AccountId, + ::Accuracy, + > { + winners, + assignments: _, + }| winners, + ) + .map_err(|e| { + log!(warn, "Failed to run election [{:?}].", e); + Self::deposit_event(Event::ElectionError); + }); - // TODO(gpestana): pull pre/post weights from WeightInfo after benchmarking - let pre_solve_weight = Weight::zero(); - let post_solve_weight = Weight::zero(); + let pre_and_election_weight = + T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) + .saturating_add(Weight::zero()); // replace with weights::pre_solve_election_weight(); - T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) - .saturating_add(pre_solve_weight) - .saturating_sub(post_solve_weight) + match election_result { + Ok(winners) => + Self::do_post_solve_election(winners, candidates_and_deposit, voters_and_stakes) + .saturating_add(pre_and_election_weight), + Err(_) => pre_and_election_weight, + } } fn do_pre_solve_election() -> Result, Event> { @@ -1041,7 +1042,7 @@ impl Pallet { winners: Vec<(T::AccountId, u128)>, candidates_and_deposit: Vec<(T::AccountId, BalanceOf)>, voters_and_stakes: Vec<(T::AccountId, BalanceOf, Vec)>, - ) { + ) -> Weight { let desired_seats = T::DesiredMembers::get() as usize; let total_issuance = T::Currency::total_issuance(); let to_balance = |e: ExtendedBalance| T::CurrencyToVote::to_currency(e, total_issuance); @@ -1167,6 +1168,9 @@ impl Pallet { log!(info, "New term election successful."); Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id }); >::mutate(|v| *v += 1); + + // TODO(gpestana): return the weight::post_solve_weight + Weight::zero() } } From c8a3508d5fafceec732db138a88a265e9b44887f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Thu, 17 Nov 2022 12:24:50 +0000 Subject: [PATCH 16/34] Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/elections/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 77f644d9ec947..71f83d8fdce85 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -129,7 +129,6 @@ pub const MAXIMUM_VOTE: usize = 16; pub(crate) const LOG_TARGET: &str = "runtime::elections"; // logging helper. -#[macro_export] macro_rules! log { ($level:tt, $patter:expr $(, $values:expr)* $(,)?) => { log::$level!( From 8021572b5d6f5644d0e5d1eea6eaa23433df8f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Thu, 17 Nov 2022 12:25:41 +0000 Subject: [PATCH 17/34] Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/elections/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 71f83d8fdce85..f8bc20c00d7ed 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -934,8 +934,7 @@ impl Pallet { }, Event::ElectionError => { Self::deposit_event(event); - log::error!( - target: "runtime:elections", + log!(error, "Failed to run election. Number of voters exceeded", ); let max_voters = ::MaxVoters::get() as usize; From c3db2cbc37e4ef0a70aec7816f64fcee93c07b39 Mon Sep 17 00:00:00 2001 From: gpestana Date: Thu, 17 Nov 2022 12:44:45 +0000 Subject: [PATCH 18/34] addresses PR comments --- frame/elections/src/lib.rs | 52 ++++++++++++-------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index f8bc20c00d7ed..a4863bcc892df 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -189,7 +189,7 @@ pub struct SeatHolder { /// The results of running the pre-election step. #[derive(Debug, Clone)] -pub struct PreElectionResults { +struct PreElectionResults { pub num_to_elect: usize, pub candidate_ids: Vec, pub candidates_and_deposit: Vec<(T::AccountId, BalanceOf)>, @@ -642,6 +642,8 @@ pub mod pallet { InvalidRenouncing, /// Prediction regarding replacement after member removal is wrong. InvalidReplacement, + /// No candidates for the next term. + EmptyTerm, } /// The current elected members. @@ -928,15 +930,13 @@ impl Pallet { } = match Self::do_pre_solve_election() { Ok(results) => results, Err(event) => match event { - Event::EmptyTerm => { - Self::deposit_event(event); + Error::EmptyTerm => { + Self::deposit_event(Event::EmptyTerm); return T::DbWeight::get().reads(3) }, - Event::ElectionError => { - Self::deposit_event(event); - log!(error, - "Failed to run election. Number of voters exceeded", - ); + Error::TooManyVotes => { + Self::deposit_event(Event::ElectionError); + log!(error, "Failed to run election. Number of voters exceeded",); let max_voters = ::MaxVoters::get() as usize; return T::DbWeight::get().reads(3 + max_voters as u64) }, @@ -968,15 +968,15 @@ impl Pallet { T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) .saturating_add(Weight::zero()); // replace with weights::pre_solve_election_weight(); - match election_result { - Ok(winners) => - Self::do_post_solve_election(winners, candidates_and_deposit, voters_and_stakes) - .saturating_add(pre_and_election_weight), - Err(_) => pre_and_election_weight, + if let Ok(winners) = election_result { + Self::do_post_solve_election(winners, candidates_and_deposit, voters_and_stakes) + .saturating_add(pre_and_election_weight) + } else { + pre_and_election_weight } } - fn do_pre_solve_election() -> Result, Event> { + fn do_pre_solve_election() -> Result, Error> { let desired_seats = T::DesiredMembers::get() as usize; let desired_runners_up = T::DesiredRunnersUp::get() as usize; let num_to_elect = desired_runners_up + desired_seats; @@ -986,8 +986,7 @@ impl Pallet { candidates_and_deposit.append(&mut Self::implicit_candidates_with_deposit()); if candidates_and_deposit.len().is_zero() { - Self::deposit_event(Event::EmptyTerm); - return Err(Event::EmptyTerm) + return Err(Error::EmptyTerm) } // All of the new winners that come out of the election will thus have a deposit recorded. @@ -1013,7 +1012,7 @@ impl Pallet { } }) { Ok(_) => (), - Err(_) => return Err(Event::ElectionError), + Err(_) => return Err(Error::TooManyVotes), } // used for elections. @@ -3282,23 +3281,4 @@ mod tests { assert_ok!(Elections::clean_defunct_voters(RuntimeOrigin::root(), 4, 2)); }) } - - #[test] - fn verify_weights() { - ExtBuilder::default().build_and_execute(|| { - assert_eq!(Elections::on_initialize(System::block_number()), Weight::zero()); - - assert_ok!(submit_candidacy(RuntimeOrigin::signed(4))); - assert_ok!(submit_candidacy(RuntimeOrigin::signed(5))); - assert_ok!(vote(RuntimeOrigin::signed(4), vec![4], 40)); - assert_ok!(vote(RuntimeOrigin::signed(5), vec![5], 50)); - - System::set_block_number(5); - - let election_weight = Elections::on_initialize(System::block_number()); - let expected_weight: Weight = <() as WeightInfo>::election(2, 2, 2); - - assert_eq!(expected_weight, election_weight); - }) - } } From 482dde3cfead710233c06fe5aa04b68e296c74fe Mon Sep 17 00:00:00 2001 From: gpestana Date: Thu, 17 Nov 2022 14:45:34 +0000 Subject: [PATCH 19/34] adds pre_solve and post_sove weights --- frame/elections/src/weights.rs | 101 +++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/frame/elections/src/weights.rs b/frame/elections/src/weights.rs index 07869852cc761..c1233a207744a 100644 --- a/frame/elections/src/weights.rs +++ b/frame/elections/src/weights.rs @@ -58,11 +58,8 @@ pub trait WeightInfo { fn remove_member_without_replacement() -> Weight; fn remove_member_with_replacement() -> Weight; fn clean_defunct_voters(v: u32, d: u32, ) -> Weight; - fn election(c: u32, v: u32, e: u32, ) -> Weight; - - // TODO(gpestana): generate from benchmarks - fn pre_election(c: u32, v: u32, e: u32) -> Weight; - fn post_election(c: u32, v: u32, e: u32) -> Weight; + fn pre_solve_election(c: u32, v: u32, e: u32, ) -> Weight; + fn post_solve_election(c: u32, v: u32, e: u32, ) -> Weight; } /// Weights for pallet_elections using the Substrate node and recommended hardware. @@ -192,39 +189,48 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads((3 as u64).saturating_mul(v as u64))) .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(v as u64))) } - // Storage: Elections Candidates (r:1 w:1) + // Storage: Elections Candidates (r:1 w:0) + // Storage: Elections Members (r:1 w:0) + // Storage: Elections RunnersUp (r:1 w:0) + // Storage: Elections Voting (r:10001 w:0) + /// The range of component `c` is `[1, 1000]`. + /// The range of component `v` is `[1, 10000]`. + /// The range of component `e` is `[10000, 160000]`. + fn pre_solve_election(_c: u32, v: u32, e: u32, ) -> Weight { + // Minimum execution time: 6_399_000 nanoseconds. + Weight::from_ref_time(1_581_352_360 as u64) + // Standard Error: 55_251 + .saturating_add(Weight::from_ref_time(8_030_872 as u64).saturating_mul(v as u64)) + // Standard Error: 3_683 + .saturating_add(Weight::from_ref_time(13_203 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(296 as u64)) + .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(v as u64))) + } // Storage: Elections Members (r:1 w:1) // Storage: Elections RunnersUp (r:1 w:1) - // Storage: Elections Voting (r:10001 w:0) // Storage: Council Proposals (r:1 w:0) // Storage: Elections ElectionRounds (r:1 w:1) + // Storage: Elections Candidates (r:0 w:1) // Storage: Council Members (r:0 w:1) // Storage: Council Prime (r:0 w:1) // Storage: System Account (r:1 w:1) /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn election(c: u32, v: u32, e: u32, ) -> Weight { - // Minimum execution time: 22_034_317 nanoseconds. - Weight::from_ref_time(22_110_020_000 as u64) - // Standard Error: 235_528 - .saturating_add(Weight::from_ref_time(25_553_585 as u64).saturating_mul(v as u64)) - // Standard Error: 15_114 - .saturating_add(Weight::from_ref_time(1_032_330 as u64).saturating_mul(e as u64)) - .saturating_add(T::DbWeight::get().reads(280 as u64)) + fn post_solve_election(c: u32, v: u32, e: u32, ) -> Weight { + // Minimum execution time: 730_000 nanoseconds. + Weight::from_ref_time(747_000_000 as u64) + // Standard Error: 50_403 + .saturating_add(Weight::from_ref_time(12_670_099 as u64).saturating_mul(c as u64)) + // Standard Error: 5_039 + .saturating_add(Weight::from_ref_time(342_861 as u64).saturating_mul(v as u64)) + // Standard Error: 323 + .saturating_add(Weight::from_ref_time(127 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(4 as u64)) .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(c as u64))) - .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(v as u64))) .saturating_add(T::DbWeight::get().writes(6 as u64)) .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(c as u64))) } - - // TODO(gpestana): generate from benchmarks - fn pre_election(_c: u32, _v: u32, _e: u32) -> Weight { - Weight::zero() - } - fn post_election(_c: u32, _v: u32, _e: u32) -> Weight { - Weight::zero() - } } // For backwards compatibility and tests @@ -353,37 +359,46 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads((3 as u64).saturating_mul(v as u64))) .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(v as u64))) } - // Storage: Elections Candidates (r:1 w:1) + // Storage: Elections Candidates (r:1 w:0) + // Storage: Elections Members (r:1 w:0) + // Storage: Elections RunnersUp (r:1 w:0) + // Storage: Elections Voting (r:10001 w:0) + /// The range of component `c` is `[1, 1000]`. + /// The range of component `v` is `[1, 10000]`. + /// The range of component `e` is `[10000, 160000]`. + fn pre_solve_election(_c: u32, v: u32, e: u32, ) -> Weight { + // Minimum execution time: 6_399_000 nanoseconds. + Weight::from_ref_time(1_581_352_360 as u64) + // Standard Error: 55_251 + .saturating_add(Weight::from_ref_time(8_030_872 as u64).saturating_mul(v as u64)) + // Standard Error: 3_683 + .saturating_add(Weight::from_ref_time(13_203 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(296 as u64)) + .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(v as u64))) + } // Storage: Elections Members (r:1 w:1) // Storage: Elections RunnersUp (r:1 w:1) - // Storage: Elections Voting (r:10001 w:0) // Storage: Council Proposals (r:1 w:0) // Storage: Elections ElectionRounds (r:1 w:1) + // Storage: Elections Candidates (r:0 w:1) // Storage: Council Members (r:0 w:1) // Storage: Council Prime (r:0 w:1) // Storage: System Account (r:1 w:1) /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn election(c: u32, v: u32, e: u32, ) -> Weight { - // Minimum execution time: 22_034_317 nanoseconds. - Weight::from_ref_time(22_110_020_000 as u64) - // Standard Error: 235_528 - .saturating_add(Weight::from_ref_time(25_553_585 as u64).saturating_mul(v as u64)) - // Standard Error: 15_114 - .saturating_add(Weight::from_ref_time(1_032_330 as u64).saturating_mul(e as u64)) - .saturating_add(RocksDbWeight::get().reads(280 as u64)) + fn post_solve_election(c: u32, v: u32, e: u32, ) -> Weight { + // Minimum execution time: 730_000 nanoseconds. + Weight::from_ref_time(747_000_000 as u64) + // Standard Error: 50_403 + .saturating_add(Weight::from_ref_time(12_670_099 as u64).saturating_mul(c as u64)) + // Standard Error: 5_039 + .saturating_add(Weight::from_ref_time(342_861 as u64).saturating_mul(v as u64)) + // Standard Error: 323 + .saturating_add(Weight::from_ref_time(127 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(4 as u64)) .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(c as u64))) - .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(v as u64))) .saturating_add(RocksDbWeight::get().writes(6 as u64)) .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(c as u64))) } - - // TODO(gpestana): generate from benchmarks - fn pre_election(_c: u32, _v: u32, _e: u32) -> Weight { - Weight::zero() - } - fn post_election(_c: u32, _v: u32, _e: u32) -> Weight { - Weight::zero() - } } From 9749d122d7c820298682956b274a2ac163f0a4df Mon Sep 17 00:00:00 2001 From: gpestana Date: Sun, 20 Nov 2022 14:47:03 +0000 Subject: [PATCH 20/34] Adds comments on election pallet id param name change --- bin/node/runtime/src/lib.rs | 3 +++ frame/elections/src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 16522bd589af7..23b0e79a4e70e 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1000,6 +1000,9 @@ parameter_types! { pub const DesiredRunnersUp: u32 = 7; pub const MaxVoters: u32 = 10 * 1000; pub const MaxCandidates: u32 = 1000; + // The ElectionsPalletId parameter name was changed along with the renaming of the elections + // pallet, but we keep the same lock ID to prevent a migration from current runtimes. + // Related to https://github.com/paritytech/substrate/issues/8250 pub const ElectionsPalletId: LockIdentifier = *b"phrelect"; } diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index a4863bcc892df..fcf3c0b76bc68 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -1337,7 +1337,7 @@ mod tests { } parameter_types! { - pub const ElectionsPalletId: LockIdentifier = *b"elects__"; + pub const ElectionsPalletId: LockIdentifier = *b"phrelect"; pub const MaxVoters: u32 = 1000; pub const MaxCandidates: u32 = 100; } From 26f984857b748a2588aa42294634eb802ae470d7 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 22 Nov 2022 02:54:18 +0000 Subject: [PATCH 21/34] ".git/.scripts/bench-bot.sh" pallet dev pallet_elections --- frame/elections/src/weights.rs | 309 ++++++++++++++++----------------- 1 file changed, 151 insertions(+), 158 deletions(-) diff --git a/frame/elections/src/weights.rs b/frame/elections/src/weights.rs index c1233a207744a..8caa93f0aa8cd 100644 --- a/frame/elections/src/weights.rs +++ b/frame/elections/src/weights.rs @@ -18,24 +18,25 @@ //! Autogenerated weights for pallet_elections //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `bm2`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! DATE: 2022-11-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/substrate +// /home/benchbot/cargo_target_dir/production/substrate // benchmark // pallet -// --chain=dev // --steps=50 // --repeat=20 -// --pallet=pallet_elections // --extrinsic=* // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./frame/elections-phragmen/src/weights.rs +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/substrate/.git/.artifacts/bench.json +// --pallet=pallet_elections +// --chain=dev // --header=./HEADER-APACHE2 +// --output=./frame/elections/src/weights.rs // --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -72,12 +73,12 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) /// The range of component `v` is `[1, 16]`. fn vote_equal(v: u32, ) -> Weight { - // Minimum execution time: 38_496 nanoseconds. - Weight::from_ref_time(39_424_348 as u64) - // Standard Error: 3_547 - .saturating_add(Weight::from_ref_time(119_971 as u64).saturating_mul(v as u64)) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + // Minimum execution time: 37_500 nanoseconds. + Weight::from_ref_time(38_575_649) + // Standard Error: 2_961 + .saturating_add(Weight::from_ref_time(154_225).saturating_mul(v.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: Elections Candidates (r:1 w:0) // Storage: Elections Members (r:1 w:0) @@ -86,12 +87,12 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) /// The range of component `v` is `[2, 16]`. fn vote_more(v: u32, ) -> Weight { - // Minimum execution time: 49_459 nanoseconds. - Weight::from_ref_time(50_225_486 as u64) - // Standard Error: 3_160 - .saturating_add(Weight::from_ref_time(170_360 as u64).saturating_mul(v as u64)) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + // Minimum execution time: 48_836 nanoseconds. + Weight::from_ref_time(49_566_969) + // Standard Error: 3_258 + .saturating_add(Weight::from_ref_time(153_342).saturating_mul(v.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: Elections Candidates (r:1 w:0) // Storage: Elections Members (r:1 w:0) @@ -100,42 +101,42 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) /// The range of component `v` is `[2, 16]`. fn vote_less(v: u32, ) -> Weight { - // Minimum execution time: 48_712 nanoseconds. - Weight::from_ref_time(49_463_298 as u64) - // Standard Error: 2_678 - .saturating_add(Weight::from_ref_time(231_771 as u64).saturating_mul(v as u64)) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + // Minimum execution time: 47_664 nanoseconds. + Weight::from_ref_time(48_768_157) + // Standard Error: 3_321 + .saturating_add(Weight::from_ref_time(215_112).saturating_mul(v.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: Elections Voting (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn remove_voter() -> Weight { - // Minimum execution time: 48_359 nanoseconds. - Weight::from_ref_time(48_767_000 as u64) - .saturating_add(T::DbWeight::get().reads(2 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + // Minimum execution time: 47_146 nanoseconds. + Weight::from_ref_time(47_846_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: Elections Candidates (r:1 w:1) // Storage: Elections Members (r:1 w:0) // Storage: Elections RunnersUp (r:1 w:0) /// The range of component `c` is `[1, 1000]`. fn submit_candidacy(c: u32, ) -> Weight { - // Minimum execution time: 43_369 nanoseconds. - Weight::from_ref_time(49_587_113 as u64) - // Standard Error: 1_008 - .saturating_add(Weight::from_ref_time(77_752 as u64).saturating_mul(c as u64)) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + // Minimum execution time: 42_799 nanoseconds. + Weight::from_ref_time(46_920_164) + // Standard Error: 780 + .saturating_add(Weight::from_ref_time(81_672).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Elections Candidates (r:1 w:1) /// The range of component `c` is `[1, 1000]`. fn renounce_candidacy_candidate(c: u32, ) -> Weight { - // Minimum execution time: 41_321 nanoseconds. - Weight::from_ref_time(50_803_289 as u64) - // Standard Error: 1_159 - .saturating_add(Weight::from_ref_time(57_239 as u64).saturating_mul(c as u64)) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + // Minimum execution time: 40_946 nanoseconds. + Weight::from_ref_time(53_109_738) + // Standard Error: 1_220 + .saturating_add(Weight::from_ref_time(60_643).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Elections Members (r:1 w:1) // Storage: Elections RunnersUp (r:1 w:1) @@ -143,22 +144,22 @@ impl WeightInfo for SubstrateWeight { // Storage: Council Proposals (r:1 w:0) // Storage: Council Members (r:0 w:1) fn renounce_candidacy_members() -> Weight { - // Minimum execution time: 53_542 nanoseconds. - Weight::from_ref_time(54_481_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(4 as u64)) + // Minimum execution time: 53_454 nanoseconds. + Weight::from_ref_time(53_921_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) } // Storage: Elections RunnersUp (r:1 w:1) fn renounce_candidacy_runners_up() -> Weight { - // Minimum execution time: 41_825 nanoseconds. - Weight::from_ref_time(42_248_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + // Minimum execution time: 41_275 nanoseconds. + Weight::from_ref_time(42_444_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Benchmark Override (r:0 w:0) fn remove_member_without_replacement() -> Weight { // Minimum execution time: 2_000_000_000 nanoseconds. - Weight::from_ref_time(2_000_000_000_000 as u64) + Weight::from_ref_time(2_000_000_000_000) } // Storage: Elections Members (r:1 w:1) // Storage: System Account (r:1 w:1) @@ -167,10 +168,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Council Proposals (r:1 w:0) // Storage: Council Members (r:0 w:1) fn remove_member_with_replacement() -> Weight { - // Minimum execution time: 62_600 nanoseconds. - Weight::from_ref_time(63_152_000 as u64) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Minimum execution time: 62_040 nanoseconds. + Weight::from_ref_time(62_569_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(5)) } // Storage: Elections Voting (r:5001 w:5000) // Storage: Elections Members (r:1 w:0) @@ -181,13 +182,13 @@ impl WeightInfo for SubstrateWeight { /// The range of component `v` is `[5000, 10000]`. /// The range of component `d` is `[0, 5000]`. fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight { - // Minimum execution time: 297_149_264 nanoseconds. - Weight::from_ref_time(297_898_499_000 as u64) - // Standard Error: 263_819 - .saturating_add(Weight::from_ref_time(37_914_985 as u64).saturating_mul(v as u64)) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().reads((3 as u64).saturating_mul(v as u64))) - .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(v as u64))) + // Minimum execution time: 298_212_195 nanoseconds. + Weight::from_ref_time(298_678_889_000) + // Standard Error: 264_713 + .saturating_add(Weight::from_ref_time(38_222_955).saturating_mul(v.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(v.into()))) + .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(v.into()))) } // Storage: Elections Candidates (r:1 w:0) // Storage: Elections Members (r:1 w:0) @@ -196,15 +197,13 @@ impl WeightInfo for SubstrateWeight { /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn pre_solve_election(_c: u32, v: u32, e: u32, ) -> Weight { - // Minimum execution time: 6_399_000 nanoseconds. - Weight::from_ref_time(1_581_352_360 as u64) - // Standard Error: 55_251 - .saturating_add(Weight::from_ref_time(8_030_872 as u64).saturating_mul(v as u64)) - // Standard Error: 3_683 - .saturating_add(Weight::from_ref_time(13_203 as u64).saturating_mul(e as u64)) - .saturating_add(T::DbWeight::get().reads(296 as u64)) - .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(v as u64))) + fn pre_solve_election(_c: u32, v: u32, _e: u32, ) -> Weight { + // Minimum execution time: 6_543_626 nanoseconds. + Weight::from_ref_time(6_627_885_000) + // Standard Error: 14_605 + .saturating_add(Weight::from_ref_time(7_613_226).saturating_mul(v.into())) + .saturating_add(T::DbWeight::get().reads(296)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(v.into()))) } // Storage: Elections Members (r:1 w:1) // Storage: Elections RunnersUp (r:1 w:1) @@ -217,19 +216,17 @@ impl WeightInfo for SubstrateWeight { /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn post_solve_election(c: u32, v: u32, e: u32, ) -> Weight { - // Minimum execution time: 730_000 nanoseconds. - Weight::from_ref_time(747_000_000 as u64) - // Standard Error: 50_403 - .saturating_add(Weight::from_ref_time(12_670_099 as u64).saturating_mul(c as u64)) - // Standard Error: 5_039 - .saturating_add(Weight::from_ref_time(342_861 as u64).saturating_mul(v as u64)) - // Standard Error: 323 - .saturating_add(Weight::from_ref_time(127 as u64).saturating_mul(e as u64)) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(c as u64))) - .saturating_add(T::DbWeight::get().writes(6 as u64)) - .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(c as u64))) + fn post_solve_election(c: u32, v: u32, _e: u32, ) -> Weight { + // Minimum execution time: 3_843_566 nanoseconds. + Weight::from_ref_time(3_854_020_000) + // Standard Error: 59_766 + .saturating_add(Weight::from_ref_time(9_622_797).saturating_mul(c.into())) + // Standard Error: 5_975 + .saturating_add(Weight::from_ref_time(541_471).saturating_mul(v.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(6)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) } } @@ -242,12 +239,12 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) /// The range of component `v` is `[1, 16]`. fn vote_equal(v: u32, ) -> Weight { - // Minimum execution time: 38_496 nanoseconds. - Weight::from_ref_time(39_424_348 as u64) - // Standard Error: 3_547 - .saturating_add(Weight::from_ref_time(119_971 as u64).saturating_mul(v as u64)) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + // Minimum execution time: 37_500 nanoseconds. + Weight::from_ref_time(38_575_649) + // Standard Error: 2_961 + .saturating_add(Weight::from_ref_time(154_225).saturating_mul(v.into())) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: Elections Candidates (r:1 w:0) // Storage: Elections Members (r:1 w:0) @@ -256,12 +253,12 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) /// The range of component `v` is `[2, 16]`. fn vote_more(v: u32, ) -> Weight { - // Minimum execution time: 49_459 nanoseconds. - Weight::from_ref_time(50_225_486 as u64) - // Standard Error: 3_160 - .saturating_add(Weight::from_ref_time(170_360 as u64).saturating_mul(v as u64)) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + // Minimum execution time: 48_836 nanoseconds. + Weight::from_ref_time(49_566_969) + // Standard Error: 3_258 + .saturating_add(Weight::from_ref_time(153_342).saturating_mul(v.into())) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: Elections Candidates (r:1 w:0) // Storage: Elections Members (r:1 w:0) @@ -270,42 +267,42 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) /// The range of component `v` is `[2, 16]`. fn vote_less(v: u32, ) -> Weight { - // Minimum execution time: 48_712 nanoseconds. - Weight::from_ref_time(49_463_298 as u64) - // Standard Error: 2_678 - .saturating_add(Weight::from_ref_time(231_771 as u64).saturating_mul(v as u64)) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + // Minimum execution time: 47_664 nanoseconds. + Weight::from_ref_time(48_768_157) + // Standard Error: 3_321 + .saturating_add(Weight::from_ref_time(215_112).saturating_mul(v.into())) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: Elections Voting (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn remove_voter() -> Weight { - // Minimum execution time: 48_359 nanoseconds. - Weight::from_ref_time(48_767_000 as u64) - .saturating_add(RocksDbWeight::get().reads(2 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + // Minimum execution time: 47_146 nanoseconds. + Weight::from_ref_time(47_846_000) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: Elections Candidates (r:1 w:1) // Storage: Elections Members (r:1 w:0) // Storage: Elections RunnersUp (r:1 w:0) /// The range of component `c` is `[1, 1000]`. fn submit_candidacy(c: u32, ) -> Weight { - // Minimum execution time: 43_369 nanoseconds. - Weight::from_ref_time(49_587_113 as u64) - // Standard Error: 1_008 - .saturating_add(Weight::from_ref_time(77_752 as u64).saturating_mul(c as u64)) - .saturating_add(RocksDbWeight::get().reads(3 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + // Minimum execution time: 42_799 nanoseconds. + Weight::from_ref_time(46_920_164) + // Standard Error: 780 + .saturating_add(Weight::from_ref_time(81_672).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Elections Candidates (r:1 w:1) /// The range of component `c` is `[1, 1000]`. fn renounce_candidacy_candidate(c: u32, ) -> Weight { - // Minimum execution time: 41_321 nanoseconds. - Weight::from_ref_time(50_803_289 as u64) - // Standard Error: 1_159 - .saturating_add(Weight::from_ref_time(57_239 as u64).saturating_mul(c as u64)) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + // Minimum execution time: 40_946 nanoseconds. + Weight::from_ref_time(53_109_738) + // Standard Error: 1_220 + .saturating_add(Weight::from_ref_time(60_643).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Elections Members (r:1 w:1) // Storage: Elections RunnersUp (r:1 w:1) @@ -313,22 +310,22 @@ impl WeightInfo for () { // Storage: Council Proposals (r:1 w:0) // Storage: Council Members (r:0 w:1) fn renounce_candidacy_members() -> Weight { - // Minimum execution time: 53_542 nanoseconds. - Weight::from_ref_time(54_481_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(4 as u64)) + // Minimum execution time: 53_454 nanoseconds. + Weight::from_ref_time(53_921_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(4)) } // Storage: Elections RunnersUp (r:1 w:1) fn renounce_candidacy_runners_up() -> Weight { - // Minimum execution time: 41_825 nanoseconds. - Weight::from_ref_time(42_248_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + // Minimum execution time: 41_275 nanoseconds. + Weight::from_ref_time(42_444_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Benchmark Override (r:0 w:0) fn remove_member_without_replacement() -> Weight { // Minimum execution time: 2_000_000_000 nanoseconds. - Weight::from_ref_time(2_000_000_000_000 as u64) + Weight::from_ref_time(2_000_000_000_000) } // Storage: Elections Members (r:1 w:1) // Storage: System Account (r:1 w:1) @@ -337,10 +334,10 @@ impl WeightInfo for () { // Storage: Council Proposals (r:1 w:0) // Storage: Council Members (r:0 w:1) fn remove_member_with_replacement() -> Weight { - // Minimum execution time: 62_600 nanoseconds. - Weight::from_ref_time(63_152_000 as u64) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(5 as u64)) + // Minimum execution time: 62_040 nanoseconds. + Weight::from_ref_time(62_569_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(5)) } // Storage: Elections Voting (r:5001 w:5000) // Storage: Elections Members (r:1 w:0) @@ -351,13 +348,13 @@ impl WeightInfo for () { /// The range of component `v` is `[5000, 10000]`. /// The range of component `d` is `[0, 5000]`. fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight { - // Minimum execution time: 297_149_264 nanoseconds. - Weight::from_ref_time(297_898_499_000 as u64) - // Standard Error: 263_819 - .saturating_add(Weight::from_ref_time(37_914_985 as u64).saturating_mul(v as u64)) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().reads((3 as u64).saturating_mul(v as u64))) - .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(v as u64))) + // Minimum execution time: 298_212_195 nanoseconds. + Weight::from_ref_time(298_678_889_000) + // Standard Error: 264_713 + .saturating_add(Weight::from_ref_time(38_222_955).saturating_mul(v.into())) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(v.into()))) + .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(v.into()))) } // Storage: Elections Candidates (r:1 w:0) // Storage: Elections Members (r:1 w:0) @@ -366,15 +363,13 @@ impl WeightInfo for () { /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn pre_solve_election(_c: u32, v: u32, e: u32, ) -> Weight { - // Minimum execution time: 6_399_000 nanoseconds. - Weight::from_ref_time(1_581_352_360 as u64) - // Standard Error: 55_251 - .saturating_add(Weight::from_ref_time(8_030_872 as u64).saturating_mul(v as u64)) - // Standard Error: 3_683 - .saturating_add(Weight::from_ref_time(13_203 as u64).saturating_mul(e as u64)) - .saturating_add(RocksDbWeight::get().reads(296 as u64)) - .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(v as u64))) + fn pre_solve_election(_c: u32, v: u32, _e: u32, ) -> Weight { + // Minimum execution time: 6_543_626 nanoseconds. + Weight::from_ref_time(6_627_885_000) + // Standard Error: 14_605 + .saturating_add(Weight::from_ref_time(7_613_226).saturating_mul(v.into())) + .saturating_add(RocksDbWeight::get().reads(296)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(v.into()))) } // Storage: Elections Members (r:1 w:1) // Storage: Elections RunnersUp (r:1 w:1) @@ -387,18 +382,16 @@ impl WeightInfo for () { /// The range of component `c` is `[1, 1000]`. /// The range of component `v` is `[1, 10000]`. /// The range of component `e` is `[10000, 160000]`. - fn post_solve_election(c: u32, v: u32, e: u32, ) -> Weight { - // Minimum execution time: 730_000 nanoseconds. - Weight::from_ref_time(747_000_000 as u64) - // Standard Error: 50_403 - .saturating_add(Weight::from_ref_time(12_670_099 as u64).saturating_mul(c as u64)) - // Standard Error: 5_039 - .saturating_add(Weight::from_ref_time(342_861 as u64).saturating_mul(v as u64)) - // Standard Error: 323 - .saturating_add(Weight::from_ref_time(127 as u64).saturating_mul(e as u64)) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(c as u64))) - .saturating_add(RocksDbWeight::get().writes(6 as u64)) - .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(c as u64))) + fn post_solve_election(c: u32, v: u32, _e: u32, ) -> Weight { + // Minimum execution time: 3_843_566 nanoseconds. + Weight::from_ref_time(3_854_020_000) + // Standard Error: 59_766 + .saturating_add(Weight::from_ref_time(9_622_797).saturating_mul(c.into())) + // Standard Error: 5_975 + .saturating_add(Weight::from_ref_time(541_471).saturating_mul(v.into())) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(6)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) } } From afce2d20308da968beceac6d15bc62706eb20083 Mon Sep 17 00:00:00 2001 From: gpestana Date: Tue, 22 Nov 2022 22:34:57 +0000 Subject: [PATCH 22/34] Finishes pre-post solve weights --- frame/elections/src/lib.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index fcf3c0b76bc68..440704b6637a6 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -964,16 +964,20 @@ impl Pallet { Self::deposit_event(Event::ElectionError); }); - let pre_and_election_weight = - T::ElectionSolver::weight::(num_voters, num_candidates, num_edges) - .saturating_add(Weight::zero()); // replace with weights::pre_solve_election_weight(); - - if let Ok(winners) = election_result { - Self::do_post_solve_election(winners, candidates_and_deposit, voters_and_stakes) - .saturating_add(pre_and_election_weight) + let post_election_weight = if let Ok(winners) = election_result { + Self::do_post_solve_election(winners, candidates_and_deposit, voters_and_stakes); + T::WeightInfo::post_solve_election(num_candidates, num_voters, num_edges) } else { - pre_and_election_weight - } + Weight::zero() + }; + + T::ElectionSolver::weight::(num_candidates, num_voters, num_edges) + .saturating_add(T::WeightInfo::pre_solve_election( + num_candidates, + num_voters, + num_edges, + )) + .saturating_add(post_election_weight) } fn do_pre_solve_election() -> Result, Error> { @@ -1039,7 +1043,7 @@ impl Pallet { winners: Vec<(T::AccountId, u128)>, candidates_and_deposit: Vec<(T::AccountId, BalanceOf)>, voters_and_stakes: Vec<(T::AccountId, BalanceOf, Vec)>, - ) -> Weight { + ) { let desired_seats = T::DesiredMembers::get() as usize; let total_issuance = T::Currency::total_issuance(); let to_balance = |e: ExtendedBalance| T::CurrencyToVote::to_currency(e, total_issuance); @@ -1165,9 +1169,6 @@ impl Pallet { log!(info, "New term election successful."); Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id }); >::mutate(|v| *v += 1); - - // TODO(gpestana): return the weight::post_solve_weight - Weight::zero() } } From 42083756a362fd35fe5140fab16376c42791a228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Tue, 29 Nov 2022 10:25:09 +0000 Subject: [PATCH 23/34] Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/elections/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 440704b6637a6..0d00aad5c4473 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -929,7 +929,7 @@ impl Pallet { num_edges, } = match Self::do_pre_solve_election() { Ok(results) => results, - Err(event) => match event { + Err(err) => match err { Error::EmptyTerm => { Self::deposit_event(Event::EmptyTerm); return T::DbWeight::get().reads(3) From 85e5a70745c88e063e857f61ba8c7d24716fa795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Tue, 29 Nov 2022 10:25:29 +0000 Subject: [PATCH 24/34] Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/elections/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 0d00aad5c4473..9d9c9a27f3969 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -948,7 +948,7 @@ impl Pallet { let num_voters = voters_and_votes.len() as u32; let num_edges = num_edges; - let election_result = + let election_winners = T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes) .map( |ElectionResult::< From 443f73db4f57d82d4cd170ef94f8d9f2da194260 Mon Sep 17 00:00:00 2001 From: gpestana Date: Tue, 29 Nov 2022 11:13:48 +0000 Subject: [PATCH 25/34] Addresses PR comments: no panic in on_init path; nits --- frame/elections/src/lib.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 9d9c9a27f3969..ba29b6bf4e812 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -940,7 +940,11 @@ impl Pallet { let max_voters = ::MaxVoters::get() as usize; return T::DbWeight::get().reads(3 + max_voters as u64) }, - _ => unreachable!("should not happen"), + _ => { + log!(error, "Unexpected pre-election error",); + let max_voters = ::MaxVoters::get() as usize; + return T::DbWeight::get().reads(3 + max_voters as u64) + }, }, }; @@ -964,7 +968,7 @@ impl Pallet { Self::deposit_event(Event::ElectionError); }); - let post_election_weight = if let Ok(winners) = election_result { + let post_election_weight = if let Ok(winners) = election_winners { Self::do_post_solve_election(winners, candidates_and_deposit, voters_and_stakes); T::WeightInfo::post_solve_election(num_candidates, num_voters, num_edges) } else { @@ -1007,17 +1011,14 @@ impl Pallet { // used for prime election. let mut voters_and_stakes = Vec::new(); - match Voting::::iter().try_for_each(|(voter, Voter { stake, votes, .. })| { + Voting::::iter().try_for_each(|(voter, Voter { stake, votes, .. })| { if voters_and_stakes.len() < max_voters { voters_and_stakes.push((voter, stake, votes)); Ok(()) } else { - Err(()) + Err(Error::TooManyVotes) } - }) { - Ok(_) => (), - Err(_) => return Err(Error::TooManyVotes), - } + })?; // used for elections. let voters_and_votes = voters_and_stakes @@ -1051,7 +1052,7 @@ impl Pallet { // this is already sorted by id. let old_members_ids_sorted = >::take().into_iter().map(|m| m.who).collect::>(); - // this one needs a sort by id. + // this one needs sorted by id. let mut old_runners_up_ids_sorted = >::take().into_iter().map(|r| r.who).collect::>(); old_runners_up_ids_sorted.sort(); From 321b654c8473bbc27e5ee65c7b1d29bb9cee3065 Mon Sep 17 00:00:00 2001 From: gpestana Date: Thu, 12 Jan 2023 14:48:02 +0100 Subject: [PATCH 26/34] Fixes node build --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index b2b4e3470478e..d59f4eafa55e9 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1012,7 +1012,7 @@ parameter_types! { // The ElectionsPalletId parameter name was changed along with the renaming of the elections // pallet, but we keep the same lock ID to prevent a migration from current runtimes. // Related to https://github.com/paritytech/substrate/issues/8250 - pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect"; + pub const ElectionsPalletId: LockIdentifier = *b"phrelect"; } // Make sure that there are no more than `MaxMembers` members elected via elections-phragmen. From 5343a6cf76967706284de0b28d1e83b06b92a02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Fri, 17 Feb 2023 16:17:21 +0000 Subject: [PATCH 27/34] Implements approval voting to use as a `NposSolver` (#13367) * Implements the approval voting methods in sp_npos_elections --- bin/node/runtime/src/lib.rs | 4 +- .../benchmarking/src/lib.rs | 15 +++- frame/election-provider-support/src/lib.rs | 23 ++++++ .../election-provider-support/src/onchain.rs | 30 ++++++- .../election-provider-support/src/weights.rs | 8 ++ frame/elections/src/lib.rs | 4 +- .../npos-elections/src/approval_voting.rs | 78 +++++++++++++++++++ primitives/npos-elections/src/lib.rs | 4 + primitives/npos-elections/src/phragmen.rs | 2 +- primitives/npos-elections/src/tests.rs | 49 +++++++++++- 10 files changed, 208 insertions(+), 9 deletions(-) create mode 100644 primitives/npos-elections/src/approval_voting.rs diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index fca33d20760e2..5705c413af48c 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -25,7 +25,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_election_provider_support::{ onchain, weights::SubstrateWeight, BalancingConfig, ElectionDataProvider, SequentialPhragmen, - VoteWeight, + VoteWeight, ApprovalVoting, }; use frame_support::{ construct_runtime, @@ -1037,7 +1037,7 @@ impl pallet_elections::Config for Runtime { type MaxVoters = MaxVoters; type MaxVotesPerVoter = MaxVotesPerVoter; type MaxCandidates = MaxCandidates; - type ElectionSolver = SequentialPhragmen; + type ElectionSolver = ApprovalVoting; type SolverWeightInfo = SubstrateWeight; type WeightInfo = pallet_elections::weights::SubstrateWeight; } diff --git a/frame/election-provider-support/benchmarking/src/lib.rs b/frame/election-provider-support/benchmarking/src/lib.rs index 5323513da98d5..7f27cf7521032 100644 --- a/frame/election-provider-support/benchmarking/src/lib.rs +++ b/frame/election-provider-support/benchmarking/src/lib.rs @@ -23,7 +23,7 @@ use codec::Decode; use frame_benchmarking::v1::{benchmarks, Vec}; -use frame_election_provider_support::{NposSolver, PhragMMS, SequentialPhragmen}; +use frame_election_provider_support::{ApprovalVoting, NposSolver, PhragMMS, SequentialPhragmen}; pub struct Pallet(frame_system::Pallet); pub trait Config: frame_system::Config {} @@ -88,4 +88,17 @@ benchmarks! { ::solve(d as usize, targets, voters).is_ok() ); } + + approval_voting { + let v in (VOTERS[0]) .. VOTERS[1]; + let t in (TARGETS[0]) .. TARGETS[1]; + let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1]; + + let (voters, targets) = set_up_voters_targets::(v, t, d as usize); + }: { + assert!( + ApprovalVoting:: + ::solve(d as usize, targets, voters).is_ok() + ); + } } diff --git a/frame/election-provider-support/src/lib.rs b/frame/election-provider-support/src/lib.rs index 9e60eb3be1a6f..14018949e6da3 100644 --- a/frame/election-provider-support/src/lib.rs +++ b/frame/election-provider-support/src/lib.rs @@ -660,6 +660,29 @@ impl(sp_std::marker::PhantomData<(AccountId, Accuracy)>); + +impl NposSolver + for ApprovalVoting +{ + type AccountId = AccountId; + type Accuracy = Accuracy; + type Error = sp_npos_elections::Error; + fn solve( + winners: usize, + targets: Vec, + voters: Vec<(Self::AccountId, VoteWeight, impl IntoIterator)>, + ) -> Result, Self::Error> { + sp_npos_elections::approval_voting(winners, targets, voters) + } + + fn weight(voters: u32, targets: u32, vote_degree: u32) -> Weight { + T::approval_voting(voters, targets, vote_degree) + } +} + /// A voter, at the level of abstraction of this crate. pub type Voter = (AccountId, VoteWeight, BoundedVec); diff --git a/frame/election-provider-support/src/onchain.rs b/frame/election-provider-support/src/onchain.rs index 483c402fe249c..6102a1c67f5f3 100644 --- a/frame/election-provider-support/src/onchain.rs +++ b/frame/election-provider-support/src/onchain.rs @@ -185,7 +185,7 @@ impl ElectionProvider for OnChainExecution { #[cfg(test)] mod tests { use super::*; - use crate::{ElectionProvider, PhragMMS, SequentialPhragmen}; + use crate::{ApprovalVoting, ElectionProvider, PhragMMS, SequentialPhragmen}; use frame_support::{assert_noop, parameter_types, traits::ConstU32}; use sp_npos_elections::Support; use sp_runtime::Perbill; @@ -235,6 +235,7 @@ mod tests { struct PhragmenParams; struct PhragMMSParams; + struct ApprovalVotingParams; parameter_types! { pub static MaxWinners: u32 = 10; @@ -261,6 +262,16 @@ mod tests { type TargetsBound = ConstU32<400>; } + impl Config for ApprovalVotingParams { + type System = Runtime; + type Solver = ApprovalVoting; + type DataProvider = mock_data_provider::DataProvider; + type WeightInfo = (); + type MaxWinners = MaxWinners; + type VotersBound = ConstU32<600>; + type TargetsBound = ConstU32<400>; + } + mod mock_data_provider { use frame_support::{bounded_vec, traits::ConstU32}; @@ -333,4 +344,21 @@ mod tests { ); }) } + + #[test] + fn onchain_approval_voting_works() { + sp_io::TestExternalities::new_empty().execute_with(|| { + DesiredTargets::set(3); + + // note that the `OnChainExecution::elect` implementation normalizes the vote weights. + assert_eq!( + as ElectionProvider>::elect().unwrap(), + vec![ + (10, Support { total: 20, voters: vec![(1, 5), (3, 15)] }), + (20, Support { total: 15, voters: vec![(1, 5), (2, 10)] }), + (30, Support { total: 25, voters: vec![(2, 10), (3, 15)] }) + ] + ) + }) + } } diff --git a/frame/election-provider-support/src/weights.rs b/frame/election-provider-support/src/weights.rs index 44075ba871228..ad26debf382a1 100644 --- a/frame/election-provider-support/src/weights.rs +++ b/frame/election-provider-support/src/weights.rs @@ -47,6 +47,7 @@ use sp_std::marker::PhantomData; pub trait WeightInfo { fn phragmen(v: u32, t: u32, d: u32, ) -> Weight; fn phragmms(v: u32, t: u32, d: u32, ) -> Weight; + fn approval_voting(v: u32, t: u32, d: u32, ) -> Weight; } /// Weights for pallet_election_provider_support_benchmarking using the Substrate node and recommended hardware. @@ -70,6 +71,10 @@ impl WeightInfo for SubstrateWeight { // Standard Error: 6_649_000 .saturating_add(Weight::from_ref_time(1_711_424_000 as u64).saturating_mul(d as u64)) } + + fn approval_voting(_v: u32, _t: u32, _d: u32, ) -> Weight { + Weight::zero() + } } // For backwards compatibility and tests @@ -92,4 +97,7 @@ impl WeightInfo for () { // Standard Error: 6_649_000 .saturating_add(Weight::from_ref_time(1_711_424_000 as u64).saturating_mul(d as u64)) } + fn approval_voting(_v: u32, _t: u32, _d: u32, ) -> Weight { + Weight::zero() + } } diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 37caa95ce11d8..77e118835771b 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -1285,7 +1285,7 @@ impl ContainsLengthBound for Pallet { mod tests { use super::*; use crate as elections; - use frame_election_provider_support::{weights::SubstrateWeight, SequentialPhragmen}; + use frame_election_provider_support::{weights::SubstrateWeight, ApprovalVoting}; use frame_support::{ assert_noop, assert_ok, dispatch::DispatchResultWithPostInfo, @@ -1419,7 +1419,7 @@ mod tests { type WeightInfo = (); type MaxVoters = MaxVoters; type MaxCandidates = MaxCandidates; - type ElectionSolver = SequentialPhragmen; + type ElectionSolver = ApprovalVoting; type SolverWeightInfo = SubstrateWeight; type MaxVotesPerVoter = ConstU32<16>; } diff --git a/primitives/npos-elections/src/approval_voting.rs b/primitives/npos-elections/src/approval_voting.rs new file mode 100644 index 0000000000000..8c1d496d77f75 --- /dev/null +++ b/primitives/npos-elections/src/approval_voting.rs @@ -0,0 +1,78 @@ +// This file is part of Substrate. + +// Copyright (C) 2023 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Implementation of the approval voting election method. +//! +//! This method allows voters to select many candidates and backing each of them with the same +//! vote weight. The candidates with the most backing are the election winners. + +use crate::{setup_inputs, ElectionResult, IdentifierT, PerThing128, VoteWeight}; +use sp_arithmetic::traits::Zero; +use sp_std::{cmp::Reverse, vec::Vec}; + +/// Execute an approvals voting election scheme. The return type is a list of winners and a weight +/// distribution vector of all voters who contribute to the winners. +/// +/// - The vote assignment distribution for each vote is always 100%, since a voter backs a candidate +/// with its full stake, regardless of how many candidates are backed by the same stake. However, +/// the caller may normalize votes on site if required. +/// - Returning winners are sorted based on desirability. Voters are unsorted. +/// - The returning winners are zipped with their final backing stake. Yet, to get the exact final +/// weight distribution from the winner's point of view, one needs to build a support map. See +/// [`crate::SupportMap`] for more info. Note that this backing stake is computed in +/// ExtendedBalance and may be slightly different that what will be computed from the support map, +/// due to accuracy loss. +/// +/// This can only fail of the normalization fails. This can happen if for any of the resulting +/// assignments, `assignment.distribution.map(|p| p.deconstruct()).sum()` fails to fit inside +/// `UpperOf

`. A user of this crate may statically assert that this can never happen and safely +/// `expect` this to return `Ok`. +pub fn approval_voting( + to_elect: usize, + candidates: Vec, + voters: Vec<(AccountId, VoteWeight, impl IntoIterator)>, +) -> Result, crate::Error> { + let to_elect = to_elect.min(candidates.len()); + + let (mut candidates, mut voters) = setup_inputs(candidates, voters); + + candidates.sort_by_key(|c| Reverse(c.borrow().approval_stake)); + + let winners = candidates + .into_iter() + .take(to_elect) + .map(|w| { + w.borrow_mut().elected = true; + w + }) + .map(|w_ptr| (w_ptr.borrow().who.clone(), w_ptr.borrow().approval_stake)) + .collect(); + + for voter in &mut voters { + for edge in &mut voter.edges { + if edge.candidate.borrow().elected { + edge.weight = voter.budget + } else { + edge.weight = Zero::zero() + } + } + } + + let assignments = voters.into_iter().filter_map(|v| v.into_assignment()).collect::>(); + + Ok(ElectionResult { winners, assignments }) +} diff --git a/primitives/npos-elections/src/lib.rs b/primitives/npos-elections/src/lib.rs index d0c9ed18caddc..5fbbd277cae06 100644 --- a/primitives/npos-elections/src/lib.rs +++ b/primitives/npos-elections/src/lib.rs @@ -24,6 +24,8 @@ //! - [`balance`](balancing::balance): Implements the star balancing algorithm. This iterative //! process can push a solution toward being more "balanced", which in turn can increase its //! score. +//! - [`approval_voting`](approval_voting::approval_voting): Implements an approval voting electoral +//! system where voters can back multiple candidates with the same stake. //! //! ### Terminology //! @@ -89,6 +91,7 @@ mod mock; #[cfg(test)] mod tests; +pub mod approval_voting; mod assignments; pub mod balancing; pub mod helpers; @@ -99,6 +102,7 @@ pub mod pjr; pub mod reduce; pub mod traits; +pub use approval_voting::*; pub use assignments::{Assignment, StakedAssignment}; pub use balancing::*; pub use helpers::*; diff --git a/primitives/npos-elections/src/phragmen.rs b/primitives/npos-elections/src/phragmen.rs index ca32780ed84b4..99c6522bdde77 100644 --- a/primitives/npos-elections/src/phragmen.rs +++ b/primitives/npos-elections/src/phragmen.rs @@ -57,7 +57,7 @@ const DEN: ExtendedBalance = ExtendedBalance::max_value(); /// - The returning weight distribution is _normalized_, meaning that it is guaranteed that the sum /// of the ratios in each voter's distribution sums up to exactly `P::one()`. /// -/// This can only fail of the normalization fails. This can happen if for any of the resulting +/// This can only fail if the normalization fails. This can happen if for any of the resulting /// assignments, `assignment.distribution.map(|p| p.deconstruct()).sum()` fails to fit inside /// `UpperOf

`. A user of this crate may statically assert that this can never happen and safely /// `expect` this to return `Ok`. diff --git a/primitives/npos-elections/src/tests.rs b/primitives/npos-elections/src/tests.rs index 6f2e4fca77115..bd821f2571335 100644 --- a/primitives/npos-elections/src/tests.rs +++ b/primitives/npos-elections/src/tests.rs @@ -18,12 +18,57 @@ //! Tests for npos-elections. use crate::{ - balancing, helpers::*, mock::*, seq_phragmen, seq_phragmen_core, setup_inputs, to_support_map, - Assignment, BalancingConfig, ElectionResult, ExtendedBalance, StakedAssignment, Support, Voter, + approval_voting::*, balancing, helpers::*, mock::*, seq_phragmen, seq_phragmen_core, + setup_inputs, to_support_map, Assignment, BalancingConfig, ElectionResult, ExtendedBalance, + StakedAssignment, Support, Voter, }; use sp_arithmetic::{PerU16, Perbill, Percent, Permill}; use substrate_test_utils::assert_eq_uvec; +#[test] +fn approval_voting_works() { + let candidates = vec![1, 2, 3, 4]; + let voters = vec![(10, vec![1, 2]), (20, vec![1, 2]), (30, vec![1, 2, 3]), (40, vec![4])]; + let stake_of = create_stake_of(&[(10, 10), (20, 20), (30, 30), (40, 40)]); + + let voters = voters + .iter() + .map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone())) + .collect::>(); + + let ElectionResult::<_, Perbill> { winners, assignments } = + approval_voting(3, candidates, voters).unwrap(); + + assert_eq_uvec!(winners, vec![(1, 60), (2, 60), (4, 40)]); + assert_eq_uvec!( + assignments, + vec![ + Assignment { + who: 10u64, + distribution: vec![ + (1, Perbill::from_percent(100)), + (2, Perbill::from_percent(100)) + ] + }, + Assignment { + who: 20u64, + distribution: vec![ + (1, Perbill::from_percent(100)), + (2, Perbill::from_percent(100)) + ] + }, + Assignment { + who: 30u64, + distribution: vec![ + (1, Perbill::from_percent(100)), + (2, Perbill::from_percent(100)) + ] + }, + Assignment { who: 40u64, distribution: vec![(4, Perbill::from_percent(100))] }, + ] + ); +} + #[test] fn float_phragmen_poc_works() { let candidates = vec![1, 2, 3]; From 59900fcba15b0c81bc06715c749a40c30d4dc2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Mon, 20 Feb 2023 04:53:06 +0100 Subject: [PATCH 28/34] fmt --- bin/node/runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 5705c413af48c..973eafe8dda43 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -24,8 +24,8 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_election_provider_support::{ - onchain, weights::SubstrateWeight, BalancingConfig, ElectionDataProvider, SequentialPhragmen, - VoteWeight, ApprovalVoting, + onchain, weights::SubstrateWeight, ApprovalVoting, BalancingConfig, ElectionDataProvider, + SequentialPhragmen, VoteWeight, }; use frame_support::{ construct_runtime, From da3339e4f14bcb563d0aa88772aa8705a5ec02c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Mon, 20 Feb 2023 05:00:47 +0100 Subject: [PATCH 29/34] remove unecessary file --- frame/elections-phragmen/src/weights.rs | 559 ------------------------ 1 file changed, 559 deletions(-) delete mode 100644 frame/elections-phragmen/src/weights.rs diff --git a/frame/elections-phragmen/src/weights.rs b/frame/elections-phragmen/src/weights.rs deleted file mode 100644 index a13dadf210ec0..0000000000000 --- a/frame/elections-phragmen/src/weights.rs +++ /dev/null @@ -1,559 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2023 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Autogenerated weights for pallet_elections_phragmen -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-b3zmxxc-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 - -// Executed Command: -// target/production/substrate -// benchmark -// pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json -// --pallet=pallet_elections_phragmen -// --chain=dev -// --header=./HEADER-APACHE2 -// --output=./frame/elections-phragmen/src/weights.rs -// --template=./.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; - -/// Weight functions needed for pallet_elections_phragmen. -pub trait WeightInfo { - fn vote_equal(v: u32, ) -> Weight; - fn vote_more(v: u32, ) -> Weight; - fn vote_less(v: u32, ) -> Weight; - fn remove_voter() -> Weight; - fn submit_candidacy(c: u32, ) -> Weight; - fn renounce_candidacy_candidate(c: u32, ) -> Weight; - fn renounce_candidacy_members() -> Weight; - fn renounce_candidacy_runners_up() -> Weight; - fn remove_member_without_replacement() -> Weight; - fn remove_member_with_replacement() -> Weight; - fn clean_defunct_voters(v: u32, d: u32, ) -> Weight; - fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight; -} - -/// Weights for pallet_elections_phragmen using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `v` is `[1, 16]`. - fn vote_equal(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `499 + v * (80 ±0)` - // Estimated: `9726 + v * (320 ±0)` - // Minimum execution time: 27_362 nanoseconds. - Weight::from_parts(28_497_963, 9726) - // Standard Error: 3_968 - .saturating_add(Weight::from_ref_time(176_840).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_proof_size(320).saturating_mul(v.into())) - } - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `v` is `[2, 16]`. - fn vote_more(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `467 + v * (80 ±0)` - // Estimated: `9598 + v * (320 ±0)` - // Minimum execution time: 37_120 nanoseconds. - Weight::from_parts(38_455_302, 9598) - // Standard Error: 5_478 - .saturating_add(Weight::from_ref_time(219_678).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_proof_size(320).saturating_mul(v.into())) - } - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `v` is `[2, 16]`. - fn vote_less(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `499 + v * (80 ±0)` - // Estimated: `9726 + v * (320 ±0)` - // Minimum execution time: 36_928 nanoseconds. - Weight::from_parts(38_334_669, 9726) - // Standard Error: 5_271 - .saturating_add(Weight::from_ref_time(232_355).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_proof_size(320).saturating_mul(v.into())) - } - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - fn remove_voter() -> Weight { - // Proof Size summary in bytes: - // Measured: `989` - // Estimated: `7238` - // Minimum execution time: 34_338 nanoseconds. - Weight::from_parts(35_672_000, 7238) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// Storage: Elections Candidates (r:1 w:1) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 64]`. - fn submit_candidacy(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1697 + c * (48 ±0)` - // Estimated: `6576 + c * (144 ±0)` - // Minimum execution time: 31_864 nanoseconds. - Weight::from_parts(33_490_161, 6576) - // Standard Error: 2_643 - .saturating_add(Weight::from_ref_time(158_386).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_proof_size(144).saturating_mul(c.into())) - } - /// Storage: Elections Candidates (r:1 w:1) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 64]`. - fn renounce_candidacy_candidate(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `349 + c * (48 ±0)` - // Estimated: `844 + c * (48 ±0)` - // Minimum execution time: 27_292 nanoseconds. - Weight::from_parts(28_364_955, 844) - // Standard Error: 1_335 - .saturating_add(Weight::from_ref_time(78_086).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_proof_size(48).saturating_mul(c.into())) - } - /// Storage: Elections Members (r:1 w:1) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:1 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - fn renounce_candidacy_members() -> Weight { - // Proof Size summary in bytes: - // Measured: `2027` - // Estimated: `12115` - // Minimum execution time: 45_975 nanoseconds. - Weight::from_parts(47_103_000, 12115) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) - } - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - fn renounce_candidacy_runners_up() -> Weight { - // Proof Size summary in bytes: - // Measured: `975` - // Estimated: `1470` - // Minimum execution time: 29_243 nanoseconds. - Weight::from_parts(30_582_000, 1470) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: Benchmark Override (r:0 w:0) - /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) - fn remove_member_without_replacement() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000_000 nanoseconds. - Weight::from_ref_time(2_000_000_000_000) - } - /// Storage: Elections Members (r:1 w:1) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:1 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - fn remove_member_with_replacement() -> Weight { - // Proof Size summary in bytes: - // Measured: `2027` - // Estimated: `14718` - // Minimum execution time: 52_527 nanoseconds. - Weight::from_parts(53_538_000, 14718) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) - } - /// Storage: Elections Voting (r:513 w:512) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Balances Locks (r:512 w:512) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: System Account (r:512 w:512) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// The range of component `v` is `[256, 512]`. - /// The range of component `d` is `[0, 256]`. - fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1115 + v * (875 ±0)` - // Estimated: `8448 + v * (12352 ±0)` - // Minimum execution time: 14_934_185 nanoseconds. - Weight::from_parts(15_014_057_000, 8448) - // Standard Error: 245_588 - .saturating_add(Weight::from_ref_time(35_586_946).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(v.into()))) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(v.into()))) - .saturating_add(Weight::from_proof_size(12352).saturating_mul(v.into())) - } - /// Storage: Elections Candidates (r:1 w:1) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:1) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:513 w:0) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Account (r:44 w:44) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Elections ElectionRounds (r:1 w:1) - /// Proof Skipped: Elections ElectionRounds (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:0 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 64]`. - /// The range of component `v` is `[1, 512]`. - /// The range of component `e` is `[512, 8192]`. - fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `0 + v * (638 ±0) + e * (28 ±0)` - // Estimated: `330033 + v * (5229 ±6) + e * (89 ±0) + c * (2135 ±7)` - // Minimum execution time: 1_273_671 nanoseconds. - Weight::from_parts(1_279_716_000, 330033) - // Standard Error: 543_277 - .saturating_add(Weight::from_ref_time(20_613_753).saturating_mul(v.into())) - // Standard Error: 34_857 - .saturating_add(Weight::from_ref_time(688_354).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(21_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(v.into()))) - .saturating_add(T::DbWeight::get().writes(6_u64)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) - .saturating_add(Weight::from_proof_size(5229).saturating_mul(v.into())) - .saturating_add(Weight::from_proof_size(89).saturating_mul(e.into())) - .saturating_add(Weight::from_proof_size(2135).saturating_mul(c.into())) - } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `v` is `[1, 16]`. - fn vote_equal(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `499 + v * (80 ±0)` - // Estimated: `9726 + v * (320 ±0)` - // Minimum execution time: 27_362 nanoseconds. - Weight::from_parts(28_497_963, 9726) - // Standard Error: 3_968 - .saturating_add(Weight::from_ref_time(176_840).saturating_mul(v.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_proof_size(320).saturating_mul(v.into())) - } - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `v` is `[2, 16]`. - fn vote_more(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `467 + v * (80 ±0)` - // Estimated: `9598 + v * (320 ±0)` - // Minimum execution time: 37_120 nanoseconds. - Weight::from_parts(38_455_302, 9598) - // Standard Error: 5_478 - .saturating_add(Weight::from_ref_time(219_678).saturating_mul(v.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_proof_size(320).saturating_mul(v.into())) - } - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `v` is `[2, 16]`. - fn vote_less(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `499 + v * (80 ±0)` - // Estimated: `9726 + v * (320 ±0)` - // Minimum execution time: 36_928 nanoseconds. - Weight::from_parts(38_334_669, 9726) - // Standard Error: 5_271 - .saturating_add(Weight::from_ref_time(232_355).saturating_mul(v.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_proof_size(320).saturating_mul(v.into())) - } - /// Storage: Elections Voting (r:1 w:1) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - fn remove_voter() -> Weight { - // Proof Size summary in bytes: - // Measured: `989` - // Estimated: `7238` - // Minimum execution time: 34_338 nanoseconds. - Weight::from_parts(35_672_000, 7238) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// Storage: Elections Candidates (r:1 w:1) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 64]`. - fn submit_candidacy(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1697 + c * (48 ±0)` - // Estimated: `6576 + c * (144 ±0)` - // Minimum execution time: 31_864 nanoseconds. - Weight::from_parts(33_490_161, 6576) - // Standard Error: 2_643 - .saturating_add(Weight::from_ref_time(158_386).saturating_mul(c.into())) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_proof_size(144).saturating_mul(c.into())) - } - /// Storage: Elections Candidates (r:1 w:1) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 64]`. - fn renounce_candidacy_candidate(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `349 + c * (48 ±0)` - // Estimated: `844 + c * (48 ±0)` - // Minimum execution time: 27_292 nanoseconds. - Weight::from_parts(28_364_955, 844) - // Standard Error: 1_335 - .saturating_add(Weight::from_ref_time(78_086).saturating_mul(c.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_proof_size(48).saturating_mul(c.into())) - } - /// Storage: Elections Members (r:1 w:1) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:1 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - fn renounce_candidacy_members() -> Weight { - // Proof Size summary in bytes: - // Measured: `2027` - // Estimated: `12115` - // Minimum execution time: 45_975 nanoseconds. - Weight::from_parts(47_103_000, 12115) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - } - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - fn renounce_candidacy_runners_up() -> Weight { - // Proof Size summary in bytes: - // Measured: `975` - // Estimated: `1470` - // Minimum execution time: 29_243 nanoseconds. - Weight::from_parts(30_582_000, 1470) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: Benchmark Override (r:0 w:0) - /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) - fn remove_member_without_replacement() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000_000 nanoseconds. - Weight::from_ref_time(2_000_000_000_000) - } - /// Storage: Elections Members (r:1 w:1) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:1 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - fn remove_member_with_replacement() -> Weight { - // Proof Size summary in bytes: - // Measured: `2027` - // Estimated: `14718` - // Minimum execution time: 52_527 nanoseconds. - Weight::from_parts(53_538_000, 14718) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(5_u64)) - } - /// Storage: Elections Voting (r:513 w:512) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:0) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:0) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Candidates (r:1 w:0) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Balances Locks (r:512 w:512) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: System Account (r:512 w:512) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// The range of component `v` is `[256, 512]`. - /// The range of component `d` is `[0, 256]`. - fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1115 + v * (875 ±0)` - // Estimated: `8448 + v * (12352 ±0)` - // Minimum execution time: 14_934_185 nanoseconds. - Weight::from_parts(15_014_057_000, 8448) - // Standard Error: 245_588 - .saturating_add(Weight::from_ref_time(35_586_946).saturating_mul(v.into())) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(v.into()))) - .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(v.into()))) - .saturating_add(Weight::from_proof_size(12352).saturating_mul(v.into())) - } - /// Storage: Elections Candidates (r:1 w:1) - /// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Members (r:1 w:1) - /// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections RunnersUp (r:1 w:1) - /// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Elections Voting (r:513 w:0) - /// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Account (r:44 w:44) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Elections ElectionRounds (r:1 w:1) - /// Proof Skipped: Elections ElectionRounds (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:0 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 64]`. - /// The range of component `v` is `[1, 512]`. - /// The range of component `e` is `[512, 8192]`. - fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `0 + v * (638 ±0) + e * (28 ±0)` - // Estimated: `330033 + v * (5229 ±6) + e * (89 ±0) + c * (2135 ±7)` - // Minimum execution time: 1_273_671 nanoseconds. - Weight::from_parts(1_279_716_000, 330033) - // Standard Error: 543_277 - .saturating_add(Weight::from_ref_time(20_613_753).saturating_mul(v.into())) - // Standard Error: 34_857 - .saturating_add(Weight::from_ref_time(688_354).saturating_mul(e.into())) - .saturating_add(RocksDbWeight::get().reads(21_u64)) - .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) - .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(v.into()))) - .saturating_add(RocksDbWeight::get().writes(6_u64)) - .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) - .saturating_add(Weight::from_proof_size(5229).saturating_mul(v.into())) - .saturating_add(Weight::from_proof_size(89).saturating_mul(e.into())) - .saturating_add(Weight::from_proof_size(2135).saturating_mul(c.into())) - } -} From fea82e820ff22f6799d88e97fa792ee284c76912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Mon, 20 Feb 2023 05:50:34 +0100 Subject: [PATCH 30/34] comment clarification --- primitives/npos-elections/src/approval_voting.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/primitives/npos-elections/src/approval_voting.rs b/primitives/npos-elections/src/approval_voting.rs index 8c1d496d77f75..a7266466a8241 100644 --- a/primitives/npos-elections/src/approval_voting.rs +++ b/primitives/npos-elections/src/approval_voting.rs @@ -24,8 +24,9 @@ use crate::{setup_inputs, ElectionResult, IdentifierT, PerThing128, VoteWeight}; use sp_arithmetic::traits::Zero; use sp_std::{cmp::Reverse, vec::Vec}; -/// Execute an approvals voting election scheme. The return type is a list of winners and a weight -/// distribution vector of all voters who contribute to the winners. +/// Execute an approvals voting election scheme. The return type is a list of winners. The weight +/// vector of all voters who contribute to the winners, which for this scheme is always 100% per +/// vote. /// /// - The vote assignment distribution for each vote is always 100%, since a voter backs a candidate /// with its full stake, regardless of how many candidates are backed by the same stake. However, From 64df4122ae8f37b135d73df216b13d9688a94f89 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 20 Feb 2023 19:04:07 +0700 Subject: [PATCH 31/34] re-run weights --- .../election-provider-support/src/weights.rs | 174 +++++++++++------- 1 file changed, 107 insertions(+), 67 deletions(-) diff --git a/frame/election-provider-support/src/weights.rs b/frame/election-provider-support/src/weights.rs index ad26debf382a1..f7851fafb993a 100644 --- a/frame/election-provider-support/src/weights.rs +++ b/frame/election-provider-support/src/weights.rs @@ -1,40 +1,33 @@ -// This file is part of Substrate. - -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. //! Autogenerated weights for pallet_election_provider_support_benchmarking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-04-23, STEPS: `1`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-02-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Rosss-MacBook-Pro-2.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // target/release/substrate // benchmark // pallet -// --chain=dev -// --steps=1 -// --repeat=1 -// --pallet=pallet_election_provider_support_benchmarking -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=frame/election-provider-support/src/weights.rs -// --template=./.maintain/frame-weight-template.hbs +// --execution +// wasm +// --wasm-execution +// compiled +// --dev +// --pallet +// pallet-election-provider-support-benchmarking +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// frame/election-provider-support/src/weights.rs +// --template +// .maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -53,51 +46,98 @@ pub trait WeightInfo { /// Weights for pallet_election_provider_support_benchmarking using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - fn phragmen(v: u32, t: u32, d: u32, ) -> Weight { - Weight::from_ref_time(0 as u64) - // Standard Error: 667_000 - .saturating_add(Weight::from_ref_time(32_973_000 as u64).saturating_mul(v as u64)) - // Standard Error: 1_334_000 - .saturating_add(Weight::from_ref_time(1_334_000 as u64).saturating_mul(t as u64)) - // Standard Error: 60_644_000 - .saturating_add(Weight::from_ref_time(2_636_364_000 as u64).saturating_mul(d as u64)) + /// The range of component `v` is `[1000, 2000]`. + /// The range of component `t` is `[500, 1000]`. + /// The range of component `d` is `[5, 16]`. + fn phragmen(v: u32, _t: u32, d: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 5_215_000 nanoseconds. + Weight::from_ref_time(5_325_000_000) + .saturating_add(Weight::from_proof_size(0)) + // Standard Error: 106_262 + .saturating_add(Weight::from_ref_time(3_989_100).saturating_mul(v.into())) + // Standard Error: 10_863_902 + .saturating_add(Weight::from_ref_time(1_008_030_786).saturating_mul(d.into())) } - fn phragmms(v: u32, t: u32, d: u32, ) -> Weight { - Weight::from_ref_time(0 as u64) - // Standard Error: 73_000 - .saturating_add(Weight::from_ref_time(21_073_000 as u64).saturating_mul(v as u64)) - // Standard Error: 146_000 - .saturating_add(Weight::from_ref_time(65_000 as u64).saturating_mul(t as u64)) - // Standard Error: 6_649_000 - .saturating_add(Weight::from_ref_time(1_711_424_000 as u64).saturating_mul(d as u64)) + /// The range of component `v` is `[1000, 2000]`. + /// The range of component `t` is `[500, 1000]`. + /// The range of component `d` is `[5, 16]`. + fn phragmms(v: u32, _t: u32, d: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_703_000 nanoseconds. + Weight::from_ref_time(3_715_000_000) + .saturating_add(Weight::from_proof_size(0)) + // Standard Error: 85_871 + .saturating_add(Weight::from_ref_time(3_443_928).saturating_mul(v.into())) + // Standard Error: 8_779_237 + .saturating_add(Weight::from_ref_time(985_037_659).saturating_mul(d.into())) + } + /// The range of component `v` is `[1000, 2000]`. + /// The range of component `t` is `[500, 1000]`. + /// The range of component `d` is `[5, 16]`. + fn approval_voting(v: u32, _t: u32, d: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_863_000 nanoseconds. + Weight::from_ref_time(1_868_000_000) + .saturating_add(Weight::from_proof_size(0)) + // Standard Error: 24_930 + .saturating_add(Weight::from_ref_time(1_215_357).saturating_mul(v.into())) + // Standard Error: 2_548_811 + .saturating_add(Weight::from_ref_time(197_537_394).saturating_mul(d.into())) } - - fn approval_voting(_v: u32, _t: u32, _d: u32, ) -> Weight { - Weight::zero() - } } // For backwards compatibility and tests impl WeightInfo for () { - fn phragmen(v: u32, t: u32, d: u32, ) -> Weight { - Weight::from_ref_time(0 as u64) - // Standard Error: 667_000 - .saturating_add(Weight::from_ref_time(32_973_000 as u64).saturating_mul(v as u64)) - // Standard Error: 1_334_000 - .saturating_add(Weight::from_ref_time(1_334_000 as u64).saturating_mul(t as u64)) - // Standard Error: 60_644_000 - .saturating_add(Weight::from_ref_time(2_636_364_000 as u64).saturating_mul(d as u64)) + /// The range of component `v` is `[1000, 2000]`. + /// The range of component `t` is `[500, 1000]`. + /// The range of component `d` is `[5, 16]`. + fn phragmen(v: u32, _t: u32, d: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 5_215_000 nanoseconds. + Weight::from_ref_time(5_325_000_000) + .saturating_add(Weight::from_proof_size(0)) + // Standard Error: 106_262 + .saturating_add(Weight::from_ref_time(3_989_100).saturating_mul(v.into())) + // Standard Error: 10_863_902 + .saturating_add(Weight::from_ref_time(1_008_030_786).saturating_mul(d.into())) + } + /// The range of component `v` is `[1000, 2000]`. + /// The range of component `t` is `[500, 1000]`. + /// The range of component `d` is `[5, 16]`. + fn phragmms(v: u32, _t: u32, d: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_703_000 nanoseconds. + Weight::from_ref_time(3_715_000_000) + .saturating_add(Weight::from_proof_size(0)) + // Standard Error: 85_871 + .saturating_add(Weight::from_ref_time(3_443_928).saturating_mul(v.into())) + // Standard Error: 8_779_237 + .saturating_add(Weight::from_ref_time(985_037_659).saturating_mul(d.into())) } - fn phragmms(v: u32, t: u32, d: u32, ) -> Weight { - Weight::from_ref_time(0 as u64) - // Standard Error: 73_000 - .saturating_add(Weight::from_ref_time(21_073_000 as u64).saturating_mul(v as u64)) - // Standard Error: 146_000 - .saturating_add(Weight::from_ref_time(65_000 as u64).saturating_mul(t as u64)) - // Standard Error: 6_649_000 - .saturating_add(Weight::from_ref_time(1_711_424_000 as u64).saturating_mul(d as u64)) + /// The range of component `v` is `[1000, 2000]`. + /// The range of component `t` is `[500, 1000]`. + /// The range of component `d` is `[5, 16]`. + fn approval_voting(v: u32, _t: u32, d: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_863_000 nanoseconds. + Weight::from_ref_time(1_868_000_000) + .saturating_add(Weight::from_proof_size(0)) + // Standard Error: 24_930 + .saturating_add(Weight::from_ref_time(1_215_357).saturating_mul(v.into())) + // Standard Error: 2_548_811 + .saturating_add(Weight::from_ref_time(197_537_394).saturating_mul(d.into())) } - fn approval_voting(_v: u32, _t: u32, _d: u32, ) -> Weight { - Weight::zero() - } } From 614fe8a97ff18785dec427eb346c035c81d4809d Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 20 Feb 2023 12:04:37 +0000 Subject: [PATCH 32/34] fix typo --- primitives/npos-elections/src/approval_voting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/npos-elections/src/approval_voting.rs b/primitives/npos-elections/src/approval_voting.rs index a7266466a8241..2fcf17b60565d 100644 --- a/primitives/npos-elections/src/approval_voting.rs +++ b/primitives/npos-elections/src/approval_voting.rs @@ -38,7 +38,7 @@ use sp_std::{cmp::Reverse, vec::Vec}; /// ExtendedBalance and may be slightly different that what will be computed from the support map, /// due to accuracy loss. /// -/// This can only fail of the normalization fails. This can happen if for any of the resulting +/// This can only fail if the normalization fails. This can happen if for any of the resulting /// assignments, `assignment.distribution.map(|p| p.deconstruct()).sum()` fails to fit inside /// `UpperOf

`. A user of this crate may statically assert that this can never happen and safely /// `expect` this to return `Ok`. From 04483c6ff574c8393749b8ba5f53a08fe6444bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Mon, 20 Feb 2023 13:43:37 +0100 Subject: [PATCH 33/34] updates MaxVoters in tests for integrity_tests to pass --- frame/elections/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 77e118835771b..13ffdbbd43078 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -340,7 +340,6 @@ pub mod pallet { T::MaxVoters::get(), T::MaxVotesPerVoter::get() * T::MaxVoters::get(), ); - let election_weight = pre_solve_weight .saturating_sub(post_solve_weight) .saturating_add(election_weight); @@ -1397,7 +1396,7 @@ mod tests { parameter_types! { pub const ElectionsPalletId: LockIdentifier = *b"phrelect"; - pub const MaxVoters: u32 = 512; + pub const MaxVoters: u32 = 256; pub const MaxCandidates: u32 = 64; } From 70ea87abb3ef4ebb1c811b70e2512d48472be6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Wed, 22 Feb 2023 13:10:19 +0000 Subject: [PATCH 34/34] Refactors election provider support benchmarks outside its own crate (#13431) * Refactors election provider support benchmarks outside its own crate --------- Co-authored-by: command-bot <> --- Cargo.lock | 258 ++++++++---------- Cargo.toml | 1 - bin/node/runtime/Cargo.toml | 4 +- bin/node/runtime/src/lib.rs | 8 +- .../election-provider-multi-phase/Cargo.toml | 2 - frame/election-provider-support/Cargo.toml | 8 +- .../benchmarking/Cargo.toml | 37 --- .../src/lib.rs => src/benchmarking.rs} | 5 +- frame/election-provider-support/src/lib.rs | 3 + .../election-provider-support/src/weights.rs | 119 ++++---- scripts/run_all_benchmarks.sh | 2 - 11 files changed, 194 insertions(+), 253 deletions(-) delete mode 100644 frame/election-provider-support/benchmarking/Cargo.toml rename frame/election-provider-support/{benchmarking/src/lib.rs => src/benchmarking.rs} (94%) diff --git a/Cargo.lock b/Cargo.lock index a49538452c820..5619beef97889 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ - "gimli 0.27.1", + "gimli 0.27.2", ] [[package]] @@ -246,7 +246,7 @@ dependencies = [ "num-traits", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.19", ] [[package]] @@ -262,7 +262,7 @@ dependencies = [ "num-traits", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.19", ] [[package]] @@ -358,19 +358,20 @@ dependencies = [ [[package]] name = "async-stream" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +checksum = "ad445822218ce64be7a341abfb0b1ea43b5c23aa83902542a4542e78309d8e5e" dependencies = [ "async-stream-impl", "futures-core", + "pin-project-lite 0.2.9", ] [[package]] name = "async-stream-impl" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +checksum = "e4655ae1a7b0cdf149156f780c5bf3f1352bc53cbd9e0a361a7ef7b22947e965" dependencies = [ "proc-macro2", "quote", @@ -579,9 +580,9 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.60.1" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ "bitflags", "cexpr", @@ -594,6 +595,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", + "syn", ] [[package]] @@ -625,24 +627,24 @@ dependencies = [ [[package]] name = "blake2b_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" +checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] name = "blake2s_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" +checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] @@ -655,7 +657,7 @@ dependencies = [ "arrayvec 0.7.2", "cc", "cfg-if", - "constant_time_eq 0.2.4", + "constant_time_eq", ] [[package]] @@ -715,9 +717,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "bounded-collections" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de2aff4807e40f478132150d80b031f2461d88f061851afcab537d7600c24120" +checksum = "a071c348a5ef6da1d3a87166b408170b46002382b1dda83992b5c2208cefb370" dependencies = [ "log", "parity-scale-codec", @@ -733,9 +735,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f0778972c64420fdedc63f09919c8a88bda7b25135357fd25a5d9f3257e832" +checksum = "5ffdb39cb703212f3c11973452c2861b972f757b021158f3516ba10f2fa8b2c1" dependencies = [ "memchr", "once_cell", @@ -917,7 +919,7 @@ name = "chain-spec-builder" version = "2.0.0" dependencies = [ "ansi_term", - "clap 4.1.4", + "clap 4.1.6", "node-cli", "rand 0.8.5", "sc-chain-spec", @@ -1010,9 +1012,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.4.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" +checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" dependencies = [ "glob", "libc", @@ -1033,9 +1035,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.4" +version = "4.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" +checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3" dependencies = [ "bitflags", "clap_derive", @@ -1048,11 +1050,11 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.1.1" +version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6540eedc41f8a5a76cf3d8d458057dcdf817be4158a55b5f861f7a5483de75" +checksum = "bd125be87bf4c255ebc50de0b7f4d2a6201e8ac3dc86e39c0ad081dc5e7236fe" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", ] [[package]] @@ -1122,12 +1124,6 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cec318a675afcb6a1ea1d4340e2d377e56e47c266f28043ceccbf4412ddfdd3b" -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "constant_time_eq" version = "0.2.4" @@ -1506,9 +1502,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc831ee6a32dd495436e317595e639a587aa9907bef96fe6e6abc290ab6204e9" +checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" dependencies = [ "cc", "cxxbridge-flags", @@ -1518,9 +1514,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94331d54f1b1a8895cd81049f7eaaaef9d05a7dcb4d1fd08bf3ff0806246789d" +checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" dependencies = [ "cc", "codespan-reporting", @@ -1533,15 +1529,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48dcd35ba14ca9b40d6e4b4b39961f23d835dbb8eed74565ded361d93e1feb8a" +checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" [[package]] name = "cxxbridge-macro" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2" +checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" dependencies = [ "proc-macro2", "quote", @@ -2042,9 +2038,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ "instant", ] @@ -2086,14 +2082,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9" +checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -2213,7 +2209,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap 4.1.4", + "clap 4.1.6", "comfy-table", "frame-benchmarking", "frame-support", @@ -2286,6 +2282,7 @@ dependencies = [ name = "frame-election-provider-support" version = "4.0.0-dev" dependencies = [ + "frame-benchmarking", "frame-election-provider-solution-type", "frame-support", "frame-system", @@ -2304,7 +2301,7 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", @@ -2787,9 +2784,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec" +checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" [[package]] name = "git2" @@ -2932,9 +2929,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] name = "hex" @@ -3026,9 +3023,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -3312,7 +3309,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" dependencies = [ - "hermit-abi 0.3.0", + "hermit-abi 0.3.1", "io-lifetimes", "rustix", "windows-sys 0.45.0", @@ -3538,7 +3535,6 @@ dependencies = [ "pallet-conviction-voting", "pallet-democracy", "pallet-election-provider-multi-phase", - "pallet-election-provider-support-benchmarking", "pallet-elections", "pallet-fast-unstake", "pallet-glutton", @@ -4104,9 +4100,9 @@ dependencies = [ [[package]] name = "librocksdb-sys" -version = "0.8.0+7.4.4" +version = "0.8.3+7.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611804e4666a25136fcc5f8cf425ab4d26c7f74ea245ffe92ea23b85b6420b5d" +checksum = "557b255ff04123fcc176162f56ed0c9cd42d8f357cf55b3fabeb60f7413741b3" dependencies = [ "bindgen", "bzip2-sys", @@ -4365,9 +4361,9 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b182332558b18d807c4ce1ca8ca983b34c3ee32765e47b3f0f69b90355cc1dc" +checksum = "2af2c65375e552a67fe3829ca63e8a7c27a378a62824594f43b2851d682b5ec2" dependencies = [ "libc", ] @@ -4435,14 +4431,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -4724,7 +4720,7 @@ name = "node-bench" version = "0.9.0-dev" dependencies = [ "array-bytes", - "clap 4.1.4", + "clap 4.1.6", "derive_more", "fs_extra", "futures", @@ -4761,7 +4757,7 @@ version = "3.0.0-dev" dependencies = [ "array-bytes", "assert_cmd", - "clap 4.1.4", + "clap 4.1.6", "clap_complete", "criterion", "frame-benchmarking-cli", @@ -4881,7 +4877,7 @@ dependencies = [ name = "node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -4940,7 +4936,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "generate-bags", "kitchensink-runtime", ] @@ -4949,7 +4945,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -5205,9 +5201,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "oorandom" @@ -5713,7 +5709,6 @@ dependencies = [ "frame-system", "log", "pallet-balances", - "pallet-election-provider-support-benchmarking", "parity-scale-codec", "parking_lot 0.12.1", "rand 0.8.5", @@ -5728,18 +5723,6 @@ dependencies = [ "strum", ] -[[package]] -name = "pallet-election-provider-support-benchmarking" -version = "4.0.0-dev" -dependencies = [ - "frame-benchmarking", - "frame-election-provider-support", - "frame-system", - "parity-scale-codec", - "sp-npos-elections", - "sp-runtime", -] - [[package]] name = "pallet-elections" version = "5.0.0-dev" @@ -6785,9 +6768,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3840933452adf7b3b9145e27086a5a3376c619dca1a21b1e5a5af0d54979bed" +checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" dependencies = [ "arrayvec 0.7.2", "bitvec", @@ -6932,9 +6915,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.4" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab62d2fa33726dbe6321cc97ef96d8cde531e3eeaf858a058de53a8a6d40d8f" +checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660" dependencies = [ "thiserror", "ucd-trie", @@ -6942,9 +6925,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.4" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf026e2d0581559db66d837fe5242320f525d85c76283c61f4d51a1238d65ea" +checksum = "2ac3922aac69a40733080f53c1ce7f91dcf57e1a5f6c52f421fadec7fbdc4b69" dependencies = [ "pest", "pest_generator", @@ -6952,9 +6935,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.4" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b27bd18aa01d91c8ed2b61ea23406a676b42d82609c6e2581fba42f0c15f17f" +checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202" dependencies = [ "pest", "pest_meta", @@ -6965,9 +6948,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.4" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d" +checksum = "e6f60b2ba541577e2a0c307c8f39d1439108120eb7903adeb6497fa880c59616" dependencies = [ "once_cell", "pest", @@ -7539,7 +7522,7 @@ checksum = "6413f3de1edee53342e6138e75b56d32e7bc6e332b3bd62d497b1929d4cfbcdd" dependencies = [ "pem", "ring", - "time 0.3.17", + "time 0.3.19", "x509-parser 0.13.2", "yasna", ] @@ -7552,7 +7535,7 @@ checksum = "ffbe84efe2f38dea12e9bfc1f65377fdf03e53a18cb3b995faedf7934c7e785b" dependencies = [ "pem", "ring", - "time 0.3.17", + "time 0.3.19", "yasna", ] @@ -8026,7 +8009,7 @@ version = "0.10.0-dev" dependencies = [ "array-bytes", "chrono", - "clap 4.1.4", + "clap 4.1.6", "fdlimit", "futures", "futures-timer", @@ -9061,7 +9044,7 @@ dependencies = [ name = "sc-storage-monitor" version = "0.1.0" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "futures", "log", "nix 0.26.2", @@ -9457,9 +9440,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7434af0dc1cbd59268aa98b4c22c131c0584d2232f6fb166efb993e2832e896a" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" dependencies = [ "itoa", "ryu", @@ -9542,9 +9525,9 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] @@ -9574,9 +9557,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] @@ -10120,7 +10103,7 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "honggfuzz", "parity-scale-codec", "rand 0.8.5", @@ -10477,9 +10460,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc" [[package]] name = "spki" @@ -10597,7 +10580,7 @@ dependencies = [ name = "subkey" version = "3.0.0" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "sc-cli", ] @@ -10625,7 +10608,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 4.1.4", + "clap 4.1.6", "frame-support", "frame-system", "sc-cli", @@ -10935,9 +10918,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.5" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d" +checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" [[package]] name = "tempfile" @@ -11002,10 +10985,11 @@ checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" [[package]] name = "thread_local" -version = "1.1.4" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ + "cfg-if", "once_cell", ] @@ -11041,9 +11025,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2" dependencies = [ "itoa", "serde", @@ -11059,9 +11043,9 @@ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] name = "time-macros" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +checksum = "a460aeb8de6dcb0f381e1ee05f1cd56fcf5a5f6eb8187ff3d8f0b11078d38b7c" dependencies = [ "time-core", ] @@ -11163,9 +11147,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" +checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" dependencies = [ "futures-core", "pin-project-lite 0.2.9", @@ -11188,9 +11172,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" dependencies = [ "bytes", "futures-core", @@ -11462,7 +11446,7 @@ name = "try-runtime-cli" version = "0.10.0-dev" dependencies = [ "async-trait", - "clap 4.1.4", + "clap 4.1.6", "frame-remote-externalities", "frame-try-runtime", "hex", @@ -11807,9 +11791,9 @@ checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-encoder" -version = "0.22.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a584273ccc2d9311f1dd19dc3fb26054661fa3e373d53ede5d1144ba07a9acd" +checksum = "704553b4d614a47080b4a457a976b3c16174b19ce95b931b847561b590dd09ba" dependencies = [ "leb128", ] @@ -11905,7 +11889,7 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01bf50edb2ea9d922aa75a7bf3c15e26a6c9e2d18c56e862b49737a582901729" dependencies = [ - "spin 0.9.4", + "spin 0.9.5", "wasmi_arena", "wasmi_core 0.5.0", "wasmparser-nostd", @@ -12140,9 +12124,9 @@ dependencies = [ [[package]] name = "wast" -version = "52.0.3" +version = "54.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15942180f265280eede7bc38b239e9770031d1821c02d905284216c645316430" +checksum = "f0d3df4a63b10958fe98ab9d7e9a57a7bc900209d2b4edd10535bfb0703e6516" dependencies = [ "leb128", "memchr", @@ -12152,9 +12136,9 @@ dependencies = [ [[package]] name = "wat" -version = "1.0.57" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37212100d4cbe6f0f6ff6e707f1e5a5b5b675f0451231ed9e4235e234e127ed3" +checksum = "3e9a7c7d177696d0548178c36e377d49eba54170e885801d4270e2d44e82ac84" dependencies = [ "wast", ] @@ -12224,7 +12208,7 @@ dependencies = [ "sha2 0.10.6", "stun", "thiserror", - "time 0.3.17", + "time 0.3.19", "tokio", "turn", "url", @@ -12297,9 +12281,9 @@ dependencies = [ [[package]] name = "webrtc-ice" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494483fbb2f5492620871fdc78b084aed8807377f6e3fe88b2e49f0a9c9c41d7" +checksum = "465a03cc11e9a7d7b4f9f99870558fe37a102b65b93f8045392fef7c67b39e80" dependencies = [ "arc-swap", "async-trait", @@ -12657,7 +12641,7 @@ dependencies = [ "ring", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.19", ] [[package]] @@ -12675,7 +12659,7 @@ dependencies = [ "oid-registry 0.6.1", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.19", ] [[package]] @@ -12704,7 +12688,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aed2e7a52e3744ab4d0c05c20aa065258e84c49fd4226f5191b2ed29712710b4" dependencies = [ - "time 0.3.17", + "time 0.3.19", ] [[package]] @@ -12749,9 +12733,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.6+zstd.1.5.2" +version = "2.0.7+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a3f9792c0c3dc6c165840a75f47ae1f4da402c2d006881129579f6597e801b" +checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" dependencies = [ "cc", "libc", diff --git a/Cargo.toml b/Cargo.toml index fc8100d26777e..2ae924bf6e1eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,6 @@ members = [ "frame/elections", "frame/election-provider-multi-phase", "frame/election-provider-support", - "frame/election-provider-support/benchmarking", "frame/election-provider-support/solution-type", "frame/election-provider-support/solution-type/fuzzer", "frame/examples/basic", diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 232592d38f7dc..d7b42efd4d2d6 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -66,7 +66,6 @@ pallet-contracts-primitives = { version = "7.0.0", default-features = false, pat pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/conviction-voting" } pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" } pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" } -pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true } pallet-elections = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections" } pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" } pallet-nis = { version = "4.0.0-dev", default-features = false, path = "../../../frame/nis" } @@ -124,7 +123,6 @@ with-tracing = ["frame-executive/with-tracing"] std = [ "pallet-whitelist/std", "pallet-offences-benchmarking?/std", - "pallet-election-provider-support-benchmarking?/std", "pallet-asset-tx-payment/std", "frame-system-benchmarking?/std", "frame-election-provider-support/std", @@ -218,6 +216,7 @@ runtime-benchmarks = [ "frame-benchmarking-pallet-pov/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "frame-election-provider-support/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-alliance/runtime-benchmarks", "pallet-assets/runtime-benchmarks", @@ -231,7 +230,6 @@ runtime-benchmarks = [ "pallet-conviction-voting/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-election-provider-multi-phase/runtime-benchmarks", - "pallet-election-provider-support-benchmarking/runtime-benchmarks", "pallet-elections/runtime-benchmarks", "pallet-fast-unstake/runtime-benchmarks", "pallet-nis/runtime-benchmarks", diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index baf8a6edf6df9..1ed43c211f8a1 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1857,6 +1857,7 @@ mod benches { frame_benchmarking::define_benchmarks!( [frame_benchmarking, BaselineBench::] [frame_benchmarking_pallet_pov, Pov] + [frame_election_provider_support, EPSBench::] [pallet_alliance, Alliance] [pallet_assets, Assets] [pallet_babe, Babe] @@ -1869,7 +1870,6 @@ mod benches { [pallet_contracts, Contracts] [pallet_democracy, Democracy] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] - [pallet_election_provider_support_benchmarking, EPSBench::] [pallet_elections, Elections] [pallet_fast_unstake, FastUnstake] [pallet_nis, Nis] @@ -2285,7 +2285,7 @@ impl_runtime_apis! { // which is why we need these two lines below. use pallet_session_benchmarking::Pallet as SessionBench; use pallet_offences_benchmarking::Pallet as OffencesBench; - use pallet_election_provider_support_benchmarking::Pallet as EPSBench; + use frame_election_provider_support::benchmarking::Pallet as EPSBench; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench; @@ -2308,14 +2308,14 @@ impl_runtime_apis! { // which is why we need these two lines below. use pallet_session_benchmarking::Pallet as SessionBench; use pallet_offences_benchmarking::Pallet as OffencesBench; - use pallet_election_provider_support_benchmarking::Pallet as EPSBench; + use frame_election_provider_support::benchmarking::Pallet as EPSBench; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench; impl pallet_session_benchmarking::Config for Runtime {} impl pallet_offences_benchmarking::Config for Runtime {} - impl pallet_election_provider_support_benchmarking::Config for Runtime {} + impl frame_election_provider_support::benchmarking::Config for Runtime {} impl frame_system_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} impl pallet_nomination_pools_benchmarking::Config for Runtime {} diff --git a/frame/election-provider-multi-phase/Cargo.toml b/frame/election-provider-multi-phase/Cargo.toml index aa734850aae43..996f40febdeba 100644 --- a/frame/election-provider-multi-phase/Cargo.toml +++ b/frame/election-provider-multi-phase/Cargo.toml @@ -33,7 +33,6 @@ frame-election-provider-support = { version = "4.0.0-dev", default-features = fa # Optional imports for benchmarking frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true } -pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support/benchmarking", optional = true } rand = { version = "0.8.5", default-features = false, features = ["alloc", "small_rng"], optional = true } strum = { version = "0.24.1", default-features = false, features = ["derive"], optional = true } @@ -50,7 +49,6 @@ frame-benchmarking = { version = "4.0.0-dev", path = "../benchmarking" } [features] default = ["std"] std = [ - "pallet-election-provider-support-benchmarking?/std", "codec/std", "scale-info/std", "log/std", diff --git a/frame/election-provider-support/Cargo.toml b/frame/election-provider-support/Cargo.toml index 114caee793f1a..f9cb5233ced22 100644 --- a/frame/election-provider-support/Cargo.toml +++ b/frame/election-provider-support/Cargo.toml @@ -23,6 +23,8 @@ sp-runtime = { version = "7.0.0", default-features = false, path = "../../primit sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" } sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true } + [dev-dependencies] rand = { version = "0.8.5", features = ["small_rng"] } sp-io = { version = "7.0.0", path = "../../primitives/io" } @@ -41,6 +43,10 @@ std = [ "sp-core/std", "sp-runtime/std", "sp-std/std", + + "frame-benchmarking?/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", ] -runtime-benchmarks = [] try-runtime = [] diff --git a/frame/election-provider-support/benchmarking/Cargo.toml b/frame/election-provider-support/benchmarking/Cargo.toml deleted file mode 100644 index bef371ec5efbf..0000000000000 --- a/frame/election-provider-support/benchmarking/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -name = "pallet-election-provider-support-benchmarking" -version = "4.0.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "Apache-2.0" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -description = "Benchmarking for election provider support onchain config trait" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [ - "derive", -] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../../benchmarking" } -frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = ".." } -frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" } -sp-npos-elections = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/npos-elections" } -sp-runtime = { version = "7.0.0", default-features = false, path = "../../../primitives/runtime" } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-benchmarking?/std", - "frame-election-provider-support/std", - "frame-system/std", - "sp-npos-elections/std", - "sp-runtime/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-election-provider-support/runtime-benchmarks", -] diff --git a/frame/election-provider-support/benchmarking/src/lib.rs b/frame/election-provider-support/src/benchmarking.rs similarity index 94% rename from frame/election-provider-support/benchmarking/src/lib.rs rename to frame/election-provider-support/src/benchmarking.rs index 8ada68ebee65f..5c5b952b6dcc9 100644 --- a/frame/election-provider-support/benchmarking/src/lib.rs +++ b/frame/election-provider-support/src/benchmarking.rs @@ -18,12 +18,9 @@ //! Election provider support pallet benchmarking. //! This is separated into its own crate to avoid bloating the size of the runtime. -#![cfg(feature = "runtime-benchmarks")] -#![cfg_attr(not(feature = "std"), no_std)] - +use crate::{ApprovalVoting, NposSolver, PhragMMS, SequentialPhragmen}; use codec::Decode; use frame_benchmarking::v1::{benchmarks, Vec}; -use frame_election_provider_support::{ApprovalVoting, NposSolver, PhragMMS, SequentialPhragmen}; pub struct Pallet(frame_system::Pallet); pub trait Config: frame_system::Config {} diff --git a/frame/election-provider-support/src/lib.rs b/frame/election-provider-support/src/lib.rs index bf404c68a1124..423ce3d67e8cb 100644 --- a/frame/election-provider-support/src/lib.rs +++ b/frame/election-provider-support/src/lib.rs @@ -199,6 +199,9 @@ pub use sp_arithmetic; #[doc(hidden)] pub use sp_std; +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; + pub mod weights; pub use weights::WeightInfo; diff --git a/frame/election-provider-support/src/weights.rs b/frame/election-provider-support/src/weights.rs index 546aba39e4c83..c28794267c640 100644 --- a/frame/election-provider-support/src/weights.rs +++ b/frame/election-provider-support/src/weights.rs @@ -1,13 +1,13 @@ // This file is part of Substrate. -// Copyright (C) Parity Technologies (UK) Ltd. +// Copyright (C) 2023 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -15,35 +15,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Autogenerated weights for pallet_election_provider_support_benchmarking +//! Autogenerated weights for frame_election_provider_support //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Rosss-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! HOSTNAME: `runner-ehxwxxsd-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// target/release/substrate +// target/production/substrate // benchmark // pallet -// --execution -// wasm -// --wasm-execution -// compiled -// --dev -// --pallet -// pallet-election-provider-support-benchmarking -// --extrinsic -// * -// --steps -// 50 -// --repeat -// 20 -// --output -// frame/election-provider-support/src/weights.rs -// --template -// .maintain/frame-weight-template.hbs +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json +// --pallet=frame_election_provider_support +// --chain=dev +// --header=./HEADER-APACHE2 +// --output=./frame/election-provider-support/src/weights.rs +// --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -52,14 +47,14 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; -/// Weight functions needed for pallet_election_provider_support_benchmarking. +/// Weight functions needed for frame_election_provider_support. pub trait WeightInfo { fn phragmen(v: u32, t: u32, d: u32, ) -> Weight; fn phragmms(v: u32, t: u32, d: u32, ) -> Weight; fn approval_voting(v: u32, t: u32, d: u32, ) -> Weight; } -/// Weights for pallet_election_provider_support_benchmarking using the Substrate node and recommended hardware. +/// Weights for frame_election_provider_support using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { /// The range of component `v` is `[1000, 2000]`. @@ -69,13 +64,13 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_215_000 nanoseconds. - Weight::from_ref_time(5_325_000_000) + // Minimum execution time: 5_789_174 nanoseconds. + Weight::from_ref_time(5_826_449_000) .saturating_add(Weight::from_proof_size(0)) - // Standard Error: 106_262 - .saturating_add(Weight::from_ref_time(3_989_100).saturating_mul(v.into())) - // Standard Error: 10_863_902 - .saturating_add(Weight::from_ref_time(1_008_030_786).saturating_mul(d.into())) + // Standard Error: 130_342 + .saturating_add(Weight::from_ref_time(5_332_741).saturating_mul(v.into())) + // Standard Error: 13_325_769 + .saturating_add(Weight::from_ref_time(1_416_874_101).saturating_mul(d.into())) } /// The range of component `v` is `[1000, 2000]`. /// The range of component `t` is `[500, 1000]`. @@ -84,13 +79,13 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_703_000 nanoseconds. - Weight::from_ref_time(3_715_000_000) + // Minimum execution time: 4_151_790 nanoseconds. + Weight::from_ref_time(4_215_936_000) .saturating_add(Weight::from_proof_size(0)) - // Standard Error: 85_871 - .saturating_add(Weight::from_ref_time(3_443_928).saturating_mul(v.into())) - // Standard Error: 8_779_237 - .saturating_add(Weight::from_ref_time(985_037_659).saturating_mul(d.into())) + // Standard Error: 125_135 + .saturating_add(Weight::from_ref_time(4_730_609).saturating_mul(v.into())) + // Standard Error: 12_793_390 + .saturating_add(Weight::from_ref_time(1_474_383_961).saturating_mul(d.into())) } /// The range of component `v` is `[1000, 2000]`. /// The range of component `t` is `[500, 1000]`. @@ -99,13 +94,13 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_863_000 nanoseconds. - Weight::from_ref_time(1_868_000_000) + // Minimum execution time: 1_800_445 nanoseconds. + Weight::from_ref_time(1_824_645_000) .saturating_add(Weight::from_proof_size(0)) - // Standard Error: 24_930 - .saturating_add(Weight::from_ref_time(1_215_357).saturating_mul(v.into())) - // Standard Error: 2_548_811 - .saturating_add(Weight::from_ref_time(197_537_394).saturating_mul(d.into())) + // Standard Error: 26_266 + .saturating_add(Weight::from_ref_time(1_229_576).saturating_mul(v.into())) + // Standard Error: 2_685_343 + .saturating_add(Weight::from_ref_time(213_080_804).saturating_mul(d.into())) } } @@ -118,13 +113,13 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_215_000 nanoseconds. - Weight::from_ref_time(5_325_000_000) + // Minimum execution time: 5_789_174 nanoseconds. + Weight::from_ref_time(5_826_449_000) .saturating_add(Weight::from_proof_size(0)) - // Standard Error: 106_262 - .saturating_add(Weight::from_ref_time(3_989_100).saturating_mul(v.into())) - // Standard Error: 10_863_902 - .saturating_add(Weight::from_ref_time(1_008_030_786).saturating_mul(d.into())) + // Standard Error: 130_342 + .saturating_add(Weight::from_ref_time(5_332_741).saturating_mul(v.into())) + // Standard Error: 13_325_769 + .saturating_add(Weight::from_ref_time(1_416_874_101).saturating_mul(d.into())) } /// The range of component `v` is `[1000, 2000]`. /// The range of component `t` is `[500, 1000]`. @@ -133,13 +128,13 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_703_000 nanoseconds. - Weight::from_ref_time(3_715_000_000) + // Minimum execution time: 4_151_790 nanoseconds. + Weight::from_ref_time(4_215_936_000) .saturating_add(Weight::from_proof_size(0)) - // Standard Error: 85_871 - .saturating_add(Weight::from_ref_time(3_443_928).saturating_mul(v.into())) - // Standard Error: 8_779_237 - .saturating_add(Weight::from_ref_time(985_037_659).saturating_mul(d.into())) + // Standard Error: 125_135 + .saturating_add(Weight::from_ref_time(4_730_609).saturating_mul(v.into())) + // Standard Error: 12_793_390 + .saturating_add(Weight::from_ref_time(1_474_383_961).saturating_mul(d.into())) } /// The range of component `v` is `[1000, 2000]`. /// The range of component `t` is `[500, 1000]`. @@ -148,12 +143,12 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_863_000 nanoseconds. - Weight::from_ref_time(1_868_000_000) + // Minimum execution time: 1_800_445 nanoseconds. + Weight::from_ref_time(1_824_645_000) .saturating_add(Weight::from_proof_size(0)) - // Standard Error: 24_930 - .saturating_add(Weight::from_ref_time(1_215_357).saturating_mul(v.into())) - // Standard Error: 2_548_811 - .saturating_add(Weight::from_ref_time(197_537_394).saturating_mul(d.into())) + // Standard Error: 26_266 + .saturating_add(Weight::from_ref_time(1_229_576).saturating_mul(v.into())) + // Standard Error: 2_685_343 + .saturating_add(Weight::from_ref_time(213_080_804).saturating_mul(d.into())) } } diff --git a/scripts/run_all_benchmarks.sh b/scripts/run_all_benchmarks.sh index b632cb5c12f04..818a5df7f6d95 100755 --- a/scripts/run_all_benchmarks.sh +++ b/scripts/run_all_benchmarks.sh @@ -67,8 +67,6 @@ SUBSTRATE=./target/production/substrate # Manually exclude some pallets. EXCLUDED_PALLETS=( - # Helper pallets - "pallet_election_provider_support_benchmarking" # Pallets without automatic benchmarking "pallet_babe" "pallet_grandpa"