diff --git a/core/src/consensus.rs b/core/src/consensus.rs index d5e738f746..83bb2fe504 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -253,6 +253,16 @@ impl Tower { sum } + // a slot is not recent if its older than the oldest lockout we have + pub fn is_recent(&self, slot: u64) -> bool { + if let Some(oldest_vote) = self.lockouts.votes.front() { + if slot < oldest_vote.slot { + return false; + } + } + true + } + pub fn has_voted(&self, slot: u64) -> bool { for vote in &self.lockouts.votes { if vote.slot == slot { @@ -590,6 +600,19 @@ mod test { assert!(!tower.has_voted(1)); } + #[test] + fn test_check_recent_slot() { + let mut tower = Tower::new_for_tests(0, 0.67); + assert!(tower.is_recent(0)); + assert!(tower.is_recent(32)); + for i in 0..64 { + tower.record_vote(i, Hash::default()); + } + assert!(!tower.is_recent(0)); + assert!(!tower.is_recent(32)); + assert!(tower.is_recent(65)); + } + #[test] fn test_is_locked_out_double_vote() { let mut tower = Tower::new_for_tests(0, 0.67); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 97bc20a170..0cc50bd564 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -574,6 +574,11 @@ impl ReplayStage { trace!("bank is votable: {} {}", b.slot(), is_votable); is_votable }) + .filter(|b| { + let is_recent = tower.is_recent(b.slot()); + trace!("tower is recent: {} {}", b.slot(), is_recent); + is_recent + }) .filter(|b| { let has_voted = tower.has_voted(b.slot()); trace!("bank has_voted: {} {}", b.slot(), has_voted);