Create gossip vote iterator sorted by stake weight (#30697)
This commit is contained in:
parent
11c942ab40
commit
9b587bf073
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue