Skip to content

Commit

Permalink
pr feedback: move local variable into helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar committed Jan 25, 2024
1 parent d7b5cb1 commit 70a206c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions gossip/src/duplicate_shred_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 70a206c

Please sign in to comment.