renames solana_runtime::vote_account::VoteAccount
Rename: VoteAccount -> VoteAccountInner # the private type ArcVoteAccount -> VoteAccount # the public type
This commit is contained in:
parent
1403eaeefc
commit
00e5e12906
|
@ -8,7 +8,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::ArcVoteAccount,
|
vote_account::VoteAccount,
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
clock::{Slot, UnixTimestamp},
|
clock::{Slot, UnixTimestamp},
|
||||||
|
@ -209,7 +209,7 @@ impl Tower {
|
||||||
latest_validator_votes_for_frozen_banks: &mut LatestValidatorVotesForFrozenBanks,
|
latest_validator_votes_for_frozen_banks: &mut LatestValidatorVotesForFrozenBanks,
|
||||||
) -> ComputedBankState
|
) -> ComputedBankState
|
||||||
where
|
where
|
||||||
F: IntoIterator<Item = (Pubkey, (u64, ArcVoteAccount))>,
|
F: IntoIterator<Item = (Pubkey, (u64, VoteAccount))>,
|
||||||
{
|
{
|
||||||
let mut vote_slots = HashSet::new();
|
let mut vote_slots = HashSet::new();
|
||||||
let mut voted_stakes = HashMap::new();
|
let mut voted_stakes = HashMap::new();
|
||||||
|
@ -555,7 +555,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, ArcVoteAccount)>,
|
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
||||||
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 {
|
||||||
|
@ -825,7 +825,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, ArcVoteAccount)>,
|
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
||||||
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 {
|
||||||
|
@ -1398,7 +1398,7 @@ pub mod test {
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
use trees::tr;
|
use trees::tr;
|
||||||
|
|
||||||
fn gen_stakes(stake_votes: &[(u64, &[u64])]) -> Vec<(Pubkey, (u64, ArcVoteAccount))> {
|
fn gen_stakes(stake_votes: &[(u64, &[u64])]) -> Vec<(Pubkey, (u64, VoteAccount))> {
|
||||||
let mut stakes = vec![];
|
let mut stakes = vec![];
|
||||||
for (lamports, votes) in stake_votes {
|
for (lamports, votes) in stake_votes {
|
||||||
let mut account = AccountSharedData::from(Account {
|
let mut account = AccountSharedData::from(Account {
|
||||||
|
@ -1417,7 +1417,7 @@ pub mod test {
|
||||||
.expect("serialize state");
|
.expect("serialize state");
|
||||||
stakes.push((
|
stakes.push((
|
||||||
solana_sdk::pubkey::new_rand(),
|
solana_sdk::pubkey::new_rand(),
|
||||||
(*lamports, ArcVoteAccount::from(account)),
|
(*lamports, VoteAccount::from(account)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
stakes
|
stakes
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
use crate::{
|
use {
|
||||||
cluster_info_vote_listener::SlotVoteTracker,
|
crate::{
|
||||||
cluster_slots::SlotPubkeys,
|
cluster_info_vote_listener::SlotVoteTracker,
|
||||||
replay_stage::SUPERMINORITY_THRESHOLD,
|
cluster_slots::SlotPubkeys,
|
||||||
{consensus::Stake, consensus::VotedStakes},
|
replay_stage::SUPERMINORITY_THRESHOLD,
|
||||||
};
|
{consensus::Stake, consensus::VotedStakes},
|
||||||
use solana_ledger::blockstore_processor::{ConfirmationProgress, ConfirmationTiming};
|
},
|
||||||
use solana_runtime::{bank::Bank, bank_forks::BankForks, vote_account::ArcVoteAccount};
|
solana_ledger::blockstore_processor::{ConfirmationProgress, ConfirmationTiming},
|
||||||
use solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey};
|
solana_runtime::{bank::Bank, bank_forks::BankForks, vote_account::VoteAccount},
|
||||||
use std::{
|
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey},
|
||||||
collections::{BTreeMap, HashMap, HashSet},
|
std::{
|
||||||
sync::{Arc, RwLock},
|
collections::{BTreeMap, HashMap, HashSet},
|
||||||
|
sync::{Arc, RwLock},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
type VotedSlot = Slot;
|
type VotedSlot = Slot;
|
||||||
|
@ -326,7 +328,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, ArcVoteAccount)>,
|
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
||||||
) {
|
) {
|
||||||
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() {
|
||||||
|
@ -522,7 +524,7 @@ mod test {
|
||||||
let epoch_vote_accounts: HashMap<_, _> = vote_account_pubkeys
|
let epoch_vote_accounts: HashMap<_, _> = vote_account_pubkeys
|
||||||
.iter()
|
.iter()
|
||||||
.skip(num_vote_accounts - staked_vote_accounts)
|
.skip(num_vote_accounts - staked_vote_accounts)
|
||||||
.map(|pubkey| (*pubkey, (1, ArcVoteAccount::default())))
|
.map(|pubkey| (*pubkey, (1, VoteAccount::default())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut stats = PropagatedStats::default();
|
let mut stats = PropagatedStats::default();
|
||||||
|
@ -564,7 +566,7 @@ mod test {
|
||||||
let epoch_vote_accounts: HashMap<_, _> = vote_account_pubkeys
|
let epoch_vote_accounts: HashMap<_, _> = vote_account_pubkeys
|
||||||
.iter()
|
.iter()
|
||||||
.skip(num_vote_accounts - staked_vote_accounts)
|
.skip(num_vote_accounts - staked_vote_accounts)
|
||||||
.map(|pubkey| (*pubkey, (1, ArcVoteAccount::default())))
|
.map(|pubkey| (*pubkey, (1, VoteAccount::default())))
|
||||||
.collect();
|
.collect();
|
||||||
stats.add_node_pubkey_internal(&node_pubkey, &vote_account_pubkeys, &epoch_vote_accounts);
|
stats.add_node_pubkey_internal(&node_pubkey, &vote_account_pubkeys, &epoch_vote_accounts);
|
||||||
assert!(stats.propagated_node_ids.contains(&node_pubkey));
|
assert!(stats.propagated_node_ids.contains(&node_pubkey));
|
||||||
|
|
|
@ -26,7 +26,7 @@ use solana_runtime::{
|
||||||
commitment::VOTE_THRESHOLD_SIZE,
|
commitment::VOTE_THRESHOLD_SIZE,
|
||||||
snapshot_utils::BankFromArchiveTimings,
|
snapshot_utils::BankFromArchiveTimings,
|
||||||
transaction_batch::TransactionBatch,
|
transaction_batch::TransactionBatch,
|
||||||
vote_account::ArcVoteAccount,
|
vote_account::VoteAccount,
|
||||||
vote_sender_types::ReplayVoteSender,
|
vote_sender_types::ReplayVoteSender,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
@ -1140,7 +1140,7 @@ fn supermajority_root_from_vote_accounts<I>(
|
||||||
vote_accounts: I,
|
vote_accounts: I,
|
||||||
) -> Option<Slot>
|
) -> Option<Slot>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (Pubkey, (u64, ArcVoteAccount))>,
|
I: IntoIterator<Item = (Pubkey, (u64, VoteAccount))>,
|
||||||
{
|
{
|
||||||
let mut roots_stakes: Vec<(Slot, u64)> = vote_accounts
|
let mut roots_stakes: Vec<(Slot, u64)> = vote_accounts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -3501,7 +3501,7 @@ pub mod tests {
|
||||||
#[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)>| -> Vec<(Pubkey, (u64, ArcVoteAccount))> {
|
|roots_stakes: Vec<(Slot, u64)>| -> Vec<(Pubkey, (u64, VoteAccount))> {
|
||||||
roots_stakes
|
roots_stakes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(root, stake)| {
|
.map(|(root, stake)| {
|
||||||
|
@ -3516,7 +3516,7 @@ pub mod tests {
|
||||||
VoteState::serialize(&versioned, vote_account.data_as_mut_slice()).unwrap();
|
VoteState::serialize(&versioned, vote_account.data_as_mut_slice()).unwrap();
|
||||||
(
|
(
|
||||||
solana_sdk::pubkey::new_rand(),
|
solana_sdk::pubkey::new_rand(),
|
||||||
(stake, ArcVoteAccount::from(vote_account)),
|
(stake, VoteAccount::from(vote_account)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect_vec()
|
.collect_vec()
|
||||||
|
|
|
@ -61,31 +61,33 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use super::*;
|
use {
|
||||||
use crate::genesis_utils::{
|
super::*,
|
||||||
bootstrap_validator_stake_lamports, create_genesis_config, GenesisConfigInfo,
|
crate::genesis_utils::{
|
||||||
};
|
bootstrap_validator_stake_lamports, create_genesis_config, GenesisConfigInfo,
|
||||||
use rand::Rng;
|
|
||||||
use solana_runtime::vote_account::{ArcVoteAccount, VoteAccounts};
|
|
||||||
use solana_sdk::{
|
|
||||||
account::{from_account, AccountSharedData},
|
|
||||||
clock::Clock,
|
|
||||||
instruction::Instruction,
|
|
||||||
pubkey::Pubkey,
|
|
||||||
signature::{Keypair, Signer},
|
|
||||||
signers::Signers,
|
|
||||||
stake::{
|
|
||||||
instruction as stake_instruction,
|
|
||||||
state::{Authorized, Delegation, Lockup, Stake},
|
|
||||||
},
|
},
|
||||||
sysvar::stake_history::{self, StakeHistory},
|
rand::Rng,
|
||||||
transaction::Transaction,
|
solana_runtime::vote_account::{VoteAccount, VoteAccounts},
|
||||||
|
solana_sdk::{
|
||||||
|
account::{from_account, AccountSharedData},
|
||||||
|
clock::Clock,
|
||||||
|
instruction::Instruction,
|
||||||
|
pubkey::Pubkey,
|
||||||
|
signature::{Keypair, Signer},
|
||||||
|
signers::Signers,
|
||||||
|
stake::{
|
||||||
|
instruction as stake_instruction,
|
||||||
|
state::{Authorized, Delegation, Lockup, Stake},
|
||||||
|
},
|
||||||
|
sysvar::stake_history::{self, StakeHistory},
|
||||||
|
transaction::Transaction,
|
||||||
|
},
|
||||||
|
solana_vote_program::{
|
||||||
|
vote_instruction,
|
||||||
|
vote_state::{VoteInit, VoteState, VoteStateVersions},
|
||||||
|
},
|
||||||
|
std::sync::Arc,
|
||||||
};
|
};
|
||||||
use solana_vote_program::{
|
|
||||||
vote_instruction,
|
|
||||||
vote_state::{VoteInit, VoteState, VoteStateVersions},
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
fn new_from_parent(parent: &Arc<Bank>, slot: Slot) -> Bank {
|
fn new_from_parent(parent: &Arc<Bank>, slot: Slot) -> Bank {
|
||||||
Bank::new_from_parent(parent, &Pubkey::default(), slot)
|
Bank::new_from_parent(parent, &Pubkey::default(), slot)
|
||||||
|
@ -317,7 +319,7 @@ pub(crate) mod tests {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let vote_pubkey = Pubkey::new_unique();
|
let vote_pubkey = Pubkey::new_unique();
|
||||||
(vote_pubkey, (stake, ArcVoteAccount::from(account)))
|
(vote_pubkey, (stake, VoteAccount::from(account)))
|
||||||
});
|
});
|
||||||
let result = vote_accounts.collect::<VoteAccounts>().staked_nodes();
|
let result = vote_accounts.collect::<VoteAccounts>().staked_nodes();
|
||||||
assert_eq!(result.len(), 2);
|
assert_eq!(result.len(), 2);
|
||||||
|
|
|
@ -59,7 +59,7 @@ use crate::{
|
||||||
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::ArcVoteAccount,
|
vote_account::VoteAccount,
|
||||||
};
|
};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -538,7 +538,7 @@ pub struct TransactionBalancesSet {
|
||||||
pub post_balances: TransactionBalances,
|
pub post_balances: TransactionBalances,
|
||||||
}
|
}
|
||||||
pub struct OverwrittenVoteAccount {
|
pub struct OverwrittenVoteAccount {
|
||||||
pub account: ArcVoteAccount,
|
pub account: VoteAccount,
|
||||||
pub transaction_index: usize,
|
pub transaction_index: usize,
|
||||||
pub transaction_result_index: usize,
|
pub transaction_result_index: usize,
|
||||||
}
|
}
|
||||||
|
@ -3713,7 +3713,7 @@ impl Bank {
|
||||||
#[allow(clippy::needless_collect)]
|
#[allow(clippy::needless_collect)]
|
||||||
fn distribute_rent_to_validators<I>(&self, vote_accounts: I, rent_to_be_distributed: u64)
|
fn distribute_rent_to_validators<I>(&self, vote_accounts: I, rent_to_be_distributed: u64)
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (Pubkey, (u64, ArcVoteAccount))>,
|
I: IntoIterator<Item = (Pubkey, (u64, VoteAccount))>,
|
||||||
{
|
{
|
||||||
let mut total_staked = 0;
|
let mut total_staked = 0;
|
||||||
|
|
||||||
|
@ -5130,7 +5130,7 @@ impl Bank {
|
||||||
/// attributed to each account
|
/// attributed to each account
|
||||||
/// Note: This clones the entire vote-accounts hashmap. For a single
|
/// Note: This clones the entire vote-accounts hashmap. For a single
|
||||||
/// account lookup use get_vote_account instead.
|
/// account lookup use get_vote_account instead.
|
||||||
pub fn vote_accounts(&self) -> Vec<(Pubkey, (u64 /*stake*/, ArcVoteAccount))> {
|
pub fn vote_accounts(&self) -> Vec<(Pubkey, (/*stake:*/ u64, VoteAccount))> {
|
||||||
self.stakes
|
self.stakes
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5141,10 +5141,7 @@ impl Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Vote account for the given vote account pubkey along with the stake.
|
/// Vote account for the given vote account pubkey along with the stake.
|
||||||
pub fn get_vote_account(
|
pub fn get_vote_account(&self, vote_account: &Pubkey) -> Option<(/*stake:*/ u64, VoteAccount)> {
|
||||||
&self,
|
|
||||||
vote_account: &Pubkey,
|
|
||||||
) -> Option<(u64 /*stake*/, ArcVoteAccount)> {
|
|
||||||
self.stakes
|
self.stakes
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -5171,7 +5168,7 @@ impl Bank {
|
||||||
pub fn epoch_vote_accounts(
|
pub fn epoch_vote_accounts(
|
||||||
&self,
|
&self,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
) -> Option<&HashMap<Pubkey, (u64, ArcVoteAccount)>> {
|
) -> Option<&HashMap<Pubkey, (u64, VoteAccount)>> {
|
||||||
self.epoch_stakes
|
self.epoch_stakes
|
||||||
.get(&epoch)
|
.get(&epoch)
|
||||||
.map(|epoch_stakes| Stakes::vote_accounts(epoch_stakes.stakes()))
|
.map(|epoch_stakes| Stakes::vote_accounts(epoch_stakes.stakes()))
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use crate::{stakes::Stakes, vote_account::ArcVoteAccount};
|
use {
|
||||||
use serde::{Deserialize, Serialize};
|
crate::{stakes::Stakes, vote_account::VoteAccount},
|
||||||
use solana_sdk::{clock::Epoch, pubkey::Pubkey};
|
serde::{Deserialize, Serialize},
|
||||||
use std::{collections::HashMap, sync::Arc};
|
solana_sdk::{clock::Epoch, pubkey::Pubkey},
|
||||||
|
std::{collections::HashMap, sync::Arc},
|
||||||
|
};
|
||||||
|
|
||||||
pub type NodeIdToVoteAccounts = HashMap<Pubkey, NodeVoteAccounts>;
|
pub type NodeIdToVoteAccounts = HashMap<Pubkey, NodeVoteAccounts>;
|
||||||
pub type EpochAuthorizedVoters = HashMap<Pubkey, Pubkey>;
|
pub type EpochAuthorizedVoters = HashMap<Pubkey, Pubkey>;
|
||||||
|
@ -57,7 +59,7 @@ impl EpochStakes {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_epoch_vote_accounts(
|
fn parse_epoch_vote_accounts(
|
||||||
epoch_vote_accounts: &HashMap<Pubkey, (u64, ArcVoteAccount)>,
|
epoch_vote_accounts: &HashMap<Pubkey, (u64, VoteAccount)>,
|
||||||
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();
|
||||||
|
@ -188,7 +190,7 @@ pub(crate) mod tests {
|
||||||
vote_accounts.iter().map(|v| {
|
vote_accounts.iter().map(|v| {
|
||||||
(
|
(
|
||||||
v.vote_account,
|
v.vote_account,
|
||||||
(stake_per_account, ArcVoteAccount::from(v.account.clone())),
|
(stake_per_account, VoteAccount::from(v.account.clone())),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -306,7 +306,7 @@ mod test_bank_serialize {
|
||||||
|
|
||||||
// This some what long test harness is required to freeze the ABI of
|
// This some what long test harness is required to freeze the ABI of
|
||||||
// Bank's serialization due to versioned nature
|
// Bank's serialization due to versioned nature
|
||||||
#[frozen_abi(digest = "9i743Qsin8qndpSGqXM3ATkX6fL8dDKtqUwJ8DPjuRam")]
|
#[frozen_abi(digest = "7XCv7DU27QC6iNJ1WYkXY3X4bKu8j6CxAn6morP2u4hu")]
|
||||||
#[derive(Serialize, AbiExample)]
|
#[derive(Serialize, AbiExample)]
|
||||||
pub struct BankAbiTestWrapperFuture {
|
pub struct BankAbiTestWrapperFuture {
|
||||||
#[serde(serialize_with = "wrapper_future")]
|
#[serde(serialize_with = "wrapper_future")]
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub(crate) struct MaxAllowableDrift {
|
||||||
|
|
||||||
pub(crate) fn calculate_stake_weighted_timestamp<I, K, V, T>(
|
pub(crate) fn calculate_stake_weighted_timestamp<I, K, V, T>(
|
||||||
unique_timestamps: I,
|
unique_timestamps: I,
|
||||||
stakes: &HashMap<Pubkey, (u64, T /*Account|ArcVoteAccount*/)>,
|
stakes: &HashMap<Pubkey, (u64, T /*Account|VoteAccount*/)>,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
slot_duration: Duration,
|
slot_duration: Duration,
|
||||||
epoch_start_timestamp: Option<(Slot, UnixTimestamp)>,
|
epoch_start_timestamp: Option<(Slot, UnixTimestamp)>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Stakes serve as a cache of stake and vote accounts to derive
|
//! Stakes serve as a cache of stake and vote accounts to derive
|
||||||
//! node stakes
|
//! node stakes
|
||||||
use {
|
use {
|
||||||
crate::vote_account::{ArcVoteAccount, VoteAccounts},
|
crate::vote_account::{VoteAccount, VoteAccounts},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount},
|
account::{AccountSharedData, ReadableAccount},
|
||||||
clock::Epoch,
|
clock::Epoch,
|
||||||
|
@ -127,7 +127,7 @@ impl Stakes {
|
||||||
account: &AccountSharedData,
|
account: &AccountSharedData,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
check_vote_init: bool,
|
check_vote_init: bool,
|
||||||
) -> Option<ArcVoteAccount> {
|
) -> Option<VoteAccount> {
|
||||||
if solana_vote_program::check_id(account.owner()) {
|
if solana_vote_program::check_id(account.owner()) {
|
||||||
// unconditionally remove existing at first; there is no dependent calculated state for
|
// unconditionally remove existing at first; there is no dependent calculated state for
|
||||||
// votes, not like stakes (stake codepath maintains calculated stake value grouped by
|
// votes, not like stakes (stake codepath maintains calculated stake value grouped by
|
||||||
|
@ -151,7 +151,7 @@ impl Stakes {
|
||||||
);
|
);
|
||||||
|
|
||||||
self.vote_accounts
|
self.vote_accounts
|
||||||
.insert(*pubkey, (stake, ArcVoteAccount::from(account.clone())));
|
.insert(*pubkey, (stake, VoteAccount::from(account.clone())));
|
||||||
}
|
}
|
||||||
old.map(|(_, account)| account)
|
old.map(|(_, account)| account)
|
||||||
} else if stake::program::check_id(account.owner()) {
|
} else if stake::program::check_id(account.owner()) {
|
||||||
|
@ -211,7 +211,7 @@ impl Stakes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vote_accounts(&self) -> &HashMap<Pubkey, (u64, ArcVoteAccount)> {
|
pub fn vote_accounts(&self) -> &HashMap<Pubkey, (u64, VoteAccount)> {
|
||||||
self.vote_accounts.borrow()
|
self.vote_accounts.borrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ const INVALID_VOTE_STATE: Result<VoteState, InstructionError> =
|
||||||
Err(InstructionError::InvalidAccountData);
|
Err(InstructionError::InvalidAccountData);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, AbiExample)]
|
#[derive(Clone, Debug, Default, PartialEq, AbiExample)]
|
||||||
pub struct ArcVoteAccount(Arc<VoteAccount>);
|
pub struct VoteAccount(Arc<VoteAccountInner>);
|
||||||
|
|
||||||
#[derive(Debug, AbiExample)]
|
#[derive(Debug, AbiExample)]
|
||||||
struct VoteAccount {
|
struct VoteAccountInner {
|
||||||
account: Account,
|
account: Account,
|
||||||
vote_state: RwLock<Result<VoteState, InstructionError>>,
|
vote_state: RwLock<Result<VoteState, InstructionError>>,
|
||||||
vote_state_once: Once,
|
vote_state_once: Once,
|
||||||
|
@ -32,7 +32,7 @@ struct VoteAccount {
|
||||||
|
|
||||||
#[derive(Debug, AbiExample)]
|
#[derive(Debug, AbiExample)]
|
||||||
pub struct VoteAccounts {
|
pub struct VoteAccounts {
|
||||||
vote_accounts: HashMap<Pubkey, (u64 /*stake*/, ArcVoteAccount)>,
|
vote_accounts: HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>,
|
||||||
// Inner Arc is meant to implement copy-on-write semantics as opposed to
|
// Inner Arc is meant to implement copy-on-write semantics as opposed to
|
||||||
// sharing mutations (hence RwLock<Arc<...>> instead of Arc<RwLock<...>>).
|
// sharing mutations (hence RwLock<Arc<...>> instead of Arc<RwLock<...>>).
|
||||||
staked_nodes: RwLock<
|
staked_nodes: RwLock<
|
||||||
|
@ -46,7 +46,7 @@ pub struct VoteAccounts {
|
||||||
staked_nodes_once: Once,
|
staked_nodes_once: Once,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArcVoteAccount {
|
impl VoteAccount {
|
||||||
pub fn lamports(&self) -> u64 {
|
pub fn lamports(&self) -> u64 {
|
||||||
self.0.account.lamports
|
self.0.account.lamports
|
||||||
}
|
}
|
||||||
|
@ -84,11 +84,11 @@ impl VoteAccounts {
|
||||||
self.staked_nodes.read().unwrap().clone()
|
self.staked_nodes.read().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (&Pubkey, &(u64, ArcVoteAccount))> {
|
pub fn iter(&self) -> impl Iterator<Item = (&Pubkey, &(u64, VoteAccount))> {
|
||||||
self.vote_accounts.iter()
|
self.vote_accounts.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, pubkey: Pubkey, (stake, vote_account): (u64, ArcVoteAccount)) {
|
pub fn insert(&mut self, pubkey: Pubkey, (stake, vote_account): (u64, VoteAccount)) {
|
||||||
self.add_node_stake(stake, &vote_account);
|
self.add_node_stake(stake, &vote_account);
|
||||||
if let Some((stake, vote_account)) =
|
if let Some((stake, vote_account)) =
|
||||||
self.vote_accounts.insert(pubkey, (stake, vote_account))
|
self.vote_accounts.insert(pubkey, (stake, vote_account))
|
||||||
|
@ -97,7 +97,7 @@ impl VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, pubkey: &Pubkey) -> Option<(u64, ArcVoteAccount)> {
|
pub fn remove(&mut self, pubkey: &Pubkey) -> Option<(u64, VoteAccount)> {
|
||||||
let value = self.vote_accounts.remove(pubkey);
|
let value = self.vote_accounts.remove(pubkey);
|
||||||
if let Some((stake, ref vote_account)) = value {
|
if let Some((stake, ref vote_account)) = value {
|
||||||
self.sub_node_stake(stake, vote_account);
|
self.sub_node_stake(stake, vote_account);
|
||||||
|
@ -123,7 +123,7 @@ impl VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_node_stake(&mut self, stake: u64, vote_account: &ArcVoteAccount) {
|
fn add_node_stake(&mut self, stake: u64, vote_account: &VoteAccount) {
|
||||||
if stake != 0 && self.staked_nodes_once.is_completed() {
|
if stake != 0 && self.staked_nodes_once.is_completed() {
|
||||||
if let Some(node_pubkey) = vote_account.node_pubkey() {
|
if let Some(node_pubkey) = vote_account.node_pubkey() {
|
||||||
let mut staked_nodes = self.staked_nodes.write().unwrap();
|
let mut staked_nodes = self.staked_nodes.write().unwrap();
|
||||||
|
@ -136,7 +136,7 @@ impl VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub_node_stake(&mut self, stake: u64, vote_account: &ArcVoteAccount) {
|
fn sub_node_stake(&mut self, stake: u64, vote_account: &VoteAccount) {
|
||||||
if stake != 0 && self.staked_nodes_once.is_completed() {
|
if stake != 0 && self.staked_nodes_once.is_completed() {
|
||||||
if let Some(node_pubkey) = vote_account.node_pubkey() {
|
if let Some(node_pubkey) = vote_account.node_pubkey() {
|
||||||
let mut staked_nodes = self.staked_nodes.write().unwrap();
|
let mut staked_nodes = self.staked_nodes.write().unwrap();
|
||||||
|
@ -156,7 +156,7 @@ impl VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for ArcVoteAccount {
|
impl Serialize for VoteAccount {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
|
@ -165,7 +165,7 @@ impl Serialize for ArcVoteAccount {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for ArcVoteAccount {
|
impl<'de> Deserialize<'de> for VoteAccount {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
|
@ -175,25 +175,25 @@ impl<'de> Deserialize<'de> for ArcVoteAccount {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AccountSharedData> for ArcVoteAccount {
|
|
||||||
fn from(account: AccountSharedData) -> Self {
|
|
||||||
Self(Arc::new(VoteAccount::from(account)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Account> for ArcVoteAccount {
|
|
||||||
fn from(account: Account) -> Self {
|
|
||||||
Self(Arc::new(VoteAccount::from(account)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AccountSharedData> for VoteAccount {
|
impl From<AccountSharedData> for VoteAccount {
|
||||||
|
fn from(account: AccountSharedData) -> Self {
|
||||||
|
Self(Arc::new(VoteAccountInner::from(account)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Account> for VoteAccount {
|
||||||
|
fn from(account: Account) -> Self {
|
||||||
|
Self(Arc::new(VoteAccountInner::from(account)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AccountSharedData> for VoteAccountInner {
|
||||||
fn from(account: AccountSharedData) -> Self {
|
fn from(account: AccountSharedData) -> Self {
|
||||||
Self::from(Account::from(account))
|
Self::from(Account::from(account))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Account> for VoteAccount {
|
impl From<Account> for VoteAccountInner {
|
||||||
fn from(account: Account) -> Self {
|
fn from(account: Account) -> Self {
|
||||||
Self {
|
Self {
|
||||||
account,
|
account,
|
||||||
|
@ -203,7 +203,7 @@ impl From<Account> for VoteAccount {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for VoteAccount {
|
impl Default for VoteAccountInner {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
account: Account::default(),
|
account: Account::default(),
|
||||||
|
@ -213,7 +213,7 @@ impl Default for VoteAccount {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<VoteAccount> for VoteAccount {
|
impl PartialEq<VoteAccountInner> for VoteAccountInner {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.account == other.account
|
self.account == other.account
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ impl PartialEq<VoteAccounts> for VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type VoteAccountsHashMap = HashMap<Pubkey, (u64 /*stake*/, ArcVoteAccount)>;
|
type VoteAccountsHashMap = HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>;
|
||||||
|
|
||||||
impl From<VoteAccountsHashMap> for VoteAccounts {
|
impl From<VoteAccountsHashMap> for VoteAccounts {
|
||||||
fn from(vote_accounts: VoteAccountsHashMap) -> Self {
|
fn from(vote_accounts: VoteAccountsHashMap) -> Self {
|
||||||
|
@ -274,10 +274,10 @@ impl Borrow<VoteAccountsHashMap> for VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromIterator<(Pubkey, (u64 /*stake*/, ArcVoteAccount))> for VoteAccounts {
|
impl FromIterator<(Pubkey, (/*stake:*/ u64, VoteAccount))> for VoteAccounts {
|
||||||
fn from_iter<I>(iter: I) -> Self
|
fn from_iter<I>(iter: I) -> Self
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (Pubkey, (u64, ArcVoteAccount))>,
|
I: IntoIterator<Item = (Pubkey, (u64, VoteAccount))>,
|
||||||
{
|
{
|
||||||
Self::from(HashMap::from_iter(iter))
|
Self::from(HashMap::from_iter(iter))
|
||||||
}
|
}
|
||||||
|
@ -341,19 +341,19 @@ mod tests {
|
||||||
fn new_rand_vote_accounts<R: Rng>(
|
fn new_rand_vote_accounts<R: Rng>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
num_nodes: usize,
|
num_nodes: usize,
|
||||||
) -> impl Iterator<Item = (Pubkey, (u64 /*stake*/, ArcVoteAccount))> + '_ {
|
) -> impl Iterator<Item = (Pubkey, (/*stake:*/ u64, VoteAccount))> + '_ {
|
||||||
let nodes: Vec<_> = repeat_with(Pubkey::new_unique).take(num_nodes).collect();
|
let nodes: Vec<_> = repeat_with(Pubkey::new_unique).take(num_nodes).collect();
|
||||||
repeat_with(move || {
|
repeat_with(move || {
|
||||||
let node = nodes[rng.gen_range(0, nodes.len())];
|
let node = nodes[rng.gen_range(0, nodes.len())];
|
||||||
let (account, _) = new_rand_vote_account(rng, Some(node));
|
let (account, _) = new_rand_vote_account(rng, Some(node));
|
||||||
let stake = rng.gen_range(0, 997);
|
let stake = rng.gen_range(0, 997);
|
||||||
(Pubkey::new_unique(), (stake, ArcVoteAccount::from(account)))
|
(Pubkey::new_unique(), (stake, VoteAccount::from(account)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn staked_nodes<'a, I>(vote_accounts: I) -> HashMap<Pubkey, u64>
|
fn staked_nodes<'a, I>(vote_accounts: I) -> HashMap<Pubkey, u64>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = &'a (Pubkey, (u64, ArcVoteAccount))>,
|
I: IntoIterator<Item = &'a (Pubkey, (u64, VoteAccount))>,
|
||||||
{
|
{
|
||||||
let mut staked_nodes = HashMap::new();
|
let mut staked_nodes = HashMap::new();
|
||||||
for (_, (stake, vote_account)) in vote_accounts
|
for (_, (stake, vote_account)) in vote_accounts
|
||||||
|
@ -375,7 +375,7 @@ mod tests {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
||||||
let lamports = account.lamports;
|
let lamports = account.lamports;
|
||||||
let vote_account = ArcVoteAccount::from(account);
|
let vote_account = VoteAccount::from(account);
|
||||||
assert_eq!(lamports, vote_account.lamports());
|
assert_eq!(lamports, vote_account.lamports());
|
||||||
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
||||||
// 2nd call to .vote_state() should return the cached value.
|
// 2nd call to .vote_state() should return the cached value.
|
||||||
|
@ -386,9 +386,9 @@ mod tests {
|
||||||
fn test_vote_account_serialize() {
|
fn test_vote_account_serialize() {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
||||||
let vote_account = ArcVoteAccount::from(account.clone());
|
let vote_account = VoteAccount::from(account.clone());
|
||||||
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
||||||
// Assert than ArcVoteAccount has the same wire format as Account.
|
// Assert than VoteAccount has the same wire format as Account.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bincode::serialize(&account).unwrap(),
|
bincode::serialize(&account).unwrap(),
|
||||||
bincode::serialize(&vote_account).unwrap()
|
bincode::serialize(&vote_account).unwrap()
|
||||||
|
@ -400,9 +400,9 @@ mod tests {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
||||||
let data = bincode::serialize(&account).unwrap();
|
let data = bincode::serialize(&account).unwrap();
|
||||||
let vote_account = ArcVoteAccount::from(account);
|
let vote_account = VoteAccount::from(account);
|
||||||
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
||||||
let other_vote_account: ArcVoteAccount = bincode::deserialize(&data).unwrap();
|
let other_vote_account: VoteAccount = bincode::deserialize(&data).unwrap();
|
||||||
assert_eq!(vote_account, other_vote_account);
|
assert_eq!(vote_account, other_vote_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vote_state,
|
vote_state,
|
||||||
|
@ -414,11 +414,11 @@ mod tests {
|
||||||
fn test_vote_account_round_trip() {
|
fn test_vote_account_round_trip() {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
let (account, vote_state) = new_rand_vote_account(&mut rng, None);
|
||||||
let vote_account = ArcVoteAccount::from(account);
|
let vote_account = VoteAccount::from(account);
|
||||||
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
assert_eq!(vote_state, *vote_account.vote_state().as_ref().unwrap());
|
||||||
let data = bincode::serialize(&vote_account).unwrap();
|
let data = bincode::serialize(&vote_account).unwrap();
|
||||||
let other_vote_account: ArcVoteAccount = bincode::deserialize(&data).unwrap();
|
let other_vote_account: VoteAccount = bincode::deserialize(&data).unwrap();
|
||||||
// Assert that serialize->deserialized returns the same ArcVoteAccount.
|
// Assert that serialize->deserialized returns the same VoteAccount.
|
||||||
assert_eq!(vote_account, other_vote_account);
|
assert_eq!(vote_account, other_vote_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vote_state,
|
vote_state,
|
||||||
|
@ -429,7 +429,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, ArcVoteAccount)> =
|
let vote_accounts_hash_map: HashMap<Pubkey, (u64, VoteAccount)> =
|
||||||
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(vote_accounts_hash_map.clone());
|
let vote_accounts = VoteAccounts::from(vote_accounts_hash_map.clone());
|
||||||
assert!(vote_accounts.staked_nodes().len() > 32);
|
assert!(vote_accounts.staked_nodes().len() > 32);
|
||||||
|
@ -448,7 +448,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, ArcVoteAccount)> =
|
let vote_accounts_hash_map: HashMap<Pubkey, (u64, VoteAccount)> =
|
||||||
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…
Reference in New Issue