Refactor: Add get_delegated_stake method to VoteAccounts (#26221)

This commit is contained in:
Justin Starry 2022-06-25 17:41:35 +01:00 committed by GitHub
parent 44d1e62007
commit 7cd7173b71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View File

@ -611,10 +611,7 @@ impl ClusterInfoVoteListener {
// 2) We do not know the hash of the earlier slot
if slot == last_vote_slot {
let vote_accounts = epoch_stakes.stakes().vote_accounts();
let stake = vote_accounts
.get(vote_pubkey)
.map(|(stake, _)| *stake)
.unwrap_or_default();
let stake = vote_accounts.get_delegated_stake(vote_pubkey);
let total_stake = epoch_stakes.total_stake();
// Fast track processing of the last slot in a vote transactions
@ -795,9 +792,7 @@ impl ClusterInfoVoteListener {
fn sum_stake(sum: &mut u64, epoch_stakes: Option<&EpochStakes>, pubkey: &Pubkey) {
if let Some(stakes) = epoch_stakes {
if let Some(vote_account) = stakes.stakes().vote_accounts().get(pubkey) {
*sum += vote_account.0;
}
*sum += stakes.stakes().vote_accounts().get_delegated_stake(pubkey)
}
}
}

View File

@ -55,9 +55,7 @@ impl EpochStakes {
pub fn vote_account_stake(&self, vote_account: &Pubkey) -> u64 {
self.stakes
.vote_accounts()
.get(vote_account)
.map(|(stake, _)| *stake)
.unwrap_or(0)
.get_delegated_stake(vote_account)
}
fn parse_epoch_vote_accounts(

View File

@ -124,6 +124,13 @@ impl VoteAccounts {
self.vote_accounts.get(pubkey)
}
pub fn get_delegated_stake(&self, pubkey: &Pubkey) -> u64 {
self.vote_accounts
.get(pubkey)
.map(|(stake, ..)| *stake)
.unwrap_or_default()
}
pub(crate) fn iter(&self) -> impl Iterator<Item = (&Pubkey, &(u64, VoteAccount))> {
self.vote_accounts.iter()
}