This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Adding benchmarking for new frame_election_provider_support
#11149
Merged
paritytech-processbot
merged 26 commits into
paritytech:master
from
georgesdib:onchain-election-benchmarking
Apr 15, 2022
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a46d35f
First stab at adding benchmarking for
2c275fc
Adding `BoundedPhragMMS` and fixing stuff
e96e7f9
Fixing node runtime
575e6d9
Fixing tests
a92a735
Finalising all benchmarking stuff
6c884cd
better comments
d96872a
Merge branch 'paritytech:master' into onchain-election-benchmarking
georgesdib 5b0bdc3
Better benchmarking config
728eeec
Better `WeightInfo` and benchmarking
d50bd98
Fixing tests
be0d0dc
Merge branch 'paritytech:master' into onchain-election-benchmarking
georgesdib 382a74a
Adding some documentation
37f2129
Merge branch 'onchain-election-benchmarking' of https://github.com/ge…
bb19b77
Fixing some typos
6eb4978
Incorporating review feedback
f2faaeb
cleanup of rustdocs
52aef01
Merge branch 'paritytech:master' into onchain-election-benchmarking
georgesdib 9e55d7f
rustdoc changes
9d2e07b
Merge branch 'onchain-election-benchmarking' of https://github.com/ge…
1729278
changes after code review
23c1453
Fixing some errors.
1375dde
Merge branch 'paritytech:master' into onchain-election-benchmarking
georgesdib 5c679fd
Fixing dependencies post merge
b61dae9
Bringing back `UnboundedExecution`
3654c7b
Better rustdoc and naming
d43e909
Cargo.toml formatting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| [package] | ||
| name = "pallet-election-provider-support-benchmarking" | ||
| version = "4.0.0-dev" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
| 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.0.0", default-features = false, features = [ | ||
| "derive", | ||
| ] } | ||
| sp-npos-elections = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/npos-elections" } | ||
| sp-runtime = { version = "6.0.0", default-features = false, path = "../../../primitives/runtime" } | ||
| frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" } | ||
| frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = ".." } | ||
| frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../benchmarking", optional = true } | ||
|
|
||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "sp-npos-elections/std", | ||
| "sp-runtime/std", | ||
| "frame-benchmarking/std", | ||
| "frame-system/std", | ||
| ] | ||
|
|
||
| runtime-benchmarks = [ | ||
| "frame-benchmarking/runtime-benchmarks", | ||
| "frame-election-provider-support/runtime-benchmarks", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2021-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. | ||
|
|
||
| //! 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 codec::Decode; | ||
| use frame_benchmarking::{benchmarks, Vec}; | ||
| use frame_election_provider_support::{NposSolver, PhragMMS, SequentialPhragmen}; | ||
|
|
||
| pub struct Pallet<T: Config>(frame_system::Pallet<T>); | ||
| pub trait Config: frame_system::Config {} | ||
|
|
||
| const VOTERS: [u32; 2] = [1_000, 2_000]; | ||
| const TARGETS: [u32; 2] = [500, 1_000]; | ||
| const VOTES_PER_VOTER: [u32; 2] = [5, 16]; | ||
|
|
||
| const SEED: u32 = 999; | ||
| fn set_up_voters_targets<AccountId: Decode + Clone>( | ||
| voters_len: u32, | ||
| targets_len: u32, | ||
| degree: usize, | ||
| ) -> (Vec<(AccountId, u64, impl IntoIterator<Item = AccountId>)>, Vec<AccountId>) { | ||
| // fill targets. | ||
| let mut targets = (0..targets_len) | ||
| .map(|i| frame_benchmarking::account::<AccountId>("Target", i, SEED)) | ||
| .collect::<Vec<_>>(); | ||
| assert!(targets.len() > degree, "we should always have enough voters to fill"); | ||
| targets.truncate(degree); | ||
|
|
||
| // fill voters. | ||
| let voters = (0..voters_len) | ||
| .map(|i| { | ||
| let voter = frame_benchmarking::account::<AccountId>("Voter", i, SEED); | ||
| (voter, 1_000, targets.clone()) | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| (voters, targets) | ||
| } | ||
|
|
||
| benchmarks! { | ||
| phragmen { | ||
| // number of votes in snapshot. | ||
| let v in (VOTERS[0]) .. VOTERS[1]; | ||
emostov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // number of targets in snapshot. | ||
| let t in (TARGETS[0]) .. TARGETS[1]; | ||
| // number of votes per voter (ie the degree). | ||
| let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1]; | ||
|
|
||
| let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as usize); | ||
| }: { | ||
| assert!( | ||
| SequentialPhragmen::<T::AccountId, sp_runtime::Perbill> | ||
| ::solve(d as usize, targets, voters).is_ok() | ||
| ); | ||
| } | ||
|
|
||
| phragmms { | ||
| // number of votes in snapshot. | ||
| let v in (VOTERS[0]) .. VOTERS[1]; | ||
| // number of targets in snapshot. | ||
| let t in (TARGETS[0]) .. TARGETS[1]; | ||
| // number of votes per voter (ie the degree). | ||
| let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1]; | ||
|
|
||
| let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as usize); | ||
| }: { | ||
| assert!( | ||
| PhragMMS::<T::AccountId, sp_runtime::Perbill> | ||
| ::solve(d as usize, targets, voters).is_ok() | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.