Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Bound elections-phragmen pallet #12549

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
69a8b37
Bound Phragmen
Szegoo Oct 23, 2022
5ccfd97
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Oct 24, 2022
82e9f07
fixes
Szegoo Oct 24, 2022
03148fe
passing tests
Szegoo Oct 25, 2022
807bd58
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Oct 25, 2022
f61ea32
map_err
Szegoo Oct 25, 2022
f6ec1e7
define bounds in runtime
Szegoo Oct 25, 2022
eae55fa
fix CI
Szegoo Oct 26, 2022
5e65bfa
fix
Szegoo Oct 26, 2022
a201e5a
..
Szegoo Oct 26, 2022
619a707
update benchmarks
Szegoo Oct 26, 2022
09d7596
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Oct 26, 2022
c2b71d8
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Oct 28, 2022
0589f64
fixes
Szegoo Oct 29, 2022
38d1c01
error messages updated
Szegoo Oct 29, 2022
e162a6f
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Oct 30, 2022
872c176
Update frame/elections-phragmen/src/lib.rs
Szegoo Nov 2, 2022
c157249
fix
Szegoo Nov 2, 2022
f06dc4c
remove TypeInfo
Szegoo Nov 2, 2022
2960402
update
Szegoo Nov 4, 2022
1afa5b3
fix
Szegoo Nov 5, 2022
bc93503
handle error
Szegoo Nov 6, 2022
b5ee15d
fix logic
Szegoo Nov 6, 2022
0b2c12e
make clippy happy
Szegoo Nov 6, 2022
e737539
nit fix
Szegoo Nov 8, 2022
6f3f2ee
remove redundent checks
Szegoo Nov 11, 2022
962b317
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Nov 11, 2022
04c5a82
fix
Szegoo Nov 12, 2022
076671a
Update frame/elections-phragmen/src/lib.rs
Szegoo Nov 24, 2022
0ad62c1
Update frame/elections-phragmen/src/lib.rs
Szegoo Nov 24, 2022
ff0281f
migration
Szegoo Nov 25, 2022
359cac1
complete migrations
Szegoo Nov 27, 2022
68d3cbc
change copyright year
Szegoo Nov 27, 2022
7f93a12
error handling
Szegoo Nov 27, 2022
d6b0c69
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Dec 3, 2022
21fa0dc
try-runtime
Szegoo Dec 4, 2022
f2aebeb
remove warning
Szegoo Dec 4, 2022
fd58b5a
testing migrations
Szegoo Dec 5, 2022
7f39aec
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Dec 5, 2022
7f78052
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Jan 16, 2023
04d0451
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Jan 28, 2023
70e7821
Merge branch 'master' into bound-phragmen
Szegoo Feb 24, 2023
1690a00
pallet & migration builds; tests don't
Szegoo Feb 27, 2023
e13bb41
update extrinsic votes arg
Szegoo Feb 27, 2023
839f85d
safer approach
Szegoo Mar 5, 2023
911db04
Merge branch 'paritytech:master' into bound-phragmen
Szegoo Apr 5, 2023
10be77e
Merge branch 'paritytech:master' into bound-phragmen
Szegoo May 25, 2023
a844619
Merge branch 'master' into bound-phragmen
Szegoo Jul 24, 2023
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
6 changes: 5 additions & 1 deletion bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ pub fn testnet_genesis(
.take((num_endowed_accounts + 1) / 2)
.cloned()
.map(|member| (member, STASH))
.collect(),
.collect::<Vec<(AccountId, Balance)>>()
.try_into()
.expect(
"Elections-Phragmen: Cannot accept more than DesiredMembers genesis member.",
),
},
council: CouncilConfig::default(),
technical_committee: TechnicalCommitteeConfig {
Expand Down
24 changes: 15 additions & 9 deletions frame/elections-phragmen/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ fn submit_candidates_with_self_vote<T: Config>(
) -> Result<Vec<T::AccountId>, &'static str> {
let candidates = submit_candidates::<T>(c, prefix)?;
let stake = default_stake::<T>(c);
let _ = candidates
.iter()
.try_for_each(|c| submit_voter::<T>(c.clone(), vec![c.clone()], stake).map(|_| ()))?;
let _ = candidates.iter().try_for_each(|c| {
submit_voter::<T>(c.clone(), vec![c.clone()].try_into().unwrap(), stake).map(|_| ())
})?;
Ok(candidates)
}

Expand All @@ -96,7 +96,7 @@ fn submit_voter<T: Config>(
votes: Vec<T::AccountId>,
stake: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
<Elections<T>>::vote(RawOrigin::Signed(caller).into(), votes, stake)
<Elections<T>>::vote(RawOrigin::Signed(caller).into(), votes.try_into().unwrap(), stake)
}

/// create `num_voter` voters who randomly vote for at most `votes` of `all_candidates` if
Expand All @@ -110,7 +110,13 @@ fn distribute_voters<T: Config>(
for i in 0..num_voters {
// to ensure that votes are different
all_candidates.rotate_left(1);
let votes = all_candidates.iter().cloned().take(votes).collect::<Vec<_>>();
let votes = all_candidates
.iter()
.cloned()
.take(votes)
.collect::<Vec<_>>()
.try_into()
.unwrap();
let voter = endowed_account::<T>("voter", i);
submit_voter::<T>(voter, votes, stake)?;
}
Expand Down Expand Up @@ -165,7 +171,7 @@ benchmarks! {
votes.rotate_left(1);

whitelist!(caller);
}: vote(RawOrigin::Signed(caller), votes, stake)
}: vote(RawOrigin::Signed(caller), votes.try_into().unwrap(), stake)

vote_more {
let v in 2 .. T::MaxVotesPerVoter::get();
Expand All @@ -187,7 +193,7 @@ benchmarks! {
assert!(votes.len() > <Voting<T>>::get(caller.clone()).votes.len());

whitelist!(caller);
}: vote(RawOrigin::Signed(caller), votes, stake / <BalanceOf<T>>::from(10u32))
}: vote(RawOrigin::Signed(caller), votes.try_into().unwrap(), stake / <BalanceOf<T>>::from(10u32))

vote_less {
let v in 2 .. T::MaxVotesPerVoter::get();
Expand All @@ -208,7 +214,7 @@ benchmarks! {
assert!(votes.len() < <Voting<T>>::get(caller.clone()).votes.len());

whitelist!(caller);
}: vote(RawOrigin::Signed(caller), votes, stake)
}: vote(RawOrigin::Signed(caller), votes.try_into().unwrap(), stake)

remove_voter {
// we fix the number of voted candidates to max
Expand All @@ -228,7 +234,7 @@ benchmarks! {

submit_candidacy {
// number of already existing candidates.
let c in 1 .. T::MaxCandidates::get();
let c in 1 .. T::MaxCandidates::get() - 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why we subtract one here is very simple actually. It is because we submit 1..T::MaxCandidates::get() before executing _(RawOrigin::Signed(candidate_account.clone()), candidate_count::<T>()) where we also submit a candidacy. So we cannot have more than T::MaxCandidates::get() candidates so that is why we subtract one. @gpestana

// we fix the number of members to the number of desired members and runners-up. We'll be in
// this state almost always.
let m = T::DesiredMembers::get() + T::DesiredRunnersUp::get();
Expand Down
Loading
Loading