From 84f74807d45170edea90a7ba39d4c46f087b5f5a Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Mon, 23 Sep 2019 19:40:03 -0700 Subject: [PATCH] Skip considering banks older than the latest vote slot (#6037) automerge --- core/src/consensus.rs | 14 ++++++++++---- core/src/replay_stage.rs | 5 ----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 83bb2fe504..786efde574 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -253,10 +253,10 @@ 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 { + // a slot is not recent if it's older than the newest vote we have + fn is_recent(&self, slot: u64) -> bool { + if let Some(last_vote) = self.lockouts.votes.back() { + if slot <= last_vote.slot { return false; } } @@ -275,6 +275,11 @@ impl Tower { pub fn is_locked_out(&self, slot: u64, ancestors: &HashMap>) -> bool { assert!(ancestors.contains_key(&slot)); + if !self.is_recent(slot) { + trace!("slot is not recent: {}", slot); + return true; + } + let mut lockouts = self.lockouts.clone(); lockouts.process_slot_vote_unchecked(slot); for vote in &lockouts.votes { @@ -610,6 +615,7 @@ mod test { } assert!(!tower.is_recent(0)); assert!(!tower.is_recent(32)); + assert!(!tower.is_recent(63)); assert!(tower.is_recent(65)); } diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 0cc50bd564..97bc20a170 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -574,11 +574,6 @@ 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);