Use VoteAccountsHashMap type alias in all applicable spots (#23904)
This commit is contained in:
parent
a22a2384bf
commit
c31db81ac4
@ -10,7 +10,7 @@ use {
|
|||||||
solana_ledger::{ancestor_iterator::AncestorIterator, blockstore::Blockstore, blockstore_db},
|
solana_ledger::{ancestor_iterator::AncestorIterator, blockstore::Blockstore, blockstore_db},
|
||||||
solana_runtime::{
|
solana_runtime::{
|
||||||
bank::Bank, bank_forks::BankForks, commitment::VOTE_THRESHOLD_SIZE,
|
bank::Bank, bank_forks::BankForks, commitment::VOTE_THRESHOLD_SIZE,
|
||||||
vote_account::VoteAccount,
|
vote_account::VoteAccountsHashMap,
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
clock::{Slot, UnixTimestamp},
|
clock::{Slot, UnixTimestamp},
|
||||||
@ -253,7 +253,7 @@ impl Tower {
|
|||||||
pub(crate) fn collect_vote_lockouts(
|
pub(crate) fn collect_vote_lockouts(
|
||||||
vote_account_pubkey: &Pubkey,
|
vote_account_pubkey: &Pubkey,
|
||||||
bank_slot: Slot,
|
bank_slot: Slot,
|
||||||
vote_accounts: &HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>,
|
vote_accounts: &VoteAccountsHashMap,
|
||||||
ancestors: &HashMap<Slot, HashSet<Slot>>,
|
ancestors: &HashMap<Slot, HashSet<Slot>>,
|
||||||
get_frozen_hash: impl Fn(Slot) -> Option<Hash>,
|
get_frozen_hash: impl Fn(Slot) -> Option<Hash>,
|
||||||
latest_validator_votes_for_frozen_banks: &mut LatestValidatorVotesForFrozenBanks,
|
latest_validator_votes_for_frozen_banks: &mut LatestValidatorVotesForFrozenBanks,
|
||||||
@ -636,7 +636,7 @@ impl Tower {
|
|||||||
descendants: &HashMap<Slot, HashSet<u64>>,
|
descendants: &HashMap<Slot, HashSet<u64>>,
|
||||||
progress: &ProgressMap,
|
progress: &ProgressMap,
|
||||||
total_stake: u64,
|
total_stake: u64,
|
||||||
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
epoch_vote_accounts: &VoteAccountsHashMap,
|
||||||
latest_validator_votes_for_frozen_banks: &LatestValidatorVotesForFrozenBanks,
|
latest_validator_votes_for_frozen_banks: &LatestValidatorVotesForFrozenBanks,
|
||||||
heaviest_subtree_fork_choice: &HeaviestSubtreeForkChoice,
|
heaviest_subtree_fork_choice: &HeaviestSubtreeForkChoice,
|
||||||
) -> SwitchForkDecision {
|
) -> SwitchForkDecision {
|
||||||
@ -929,7 +929,7 @@ impl Tower {
|
|||||||
descendants: &HashMap<Slot, HashSet<u64>>,
|
descendants: &HashMap<Slot, HashSet<u64>>,
|
||||||
progress: &ProgressMap,
|
progress: &ProgressMap,
|
||||||
total_stake: u64,
|
total_stake: u64,
|
||||||
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
epoch_vote_accounts: &VoteAccountsHashMap,
|
||||||
latest_validator_votes_for_frozen_banks: &LatestValidatorVotesForFrozenBanks,
|
latest_validator_votes_for_frozen_banks: &LatestValidatorVotesForFrozenBanks,
|
||||||
heaviest_subtree_fork_choice: &HeaviestSubtreeForkChoice,
|
heaviest_subtree_fork_choice: &HeaviestSubtreeForkChoice,
|
||||||
) -> SwitchForkDecision {
|
) -> SwitchForkDecision {
|
||||||
@ -1377,7 +1377,7 @@ pub mod test {
|
|||||||
},
|
},
|
||||||
itertools::Itertools,
|
itertools::Itertools,
|
||||||
solana_ledger::{blockstore::make_slot_entries, get_tmp_ledger_path},
|
solana_ledger::{blockstore::make_slot_entries, get_tmp_ledger_path},
|
||||||
solana_runtime::bank::Bank,
|
solana_runtime::{bank::Bank, vote_account::VoteAccount},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
|
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
@ -1398,7 +1398,7 @@ pub mod test {
|
|||||||
trees::tr,
|
trees::tr,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn gen_stakes(stake_votes: &[(u64, &[u64])]) -> HashMap<Pubkey, (u64, VoteAccount)> {
|
fn gen_stakes(stake_votes: &[(u64, &[u64])]) -> VoteAccountsHashMap {
|
||||||
stake_votes
|
stake_votes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(lamports, votes)| {
|
.map(|(lamports, votes)| {
|
||||||
|
@ -7,7 +7,7 @@ use {
|
|||||||
},
|
},
|
||||||
solana_ledger::blockstore_processor::{ConfirmationProgress, ConfirmationTiming},
|
solana_ledger::blockstore_processor::{ConfirmationProgress, ConfirmationTiming},
|
||||||
solana_program_runtime::timings::ExecuteTimingType,
|
solana_program_runtime::timings::ExecuteTimingType,
|
||||||
solana_runtime::{bank::Bank, bank_forks::BankForks, vote_account::VoteAccount},
|
solana_runtime::{bank::Bank, bank_forks::BankForks, vote_account::VoteAccountsHashMap},
|
||||||
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey},
|
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey},
|
||||||
std::{
|
std::{
|
||||||
collections::{BTreeMap, HashMap, HashSet},
|
collections::{BTreeMap, HashMap, HashSet},
|
||||||
@ -516,7 +516,7 @@ impl PropagatedStats {
|
|||||||
&mut self,
|
&mut self,
|
||||||
node_pubkey: &Pubkey,
|
node_pubkey: &Pubkey,
|
||||||
vote_account_pubkeys: &[Pubkey],
|
vote_account_pubkeys: &[Pubkey],
|
||||||
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
epoch_vote_accounts: &VoteAccountsHashMap,
|
||||||
) {
|
) {
|
||||||
self.propagated_node_ids.insert(*node_pubkey);
|
self.propagated_node_ids.insert(*node_pubkey);
|
||||||
for vote_account_pubkey in vote_account_pubkeys.iter() {
|
for vote_account_pubkey in vote_account_pubkeys.iter() {
|
||||||
@ -695,7 +695,7 @@ impl ProgressMap {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use {super::*, solana_runtime::vote_account::VoteAccount};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_add_vote_pubkey() {
|
fn test_add_vote_pubkey() {
|
||||||
|
@ -34,7 +34,7 @@ use {
|
|||||||
snapshot_utils,
|
snapshot_utils,
|
||||||
transaction_batch::TransactionBatch,
|
transaction_batch::TransactionBatch,
|
||||||
transaction_cost_metrics_sender::TransactionCostMetricsSender,
|
transaction_cost_metrics_sender::TransactionCostMetricsSender,
|
||||||
vote_account::VoteAccount,
|
vote_account::VoteAccountsHashMap,
|
||||||
vote_sender_types::ReplayVoteSender,
|
vote_sender_types::ReplayVoteSender,
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
@ -1349,7 +1349,7 @@ fn supermajority_root(roots: &[(Slot, u64)], total_epoch_stake: u64) -> Option<S
|
|||||||
fn supermajority_root_from_vote_accounts(
|
fn supermajority_root_from_vote_accounts(
|
||||||
bank_slot: Slot,
|
bank_slot: Slot,
|
||||||
total_epoch_stake: u64,
|
total_epoch_stake: u64,
|
||||||
vote_accounts: &HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>,
|
vote_accounts: &VoteAccountsHashMap,
|
||||||
) -> Option<Slot> {
|
) -> Option<Slot> {
|
||||||
let mut roots_stakes: Vec<(Slot, u64)> = vote_accounts
|
let mut roots_stakes: Vec<(Slot, u64)> = vote_accounts
|
||||||
.iter()
|
.iter()
|
||||||
@ -1551,8 +1551,11 @@ pub mod tests {
|
|||||||
matches::assert_matches,
|
matches::assert_matches,
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
solana_entry::entry::{create_ticks, next_entry, next_entry_mut},
|
solana_entry::entry::{create_ticks, next_entry, next_entry_mut},
|
||||||
solana_runtime::genesis_utils::{
|
solana_runtime::{
|
||||||
self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs,
|
genesis_utils::{
|
||||||
|
self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs,
|
||||||
|
},
|
||||||
|
vote_account::VoteAccount,
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{AccountSharedData, WritableAccount},
|
account::{AccountSharedData, WritableAccount},
|
||||||
@ -3799,27 +3802,23 @@ pub mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[allow(clippy::field_reassign_with_default)]
|
#[allow(clippy::field_reassign_with_default)]
|
||||||
fn test_supermajority_root_from_vote_accounts() {
|
fn test_supermajority_root_from_vote_accounts() {
|
||||||
let convert_to_vote_accounts =
|
let convert_to_vote_accounts = |roots_stakes: Vec<(Slot, u64)>| -> VoteAccountsHashMap {
|
||||||
|roots_stakes: Vec<(Slot, u64)>| -> HashMap<Pubkey, (u64, VoteAccount)> {
|
roots_stakes
|
||||||
roots_stakes
|
.into_iter()
|
||||||
.into_iter()
|
.map(|(root, stake)| {
|
||||||
.map(|(root, stake)| {
|
let mut vote_state = VoteState::default();
|
||||||
let mut vote_state = VoteState::default();
|
vote_state.root_slot = Some(root);
|
||||||
vote_state.root_slot = Some(root);
|
let mut vote_account =
|
||||||
let mut vote_account = AccountSharedData::new(
|
AccountSharedData::new(1, VoteState::size_of(), &solana_vote_program::id());
|
||||||
1,
|
let versioned = VoteStateVersions::new_current(vote_state);
|
||||||
VoteState::size_of(),
|
VoteState::serialize(&versioned, vote_account.data_as_mut_slice()).unwrap();
|
||||||
&solana_vote_program::id(),
|
(
|
||||||
);
|
solana_sdk::pubkey::new_rand(),
|
||||||
let versioned = VoteStateVersions::new_current(vote_state);
|
(stake, VoteAccount::from(vote_account)),
|
||||||
VoteState::serialize(&versioned, vote_account.data_as_mut_slice()).unwrap();
|
)
|
||||||
(
|
})
|
||||||
solana_sdk::pubkey::new_rand(),
|
.collect()
|
||||||
(stake, VoteAccount::from(vote_account)),
|
};
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
};
|
|
||||||
|
|
||||||
let total_stake = 10;
|
let total_stake = 10;
|
||||||
let slot = 100;
|
let slot = 100;
|
||||||
|
@ -61,7 +61,7 @@ use {
|
|||||||
status_cache::{SlotDelta, StatusCache},
|
status_cache::{SlotDelta, StatusCache},
|
||||||
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
|
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
|
||||||
transaction_batch::TransactionBatch,
|
transaction_batch::TransactionBatch,
|
||||||
vote_account::VoteAccount,
|
vote_account::{VoteAccount, VoteAccountsHashMap},
|
||||||
vote_parser,
|
vote_parser,
|
||||||
},
|
},
|
||||||
byteorder::{ByteOrder, LittleEndian},
|
byteorder::{ByteOrder, LittleEndian},
|
||||||
@ -4524,7 +4524,7 @@ impl Bank {
|
|||||||
#[allow(clippy::needless_collect)]
|
#[allow(clippy::needless_collect)]
|
||||||
fn distribute_rent_to_validators(
|
fn distribute_rent_to_validators(
|
||||||
&self,
|
&self,
|
||||||
vote_accounts: &HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>,
|
vote_accounts: &VoteAccountsHashMap,
|
||||||
rent_to_be_distributed: u64,
|
rent_to_be_distributed: u64,
|
||||||
) {
|
) {
|
||||||
let mut total_staked = 0;
|
let mut total_staked = 0;
|
||||||
@ -6163,7 +6163,7 @@ impl Bank {
|
|||||||
|
|
||||||
/// current vote accounts for this bank along with the stake
|
/// current vote accounts for this bank along with the stake
|
||||||
/// attributed to each account
|
/// 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();
|
let stakes = self.stakes_cache.stakes();
|
||||||
Arc::from(stakes.vote_accounts())
|
Arc::from(stakes.vote_accounts())
|
||||||
}
|
}
|
||||||
@ -6189,10 +6189,7 @@ impl Bank {
|
|||||||
|
|
||||||
/// vote accounts for the specific epoch along with the stake
|
/// vote accounts for the specific epoch along with the stake
|
||||||
/// attributed to each account
|
/// attributed to each account
|
||||||
pub fn epoch_vote_accounts(
|
pub fn epoch_vote_accounts(&self, epoch: Epoch) -> Option<&VoteAccountsHashMap> {
|
||||||
&self,
|
|
||||||
epoch: Epoch,
|
|
||||||
) -> Option<&HashMap<Pubkey, (u64, VoteAccount)>> {
|
|
||||||
let epoch_stakes = self.epoch_stakes.get(&epoch)?.stakes();
|
let epoch_stakes = self.epoch_stakes.get(&epoch)?.stakes();
|
||||||
Some(epoch_stakes.vote_accounts().as_ref())
|
Some(epoch_stakes.vote_accounts().as_ref())
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use {
|
use {
|
||||||
crate::{stakes::Stakes, vote_account::VoteAccount},
|
crate::{stakes::Stakes, vote_account::VoteAccountsHashMap},
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
solana_sdk::{clock::Epoch, pubkey::Pubkey},
|
solana_sdk::{clock::Epoch, pubkey::Pubkey},
|
||||||
std::{collections::HashMap, sync::Arc},
|
std::{collections::HashMap, sync::Arc},
|
||||||
@ -60,7 +60,7 @@ impl EpochStakes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_epoch_vote_accounts(
|
fn parse_epoch_vote_accounts(
|
||||||
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
epoch_vote_accounts: &VoteAccountsHashMap,
|
||||||
leader_schedule_epoch: Epoch,
|
leader_schedule_epoch: Epoch,
|
||||||
) -> (u64, NodeIdToVoteAccounts, EpochAuthorizedVoters) {
|
) -> (u64, NodeIdToVoteAccounts, EpochAuthorizedVoters) {
|
||||||
let mut node_id_to_vote_accounts: NodeIdToVoteAccounts = HashMap::new();
|
let mut node_id_to_vote_accounts: NodeIdToVoteAccounts = HashMap::new();
|
||||||
@ -119,7 +119,7 @@ impl EpochStakes {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use {
|
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,
|
solana_vote_program::vote_state::create_account_with_authorized, std::iter,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_vote_accounts_serialize() {
|
fn test_vote_accounts_serialize() {
|
||||||
let mut rng = rand::thread_rng();
|
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();
|
new_rand_vote_accounts(&mut rng, 64).take(1024).collect();
|
||||||
let vote_accounts = VoteAccounts::from(Arc::new(vote_accounts_hash_map.clone()));
|
let vote_accounts = VoteAccounts::from(Arc::new(vote_accounts_hash_map.clone()));
|
||||||
assert!(vote_accounts.staked_nodes().len() > 32);
|
assert!(vote_accounts.staked_nodes().len() > 32);
|
||||||
@ -479,7 +479,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_vote_accounts_deserialize() {
|
fn test_vote_accounts_deserialize() {
|
||||||
let mut rng = rand::thread_rng();
|
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();
|
new_rand_vote_accounts(&mut rng, 64).take(1024).collect();
|
||||||
let data = bincode::serialize(&vote_accounts_hash_map).unwrap();
|
let data = bincode::serialize(&vote_accounts_hash_map).unwrap();
|
||||||
let vote_accounts: VoteAccounts = bincode::deserialize(&data).unwrap();
|
let vote_accounts: VoteAccounts = bincode::deserialize(&data).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user