implements copy-on-write for staked-nodes (#19090)

Bank::staked_nodes and Bank::epoch_staked_nodes redundantly clone
staked-nodes HashMap even though an immutable reference will suffice:
https://github.com/solana-labs/solana/blob/a9014cece/runtime/src/vote_account.rs#L77

This commit implements copy-on-write semantics for staked-nodes by
wrapping the underlying HashMap in Arc<...>.
This commit is contained in:
behzad nouri
2021-08-10 12:59:12 +00:00
committed by GitHub
parent c18bd08021
commit f302774cf7
5 changed files with 105 additions and 56 deletions

View File

@ -1690,7 +1690,7 @@ impl ClusterInfo {
Some(root_bank.feature_set.clone()),
)
}
None => (HashMap::new(), None),
None => (Arc::default(), None),
};
let require_stake_for_gossip =
self.require_stake_for_gossip(feature_set.as_deref(), &stakes);
@ -2485,7 +2485,7 @@ impl ClusterInfo {
// feature does not roll back (if the feature happens to get enabled in
// a minority fork).
let (feature_set, stakes) = match bank_forks {
None => (None, HashMap::default()),
None => (None, Arc::default()),
Some(bank_forks) => {
let bank = bank_forks.read().unwrap().root_bank();
let feature_set = bank.feature_set.clone();