implements copy-on-write for vote-accounts (backport #19362) #22139 (#22139)

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<...>.

Co-authored-by: behzad nouri <behzadnouri@gmail.com>
This commit is contained in:
mergify[bot]
2021-12-28 21:18:37 +00:00
committed by GitHub
parent 262b157d21
commit a305fa0472
12 changed files with 210 additions and 156 deletions

View File

@@ -334,18 +334,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);
}
}
}
@@ -375,7 +375,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() {