Create gossip vote iterator sorted by stake weight (#30697)

This commit is contained in:
Brennan 2023-03-14 08:43:01 -07:00 committed by GitHub
parent 11c942ab40
commit 9b587bf073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -59,8 +59,21 @@ impl<'a> ValidatorGossipVotesIterator<'a> {
// TODO: my_leader_bank.vote_accounts() may not contain zero-staked validators
// in this epoch, but those validators may have stake warming up in the next epoch
let vote_account_keys: Vec<Pubkey> =
let mut vote_account_keys: Vec<Pubkey> =
my_leader_bank.vote_accounts().keys().copied().collect();
// Sort by stake weight so heavier validators' votes are sent first
vote_account_keys.sort_by(|a, b| {
my_leader_bank
.vote_accounts()
.get(b)
.map_or(0, |(stake, _)| *stake)
.cmp(
&my_leader_bank
.vote_accounts()
.get(a)
.map_or(0, |(stake, _)| *stake),
)
});
Self {
my_leader_bank,
@ -107,7 +120,6 @@ impl<'a> Iterator for ValidatorGossipVotesIterator<'a> {
fn next(&mut self) -> Option<Self::Item> {
use SingleValidatorVotes::*;
// TODO: Maybe prioritize by stake weight
while !self.vote_account_keys.is_empty() {
let vote_account_key = self.vote_account_keys.pop().unwrap();
// Get all the gossip votes we've queued up for this validator