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:
@ -12,7 +12,10 @@ pub fn leader_schedule(epoch: Epoch, bank: &Bank) -> Option<LeaderSchedule> {
|
||||
bank.epoch_staked_nodes(epoch).map(|stakes| {
|
||||
let mut seed = [0u8; 32];
|
||||
seed[0..8].copy_from_slice(&epoch.to_le_bytes());
|
||||
let mut stakes: Vec<_> = stakes.into_iter().collect();
|
||||
let mut stakes: Vec<_> = stakes
|
||||
.iter()
|
||||
.map(|(pubkey, stake)| (*pubkey, *stake))
|
||||
.collect();
|
||||
sort_stakes(&mut stakes);
|
||||
LeaderSchedule::new(
|
||||
&stakes,
|
||||
@ -88,7 +91,11 @@ mod tests {
|
||||
.genesis_config;
|
||||
let bank = Bank::new_for_tests(&genesis_config);
|
||||
|
||||
let pubkeys_and_stakes: Vec<_> = bank.staked_nodes().into_iter().collect();
|
||||
let pubkeys_and_stakes: Vec<_> = bank
|
||||
.staked_nodes()
|
||||
.iter()
|
||||
.map(|(pubkey, stake)| (*pubkey, *stake))
|
||||
.collect();
|
||||
let seed = [0u8; 32];
|
||||
let leader_schedule = LeaderSchedule::new(
|
||||
&pubkeys_and_stakes,
|
||||
|
Reference in New Issue
Block a user