Use VoteAccountsHashMap type alias in all applicable spots (#23904)

This commit is contained in:
steviez
2022-03-24 12:09:48 -05:00
committed by GitHub
parent a22a2384bf
commit c31db81ac4
6 changed files with 42 additions and 46 deletions

View File

@ -61,7 +61,7 @@ use {
status_cache::{SlotDelta, StatusCache},
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
transaction_batch::TransactionBatch,
vote_account::VoteAccount,
vote_account::{VoteAccount, VoteAccountsHashMap},
vote_parser,
},
byteorder::{ByteOrder, LittleEndian},
@ -4524,7 +4524,7 @@ impl Bank {
#[allow(clippy::needless_collect)]
fn distribute_rent_to_validators(
&self,
vote_accounts: &HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>,
vote_accounts: &VoteAccountsHashMap,
rent_to_be_distributed: u64,
) {
let mut total_staked = 0;
@ -6163,7 +6163,7 @@ impl Bank {
/// current vote accounts for this bank along with the stake
/// attributed to each account
pub fn vote_accounts(&self) -> Arc<HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>> {
pub fn vote_accounts(&self) -> Arc<VoteAccountsHashMap> {
let stakes = self.stakes_cache.stakes();
Arc::from(stakes.vote_accounts())
}
@ -6189,10 +6189,7 @@ impl Bank {
/// vote accounts for the specific epoch along with the stake
/// attributed to each account
pub fn epoch_vote_accounts(
&self,
epoch: Epoch,
) -> Option<&HashMap<Pubkey, (u64, VoteAccount)>> {
pub fn epoch_vote_accounts(&self, epoch: Epoch) -> Option<&VoteAccountsHashMap> {
let epoch_stakes = self.epoch_stakes.get(&epoch)?.stakes();
Some(epoch_stakes.vote_accounts().as_ref())
}

View File

@ -1,5 +1,5 @@
use {
crate::{stakes::Stakes, vote_account::VoteAccount},
crate::{stakes::Stakes, vote_account::VoteAccountsHashMap},
serde::{Deserialize, Serialize},
solana_sdk::{clock::Epoch, pubkey::Pubkey},
std::{collections::HashMap, sync::Arc},
@ -60,7 +60,7 @@ impl EpochStakes {
}
fn parse_epoch_vote_accounts(
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
epoch_vote_accounts: &VoteAccountsHashMap,
leader_schedule_epoch: Epoch,
) -> (u64, NodeIdToVoteAccounts, EpochAuthorizedVoters) {
let mut node_id_to_vote_accounts: NodeIdToVoteAccounts = HashMap::new();
@ -119,7 +119,7 @@ impl EpochStakes {
#[cfg(test)]
pub(crate) mod tests {
use {
super::*, solana_sdk::account::AccountSharedData,
super::*, crate::vote_account::VoteAccount, solana_sdk::account::AccountSharedData,
solana_vote_program::vote_state::create_account_with_authorized, std::iter,
};

View File

@ -460,7 +460,7 @@ mod tests {
#[test]
fn test_vote_accounts_serialize() {
let mut rng = rand::thread_rng();
let vote_accounts_hash_map: HashMap<Pubkey, (u64, VoteAccount)> =
let vote_accounts_hash_map: VoteAccountsHashMap =
new_rand_vote_accounts(&mut rng, 64).take(1024).collect();
let vote_accounts = VoteAccounts::from(Arc::new(vote_accounts_hash_map.clone()));
assert!(vote_accounts.staked_nodes().len() > 32);
@ -479,7 +479,7 @@ mod tests {
#[test]
fn test_vote_accounts_deserialize() {
let mut rng = rand::thread_rng();
let vote_accounts_hash_map: HashMap<Pubkey, (u64, VoteAccount)> =
let vote_accounts_hash_map: VoteAccountsHashMap =
new_rand_vote_accounts(&mut rng, 64).take(1024).collect();
let data = bincode::serialize(&vote_accounts_hash_map).unwrap();
let vote_accounts: VoteAccounts = bincode::deserialize(&data).unwrap();