From 70a206cd3b1133de4ceab8e7063a194eca822171 Mon Sep 17 00:00:00 2001 From: Ashwin Sekar Date: Wed, 24 Jan 2024 21:08:30 +0000 Subject: [PATCH] pr feedback: move local variable into helper function --- gossip/src/duplicate_shred_handler.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/gossip/src/duplicate_shred_handler.rs b/gossip/src/duplicate_shred_handler.rs index 279bcb3552fe4d..8bcbee53cae875 100644 --- a/gossip/src/duplicate_shred_handler.rs +++ b/gossip/src/duplicate_shred_handler.rs @@ -137,19 +137,7 @@ impl DuplicateShredHandler { shred1.into_payload(), shred2.into_payload(), )?; - let should_notify = { - let root_bank = self.bank_forks.read().unwrap().root_bank(); - let activated_slot = root_bank - .feature_set - .activated_slot(&feature_set::enable_gossip_duplicate_proof_ingestion::id()) - .map(|slot| root_bank.epoch_schedule().get_epoch(slot)); - activated_slot.is_some_and(|feature_epoch| { - root_bank.epoch_schedule().get_epoch(slot) > feature_epoch - // feature_epoch could only be 0 in tests and new cluster setup. - || feature_epoch == 0 - }) - }; - if should_notify { + if self.should_notify_state_machine(slot) { // Notify duplicate consensus state machine self.duplicate_slots_sender .send(slot) @@ -161,6 +149,19 @@ impl DuplicateShredHandler { Ok(()) } + fn should_notify_state_machine(&self, slot: Slot) -> bool { + let root_bank = self.bank_forks.read().unwrap().root_bank(); + let activated_slot = root_bank + .feature_set + .activated_slot(&feature_set::enable_gossip_duplicate_proof_ingestion::id()) + .map(|slot| root_bank.epoch_schedule().get_epoch(slot)); + activated_slot.is_some_and(|feature_epoch| { + root_bank.epoch_schedule().get_epoch(slot) > feature_epoch + // feature_epoch could only be 0 in tests and new cluster setup. + || feature_epoch == 0 + }) + } + fn should_consume_slot(&mut self, slot: Slot) -> bool { slot > self.last_root && slot < self.last_root.saturating_add(self.cached_slots_in_epoch)