Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
922f655
Allow `pallet-election-provider` to accept smaller
Feb 23, 2022
5e63199
Fixing a typo
Feb 23, 2022
d0177c0
Adding some more tests
Feb 25, 2022
46de469
making it a URL
Feb 25, 2022
6ad51ab
Updating test name as per suggestion
georgesdib Mar 1, 2022
0506bd1
Updating documentation to be more explicit
georgesdib Mar 1, 2022
a604cea
Fixing formatting
Mar 1, 2022
a7bf404
`Fallback` now of type `InstantElectionProvider`
Mar 1, 2022
8f3e8b4
Allow `pallet-election-provider` to accept smaller
Feb 23, 2022
80ce9cb
Fixing a typo
Feb 23, 2022
1960035
Adding some more tests
Feb 25, 2022
3f87102
making it a URL
Feb 25, 2022
f683841
Updating test name as per suggestion
georgesdib Mar 1, 2022
3e3752f
Updating documentation to be more explicit
georgesdib Mar 1, 2022
521e4d2
Fixing formatting
Mar 1, 2022
d94ac40
`Fallback` now of type `InstantElectionProvider`
Mar 1, 2022
d389ee3
Merge branch 'election-fallback' of https://github.com/georgesdib/sub…
Mar 1, 2022
6e8c419
Merging types into one type with generics
Mar 6, 2022
de45d73
Merge upstream into current branch
Mar 6, 2022
47dc9ef
Removing `ConstUSize` and use `ConstU32`
Mar 8, 2022
bcc76e5
cleaning up the code
Mar 9, 2022
b7a7dbf
Merge branch 'paritytech:master' into election-fallback
georgesdib Mar 10, 2022
ee3848a
deprecating `OnChainSequentialPhragmen`
Mar 11, 2022
c760262
Merge branch 'election-fallback' of https://github.com/georgesdib/sub…
Mar 11, 2022
27477c0
Merge branch 'paritytech:master' into election-fallback
georgesdib Mar 11, 2022
d2616bc
Amending docs
Mar 12, 2022
3001d58
Merge branch 'election-fallback' of https://github.com/georgesdib/sub…
Mar 12, 2022
726bfc1
Merge branch 'paritytech:master' into election-fallback
georgesdib Mar 17, 2022
ff9fa7e
Adding some explicit imports
Mar 17, 2022
04eeb7f
Adding some explicit imports
Mar 17, 2022
38e204c
Implementing generic `BoundedOnchainExecution`
Mar 18, 2022
75a459f
Use the right Balancing strategy
Mar 19, 2022
afe8385
Merge branch 'paritytech:master' into election-fallback
georgesdib Mar 19, 2022
598ce52
Refactoring `onchain::Config`
Mar 19, 2022
086ea2d
Merge branch 'master' into election-fallback
Mar 19, 2022
9fdc250
Merge master
Mar 19, 2022
a09a7d7
fmt
Mar 19, 2022
e60e026
Name cleanups after review suggestions
Mar 20, 2022
cd42c4e
cosmetics
Mar 20, 2022
2d698d3
renaming `instant_elect` to `elect_with_bounds`
Mar 20, 2022
7c7c1ba
`BoundedOnchainExecution` -> `BoundedExecution`
Mar 20, 2022
762966f
feedback from kian
kianenigma Mar 21, 2022
5aae3e2
Merge pull request #47 from georgesdib/kiz-election-fallback
georgesdib Mar 21, 2022
ae86c59
fmt + unneeded import
Mar 21, 2022
e4afb57
Moving `onchain::Config` to become a pallet
Mar 25, 2022
0262dd4
merge master
Mar 25, 2022
a5e74ba
Missing import
Mar 25, 2022
8fe4bf5
First stab at benchmarking
Mar 26, 2022
d7a8273
Fixed tests for benchmarking
Mar 26, 2022
0fbe599
fixed the benchmark
Mar 26, 2022
2c840fd
Fully functionting benchmarking
Mar 26, 2022
35a9f83
Refactoring code to avoid duplication
Mar 26, 2022
3b8bb78
Adding weights, first fully working prototype
Mar 27, 2022
2d75103
Adding `PhragMMS` and some cleanups
Mar 27, 2022
a223e0d
Fixing tests everywhere
Mar 27, 2022
e13be98
Implementing default values
Mar 27, 2022
2b62b31
Added a warning
Mar 27, 2022
2cf6336
Fixing rustdocs
Mar 27, 2022
4c466ac
Adding `WeightInfo`
Mar 27, 2022
4566da8
Fixing typo
Mar 27, 2022
def5ed8
Merge branch 'paritytech:master' into npos-election-benchmarking
georgesdib Mar 27, 2022
587077b
Some cleanups
Mar 28, 2022
678b7e5
Merge branch 'npos-election-benchmarking' of https://github.com/georg…
Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ members = [
"frame/election-provider-support",
"frame/election-provider-support/solution-type",
"frame/election-provider-support/solution-type/fuzzer",
"frame/election-provider-support/onchain",
"frame/examples/basic",
"frame/examples/offchain-worker",
"frame/examples/parallel",
Expand Down
3 changes: 3 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = f
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-onchain = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/onchain" }
pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" }
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" }
Expand Down Expand Up @@ -161,6 +162,7 @@ std = [
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"pallet-election-provider-multi-phase/std",
"pallet-election-provider-support-onchain/std",
"pallet-timestamp/std",
"pallet-tips/std",
"pallet-transaction-payment-rpc-runtime-api/std",
Expand Down Expand Up @@ -195,6 +197,7 @@ runtime-benchmarks = [
"pallet-contracts/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-election-provider-support-onchain/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-gilt/runtime-benchmarks",
Expand Down
39 changes: 23 additions & 16 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![recursion_limit = "256"]

use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::{onchain, ExtendedBalance, SequentialPhragmen, VoteWeight};
use frame_election_provider_support::{ExtendedBalance, SequentialPhragmen, VoteWeight};
use frame_support::{
construct_runtime,
pallet_prelude::Get,
Expand All @@ -47,6 +47,7 @@ pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use pallet_contracts::weights::WeightInfo;
use pallet_election_provider_multi_phase::SolutionAccuracyOf;
use pallet_election_provider_support_onchain::BoundedExecution;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
Expand Down Expand Up @@ -557,7 +558,8 @@ impl pallet_staking::Config for Runtime {
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = ElectionProviderMultiPhase;
type GenesisElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider =
BoundedExecution<Self, SequentialPhragmen<AccountId, SolutionAccuracyOf<Runtime>>>;
type VoterList = BagsList;
type MaxUnlockingChunks = ConstU32<32>;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
Expand Down Expand Up @@ -618,6 +620,14 @@ impl pallet_election_provider_multi_phase::BenchmarkingConfig for ElectionProvid
const MAXIMUM_TARGETS: u32 = 300;
}

impl pallet_election_provider_support_onchain::BenchmarkingConfig
for ElectionProviderBenchmarkConfig
{
const VOTERS: [u32; 2] = [1000, 2000];
const TARGETS: [u32; 2] = [500, 1000];
const VOTES_PER_VOTER: [u32; 2] = [5, 16];
}

/// Maximum number of iterations for balancing that will be executed in the embedded OCW
/// miner of election provider multi phase.
pub const MINER_MAX_ITERATIONS: u32 = 10;
Expand All @@ -642,19 +652,12 @@ impl Get<Option<(usize, ExtendedBalance)>> for OffchainRandomBalancing {
}
}

pub struct OnChainSeqPhragmen;
impl onchain::ExecutionConfig for OnChainSeqPhragmen {
type System = Runtime;
type Solver = SequentialPhragmen<
AccountId,
pallet_election_provider_multi_phase::SolutionAccuracyOf<Runtime>,
>;
impl pallet_election_provider_support_onchain::Config for Runtime {
type DataProvider = <Runtime as pallet_election_provider_multi_phase::Config>::DataProvider;
}

impl onchain::BoundedExecutionConfig for OnChainSeqPhragmen {
type VotersBound = ConstU32<20_000>;
type TargetsBound = ConstU32<2_000>;
type MaxVoters = MaxElectingVoters;
type MaxTargets = ConstU32<1_000>;
type BenchmarkingConfig = ElectionProviderBenchmarkConfig;
type WeightInfo = pallet_election_provider_support_onchain::weights::SubstrateWeight<Self>;
}

impl pallet_election_provider_multi_phase::Config for Runtime {
Expand All @@ -678,8 +681,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type RewardHandler = (); // nothing to do upon rewards
type DataProvider = Staking;
type Solution = NposSolution16;
type Fallback = onchain::BoundedExecution<OnChainSeqPhragmen>;
type GovernanceFallback = onchain::BoundedExecution<OnChainSeqPhragmen>;
type Fallback =
BoundedExecution<Self, SequentialPhragmen<AccountId, SolutionAccuracyOf<Runtime>>>;
type GovernanceFallback =
BoundedExecution<Self, SequentialPhragmen<AccountId, SolutionAccuracyOf<Runtime>>>;
type Solver = SequentialPhragmen<AccountId, SolutionAccuracyOf<Self>, OffchainRandomBalancing>;
type ForceOrigin = EnsureRootOrHalfCouncil;
type MaxElectableTargets = ConstU16<{ u16::MAX }>;
Expand Down Expand Up @@ -1420,6 +1425,7 @@ construct_runtime!(
TransactionPayment: pallet_transaction_payment,
AssetTxPayment: pallet_asset_tx_payment,
ElectionProviderMultiPhase: pallet_election_provider_multi_phase,
ElectionProviderSupportOnchain: pallet_election_provider_support_onchain,
Staking: pallet_staking,
Session: pallet_session,
Democracy: pallet_democracy,
Expand Down Expand Up @@ -1531,6 +1537,7 @@ mod benches {
[pallet_contracts, Contracts]
[pallet_democracy, Democracy]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[pallet_election_provider_support_onchain, ElectionProviderSupportOnchain]
[pallet_elections_phragmen, Elections]
[pallet_gilt, Gilt]
[pallet_grandpa, Grandpa]
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pallet-offences = { version = "4.0.0-dev", path = "../offences" }
pallet-staking = { version = "4.0.0-dev", path = "../staking" }
pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../staking/reward-curve" }
sp-core = { version = "6.0.0", path = "../../primitives/core" }
frame-election-provider-support = { version = "4.0.0-dev", path = "../election-provider-support" }
pallet-election-provider-support-onchain = { version = "4.0.0-dev", path = "../election-provider-support/onchain" }

[features]
default = ["std"]
Expand Down
13 changes: 7 additions & 6 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

use crate::{self as pallet_babe, Config, CurrentSlot};
use codec::Encode;
use frame_election_provider_support::{onchain, SequentialPhragmen};
use frame_support::{
parameter_types,
traits::{ConstU128, ConstU32, ConstU64, GenesisBuild, KeyOwnerProofSystem, OnInitialize},
};
use pallet_election_provider_support_onchain::OnChainPhragmen;
use pallet_session::historical as pallet_session_historical;
use sp_consensus_babe::{AuthorityId, AuthorityPair, Slot};
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
Expand Down Expand Up @@ -172,11 +172,12 @@ parameter_types! {
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(16);
}

pub struct OnChainSeqPhragmen;
impl onchain::ExecutionConfig for OnChainSeqPhragmen {
type System = Test;
type Solver = SequentialPhragmen<DummyValidatorId, Perbill>;
impl pallet_election_provider_support_onchain::Config for Test {
type DataProvider = Staking;
type MaxVoters = ConstU32<600>;
type MaxTargets = ConstU32<400>;
type BenchmarkingConfig = ();
type WeightInfo = ();
}

impl pallet_staking::Config for Test {
Expand All @@ -197,7 +198,7 @@ impl pallet_staking::Config for Test {
type MaxNominatorRewardedPerValidator = ConstU32<64>;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type NextNewSession = Session;
type ElectionProvider = onchain::UnboundedExecution<OnChainSeqPhragmen>;
type ElectionProvider = OnChainPhragmen<Self, sp_runtime::Perbill>;
type GenesisElectionProvider = Self::ElectionProvider;
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
type MaxUnlockingChunks = ConstU32<32>;
Expand Down
3 changes: 3 additions & 0 deletions frame/election-provider-multi-phase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rand = { version = "0.7.3", default-features = false, optional = true, features
"small_rng",
] }
strum = { optional = true, default-features = false, version = "0.23.0", features = ["derive"] }
pallet-election-provider-support-onchain = { version = "4.0.0-dev", optional = true, default-features = false, path = "../election-provider-support/onchain" }

[dev-dependencies]
parking_lot = "0.12.0"
Expand Down Expand Up @@ -70,12 +71,14 @@ std = [
"log/std",

"frame-benchmarking/std",
"pallet-election-provider-support-onchain/std",
"rand/std",
"strum/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"pallet-election-provider-support-onchain/runtime-benchmarks",
"rand",
"strum",
]
Expand Down
42 changes: 9 additions & 33 deletions frame/election-provider-multi-phase/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ use frame_support::{
BoundedVec,
};
use frame_system::RawOrigin;
use pallet_election_provider_support_onchain::SEED;
use rand::{prelude::SliceRandom, rngs::SmallRng, SeedableRng};
use sp_arithmetic::{per_things::Percent, traits::One};
use sp_runtime::InnerOf;

const SEED: u32 = 999;
fn set_up_data_provider<T: Config>(voters_len: u32, targets_len: u32) {
pallet_election_provider_support_onchain::set_up_data_provider::<T, T::DataProvider>(
voters_len,
targets_len,
<T::DataProvider as ElectionDataProvider>::MaxVotesPerVoter::get(),
T::Currency::minimum_balance().saturated_into::<u64>() * 1000,
);
}

/// Creates a **valid** solution with exactly the given size.
///
Expand Down Expand Up @@ -154,38 +162,6 @@ fn solution_with_size<T: Config>(
Ok(RawSolution { solution, score, round })
}

fn set_up_data_provider<T: Config>(v: u32, t: u32) {
T::DataProvider::clear();
log!(
info,
"setting up with voters = {} [degree = {}], targets = {}",
v,
<T::DataProvider as ElectionDataProvider>::MaxVotesPerVoter::get(),
t
);

// fill targets.
let mut targets = (0..t)
.map(|i| {
let target = frame_benchmarking::account::<T::AccountId>("Target", i, SEED);
T::DataProvider::add_target(target.clone());
target
})
.collect::<Vec<_>>();
// we should always have enough voters to fill.
assert!(
targets.len() > <T::DataProvider as ElectionDataProvider>::MaxVotesPerVoter::get() as usize
);
targets.truncate(<T::DataProvider as ElectionDataProvider>::MaxVotesPerVoter::get() as usize);

// fill voters.
(0..v).for_each(|i| {
let voter = frame_benchmarking::account::<T::AccountId>("Voter", i, SEED);
let weight = T::Currency::minimum_balance().saturated_into::<u64>() * 1000;
T::DataProvider::add_voter(voter, weight, targets.clone().try_into().unwrap());
});
}

frame_benchmarking::benchmarks! {
on_initialize_nothing {
assert!(<MultiPhase<T>>::current_phase().is_off());
Expand Down
Loading