removes hash-map lookups when sorting vote-account keys (#30878)

This commit is contained in:
behzad nouri 2023-03-23 22:29:35 +00:00 committed by GitHub
parent 653083806f
commit a36e8f559c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 15 deletions

View File

@ -1,5 +1,6 @@
use { use {
crate::{cluster_info_vote_listener::VerifiedLabelVotePacketsReceiver, result::Result}, crate::{cluster_info_vote_listener::VerifiedLabelVotePacketsReceiver, result::Result},
itertools::Itertools,
solana_perf::packet::PacketBatch, solana_perf::packet::PacketBatch,
solana_runtime::{ solana_runtime::{
bank::Bank, bank::Bank,
@ -59,22 +60,14 @@ impl<'a> ValidatorGossipVotesIterator<'a> {
// TODO: my_leader_bank.vote_accounts() may not contain zero-staked validators // 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 // in this epoch, but those validators may have stake warming up in the next epoch
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 // Sort by stake weight so heavier validators' votes are sent first
vote_account_keys.sort_by(|a, b| { let vote_account_keys: Vec<Pubkey> = my_leader_bank
my_leader_bank .vote_accounts()
.vote_accounts() .iter()
.get(b) .map(|(pubkey, &(stake, _))| (pubkey, stake))
.map_or(0, |(stake, _)| *stake) .sorted_unstable_by_key(|&(_, stake)| std::cmp::Reverse(stake))
.cmp( .map(|(&pubkey, _)| pubkey)
&my_leader_bank .collect();
.vote_accounts()
.get(a)
.map_or(0, |(stake, _)| *stake),
)
});
Self { Self {
my_leader_bank, my_leader_bank,
slot_hashes, slot_hashes,