Use `.find()` instead of loop+filter+break for sending snapshot request (#27674)

This commit is contained in:
Brooks Prumo 2022-09-10 19:11:37 -04:00 committed by GitHub
parent bd6177d5f2
commit d36c5774a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 38 deletions

View File

@ -258,11 +258,11 @@ impl BankForks {
let mut total_squash_accounts_store_ms = 0;
let mut total_squash_cache_ms = 0;
let mut total_snapshot_ms = 0;
for bank in banks.iter() {
if let Some(bank) = banks.iter().find(|bank| {
bank.slot() > self.last_accounts_hash_slot
&& bank.block_height() % self.accounts_hash_interval_slots == 0
}) {
let bank_slot = bank.slot();
if bank.block_height() % self.accounts_hash_interval_slots == 0
&& bank_slot > self.last_accounts_hash_slot
{
self.last_accounts_hash_slot = bank_slot;
let squash_timing = bank.squash();
total_squash_accounts_ms += squash_timing.squash_accounts_ms as i64;
@ -281,13 +281,13 @@ impl BankForks {
// `set_root()` is called before the snapshots package can be generated
let status_cache_slot_deltas =
bank.status_cache.read().unwrap().root_slot_deltas();
if let Err(e) = accounts_background_request_sender.send_snapshot_request(
SnapshotRequest {
if let Err(e) =
accounts_background_request_sender.send_snapshot_request(SnapshotRequest {
snapshot_root_bank: Arc::clone(bank),
status_cache_slot_deltas,
request_type: SnapshotRequestType::Snapshot,
},
) {
})
{
warn!(
"Error sending snapshot request for bank: {}, err: {:?}",
bank_slot, e
@ -299,8 +299,6 @@ impl BankForks {
}
snapshot_time.stop();
total_snapshot_ms += snapshot_time.as_ms() as i64;
break;
}
}
if !is_root_bank_squashed {
let squash_timing = root_bank.squash();