-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Phragmén Validator Election #1915
Changes from 1 commit
89417a1
cf8157c
b0b8e21
653456f
ee38f86
f969335
2c02b54
89185ec
baf8778
cfaf7b9
9408b95
b2973a3
e9b5244
cabdc5b
9584ac7
747d650
216be37
9365327
d3ad7b4
938bd7b
ed487ec
043d182
d605e26
633bb37
cac9d3f
f8b04a3
3bd69ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -738,7 +738,7 @@ impl<T: Trait> Module<T> { | |
| let mut candidates = candidates.into_iter().filter(|c| c.approval_stake > BalanceOf::<T>::zero()) | ||
| .collect::<Vec<Candidate<T::AccountId, BalanceOf<T>>>>(); | ||
|
|
||
| // If we have more candidates then needed, run phragmen. | ||
| // 4- If we have more candidates then needed, run phragmen. | ||
| if candidates.len() > rounds { | ||
| // Main election loop | ||
| for _round in 0..rounds { | ||
|
|
@@ -771,7 +771,7 @@ impl<T: Trait> Module<T> { | |
| let (winner_index, _) = candidates.iter().enumerate().min_by_key(|&(_i, c)| c.score.extract()) | ||
| .expect("candidates length is checked to be >0; qed"); | ||
|
|
||
| // update nominator and vote load | ||
| // loop 3: update nominator and vote load | ||
| let winner = candidates.remove(winner_index); | ||
| for nominator_idx in 0..nominations.len() { | ||
| for vote_idx in 0..nominations[nominator_idx].nominees.len() { | ||
|
|
@@ -785,10 +785,12 @@ impl<T: Trait> Module<T> { | |
| } | ||
| } | ||
| } | ||
|
|
||
| elected_candidates.push(winner); | ||
|
|
||
| } // end of all rounds | ||
|
|
||
| // Update backing stake of candidates and nominators | ||
| // 4.1- Update backing stake of candidates and nominators | ||
| for nomination in &mut nominations { | ||
| for vote in &mut nomination.nominees { | ||
| // if the target of this vote is among the winners, otherwise let go. | ||
|
|
@@ -818,7 +820,7 @@ impl<T: Trait> Module<T> { | |
| } | ||
| } | ||
|
|
||
| // Figure out the minimum stake behind a slot. | ||
| // 5- Figure out the minimum stake behind a slot. | ||
| let slot_stake; | ||
| if let Some(min_candidate) = elected_candidates.iter().min_by_key(|c| c.exposure.total) { | ||
| slot_stake = min_candidate.exposure.total; | ||
|
|
@@ -828,7 +830,7 @@ impl<T: Trait> Module<T> { | |
| slot_stake = BalanceOf::<T>::zero(); | ||
| } | ||
|
|
||
| // Clear Stakers and reduce their slash_count. | ||
| // 6- Clear Stakers and reduce their slash_count. | ||
| for v in <session::Module<T>>::validators().iter() { | ||
| <Stakers<T>>::remove(v); | ||
| let slash_count = <SlashCount<T>>::take(v); | ||
|
|
@@ -837,12 +839,12 @@ impl<T: Trait> Module<T> { | |
| } | ||
| } | ||
|
|
||
| // Populate Stakers. | ||
| // 7- Populate Stakers. | ||
| for candidate in &elected_candidates { | ||
| <Stakers<T>>::insert(candidate.who.clone(), candidate.exposure.clone()); | ||
| } | ||
|
|
||
| // Set the new validator set. | ||
| // 8- Set the new validator set. | ||
| <session::Module<T>>::set_validators( | ||
| &elected_candidates.into_iter().map(|i| i.who).collect::<Vec<_>>() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You just iterated this list above, maybe merge both iterations?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the new function decomposition its not the same + this is passing the whole
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you refactored and saying that my comment does not apply anymore, what should I do without seeing the new code?(nevertheless, you were iterating this list twice and that does not need to be done)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for reference, you now iterate the same vector 3 times :D |
||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay that can be simplified to