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

Phragmen should ignore "empty" voters #7172

@kianenigma

Description

@kianenigma

We build the voters as such:

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

No one assigned

    Labels

    I4-annoyanceThe 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 coderZ6-mentorAn easy task where a mentor is available. Please indicate in the issue who the mentor could be.

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions