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
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Phragmen should ignore "empty" voters #7172
Copy link
Copy link
Closed
Labels
I4-annoyanceThe client behaves within expectations, however this “expected behaviour” itself is at issue.The client behaves within expectations, however this “expected behaviour” itself is at issue.Z1-easyCan be fixed primarily by duplicating and adapting code by an intermediate coderCan be fixed primarily by duplicating and adapting code by an intermediate coderZ6-mentorAn easy task where a mentor is available. Please indicate in the issue who the mentor could be.An easy task where a mentor is available. Please indicate in the issue who the mentor could be.
Description
We build the voters as such:
substrate/primitives/npos-elections/src/lib.rs
Lines 385 to 405 in 0c8329c
| voters.extend(initial_voters.into_iter().map(|(who, voter_stake, votes)| { | |
| let mut edges: Vec<Edge<AccountId>> = Vec::with_capacity(votes.len()); | |
| for v in votes { | |
| if edges.iter().any(|e| e.who == v) { | |
| // duplicate edge. | |
| continue; | |
| } | |
| if let Some(idx) = c_idx_cache.get(&v) { | |
| // This candidate is valid + already cached. | |
| candidates[*idx].approval_stake = candidates[*idx].approval_stake | |
| .saturating_add(voter_stake.into()); | |
| edges.push(Edge { who: v.clone(), candidate_index: *idx, ..Default::default() }); | |
| } // else {} would be wrong votes. We don't really care about it. | |
| } | |
| Voter { | |
| who, | |
| edges: edges, | |
| budget: voter_stake.into(), | |
| load: Rational128::zero(), | |
| } | |
| })); |
If by the end of the map(), edges.len() is empty, then this voter should not be even included. Essentially, we have to change the map() to filter_map.
Ideally there should be a test added for this, else we need to make sure the change is reflected in #6685 as well.
This (as far as I know) does not cause any issues. It is just extra iterations here and there that will make the execution a bit slower.
Metadata
Metadata
Assignees
Labels
I4-annoyanceThe client behaves within expectations, however this “expected behaviour” itself is at issue.The client behaves within expectations, however this “expected behaviour” itself is at issue.Z1-easyCan be fixed primarily by duplicating and adapting code by an intermediate coderCan be fixed primarily by duplicating and adapting code by an intermediate coderZ6-mentorAn easy task where a mentor is available. Please indicate in the issue who the mentor could be.An easy task where a mentor is available. Please indicate in the issue who the mentor could be.
Type
Projects
Status
✅ Done