From 65c7292ea623621083ae0aa3debf2caf201fb50a Mon Sep 17 00:00:00 2001 From: Steven Czabaniuk Date: Wed, 30 Aug 2023 13:13:20 +0200 Subject: [PATCH] Cleanup BankForks access code in ShredFetchStage - BankForks is not an optional argument, so remove dated comment - Given that BankForks is always present, no need for special values to initialize variables before the loop - Root slot can be retrieved from root bank, no need for second call to BankForks (which would load the underlying atomic a second time) - Use BankForks::highest_slot() instead of .slot() on .working_bank() to avoid the extra clone that .working_bank() performs - Move several operations outside of BankForks read lock scope to minimize lock time --- core/src/shred_fetch_stage.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/shred_fetch_stage.rs b/core/src/shred_fetch_stage.rs index 3a5e5ee5dcfd4b..8923814b09ee5b 100644 --- a/core/src/shred_fetch_stage.rs +++ b/core/src/shred_fetch_stage.rs @@ -52,12 +52,14 @@ impl ShredFetchStage { .as_ref() .map(|(_, cluster_info)| cluster_info.keypair().clone()); - // In the case of bank_forks=None, setup to accept any slot range - let mut root_bank = bank_forks.read().unwrap().root_bank(); - let mut last_root = 0; - let mut last_slot = std::u64::MAX; - let mut slots_per_epoch = 0; - + // Only need root bank in order to check feature statuses later on; + // can demote to only fetching root slot once those features go away. + let (mut root_bank, mut last_slot) = { + let bank_forks_r = bank_forks.read().unwrap(); + (bank_forks_r.root_bank(), bank_forks_r.highest_slot()) + }; + let mut last_root = root_bank.slot(); + let mut slots_per_epoch = root_bank.get_slots_in_epoch(root_bank.epoch()); let mut stats = ShredFetchStats::default(); for mut packet_batch in recvr { @@ -65,12 +67,11 @@ impl ShredFetchStage { last_updated = Instant::now(); { let bank_forks_r = bank_forks.read().unwrap(); - last_root = bank_forks_r.root(); - let working_bank = bank_forks_r.working_bank(); - last_slot = working_bank.slot(); root_bank = bank_forks_r.root_bank(); - slots_per_epoch = root_bank.get_slots_in_epoch(root_bank.epoch()); + last_slot = bank_forks_r.highest_slot(); } + last_root = root_bank.slot(); + slots_per_epoch = root_bank.get_slots_in_epoch(root_bank.epoch()); keypair = repair_context .as_ref() .map(|(_, cluster_info)| cluster_info.keypair().clone());