Sensible way of selecting Prime member (#5346)

* Calculate prime votes only during the election

* Migration

* Fix build, enable migration

* Fix tests

* Bump runtime version

* Update frame/elections-phragmen/src/lib.rs

Co-Authored-By: Marcio Diaz <marcio.diaz@gmail.com>

Co-authored-by: Marcio Diaz <marcio.diaz@gmail.com>
This commit is contained in:
Gavin Wood
2020-03-23 11:52:44 +01:00
committed by GitHub
parent 1da48b3b3f
commit 95d1d668c3
7 changed files with 135 additions and 79 deletions
+7 -5
View File
@@ -1810,11 +1810,11 @@ impl<T: Trait> Module<T> {
///
/// Assumes storage is coherent with the declaration.
fn select_validators(current_era: EraIndex) -> Option<Vec<T::AccountId>> {
let mut all_nominators: Vec<(T::AccountId, Vec<T::AccountId>)> = Vec::new();
let mut all_nominators: Vec<(T::AccountId, BalanceOf<T>, Vec<T::AccountId>)> = Vec::new();
let mut all_validators_and_prefs = BTreeMap::new();
let mut all_validators = Vec::new();
for (validator, preference) in <Validators<T>>::iter() {
let self_vote = (validator.clone(), vec![validator.clone()]);
let self_vote = (validator.clone(), Self::slashable_balance_of(&validator), vec![validator.clone()]);
all_nominators.push(self_vote);
all_validators_and_prefs.insert(validator.clone(), preference);
all_validators.push(validator);
@@ -1834,14 +1834,16 @@ impl<T: Trait> Module<T> {
(nominator, targets)
});
all_nominators.extend(nominator_votes);
all_nominators.extend(nominator_votes.map(|(n, ns)| {
let s = Self::slashable_balance_of(&n);
(n, s, ns)
}));
let maybe_phragmen_result = sp_phragmen::elect::<_, _, _, T::CurrencyToVote, Perbill>(
let maybe_phragmen_result = sp_phragmen::elect::<_, _, T::CurrencyToVote, Perbill>(
Self::validator_count() as usize,
Self::minimum_validator_count().max(1) as usize,
all_validators,
all_nominators,
Self::slashable_balance_of,
);
if let Some(phragmen_result) = maybe_phragmen_result {