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:
@ -353,18 +353,18 @@ fn graph_forks(bank_forks: &BankForks, include_all_votes: bool) -> String {
|
||||
.iter()
|
||||
.map(|(_, (stake, _))| stake)
|
||||
.sum();
|
||||
for (_, (stake, vote_account)) in bank.vote_accounts() {
|
||||
for (stake, vote_account) in bank.vote_accounts().values() {
|
||||
let vote_state = vote_account.vote_state();
|
||||
let vote_state = vote_state.as_ref().unwrap_or(&default_vote_state);
|
||||
if let Some(last_vote) = vote_state.votes.iter().last() {
|
||||
let entry = last_votes.entry(vote_state.node_pubkey).or_insert((
|
||||
last_vote.slot,
|
||||
vote_state.clone(),
|
||||
stake,
|
||||
*stake,
|
||||
total_stake,
|
||||
));
|
||||
if entry.0 < last_vote.slot {
|
||||
*entry = (last_vote.slot, vote_state.clone(), stake, total_stake);
|
||||
*entry = (last_vote.slot, vote_state.clone(), *stake, total_stake);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -394,7 +394,7 @@ fn graph_forks(bank_forks: &BankForks, include_all_votes: bool) -> String {
|
||||
|
||||
let mut first = true;
|
||||
loop {
|
||||
for (_, (_, vote_account)) in bank.vote_accounts() {
|
||||
for (_, vote_account) in bank.vote_accounts().values() {
|
||||
let vote_state = vote_account.vote_state();
|
||||
let vote_state = vote_state.as_ref().unwrap_or(&default_vote_state);
|
||||
if let Some(last_vote) = vote_state.votes.iter().last() {
|
||||
|
Reference in New Issue
Block a user