implements copy-on-write for vote-accounts (#19362)
Bank::vote_accounts redundantly clones vote-accounts HashMap even though an immutable reference will suffice: https://github.com/solana-labs/solana/blob/95c998a19/runtime/src/bank.rs#L5174-L5186 This commit implements copy-on-write semantics for vote-accounts by wrapping the underlying HashMap in Arc<...>.
This commit is contained in:
@@ -24,9 +24,9 @@ pub struct EpochStakes {
|
||||
|
||||
impl EpochStakes {
|
||||
pub fn new(stakes: &Stakes, leader_schedule_epoch: Epoch) -> Self {
|
||||
let epoch_vote_accounts = Stakes::vote_accounts(stakes);
|
||||
let epoch_vote_accounts = stakes.vote_accounts();
|
||||
let (total_stake, node_id_to_vote_accounts, epoch_authorized_voters) =
|
||||
Self::parse_epoch_vote_accounts(epoch_vote_accounts, leader_schedule_epoch);
|
||||
Self::parse_epoch_vote_accounts(epoch_vote_accounts.as_ref(), leader_schedule_epoch);
|
||||
Self {
|
||||
stakes: Arc::new(stakes.clone()),
|
||||
total_stake,
|
||||
@@ -52,7 +52,8 @@ impl EpochStakes {
|
||||
}
|
||||
|
||||
pub fn vote_account_stake(&self, vote_account: &Pubkey) -> u64 {
|
||||
Stakes::vote_accounts(&self.stakes)
|
||||
self.stakes
|
||||
.vote_accounts()
|
||||
.get(vote_account)
|
||||
.map(|(stake, _)| *stake)
|
||||
.unwrap_or(0)
|
||||
|
||||
Reference in New Issue
Block a user