diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 065eb2502c..3571e42c8a 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -66,6 +66,8 @@ pub(crate) struct ComputedBankState { pub voted_stakes: VotedStakes, pub total_stake: Stake, pub bank_weight: u128, + // Tree of intervals of lockouts of the form [slot, slot + slot.lockout], + // keyed by end of the range pub lockout_intervals: LockoutIntervals, pub pubkey_votes: Vec<(Pubkey, Slot)>, } @@ -456,7 +458,7 @@ impl Tower { .lockout_intervals; // Find any locked out intervals in this bank with endpoint >= last_vote, // implies they are locked out at last_vote - for (_, value) in lockout_intervals.range((Included(last_voted_slot), Unbounded)) { + for (_lockout_ineterval_end, value) in lockout_intervals.range((Included(last_voted_slot), Unbounded)) { for (lockout_interval_start, vote_account_pubkey) in value { // Only count lockouts on slots that are: // 1) Not ancestors of `last_vote` @@ -1196,11 +1198,15 @@ pub mod test { // count toward the switch threshold. This means the other validator's // vote lockout no longer counts vote_simulator.set_root(43); + // Refresh ancestors and descendants for new root. + let ancestors = vote_simulator.bank_forks.read().unwrap().ancestors(); + let descendants = vote_simulator.bank_forks.read().unwrap().descendants(); + assert_eq!( tower.check_switch_threshold( 110, - &vote_simulator.bank_forks.read().unwrap().ancestors(), - &vote_simulator.bank_forks.read().unwrap().descendants(), + &ancestors, + &descendants, &vote_simulator.progress, total_stake, bank0.epoch_vote_accounts(0).unwrap(), diff --git a/core/src/heaviest_subtree_fork_choice.rs b/core/src/heaviest_subtree_fork_choice.rs index c0092d5cc4..d4c2f237c7 100644 --- a/core/src/heaviest_subtree_fork_choice.rs +++ b/core/src/heaviest_subtree_fork_choice.rs @@ -580,10 +580,10 @@ impl ForkChoice for HeaviestSubtreeForkChoice { bank_forks: &RwLock, ) -> (Arc, Option>) { let last_voted_slot = tower.last_voted_slot(); - let heaviest_slot_on_same_voted_fork = last_voted_slot.map(|last_vote| { + let heaviest_slot_on_same_voted_fork = last_voted_slot.map(|last_voted_slot| { let heaviest_slot_on_same_voted_fork = - self.best_slot(last_vote).expect("last_vote is a frozen bank so must have been added to heaviest_subtree_fork_choice at time of freezing"); - if heaviest_slot_on_same_voted_fork == last_vote { + self.best_slot(last_voted_slot).expect("a bank at last_voted_slot is a frozen bank so must have been added to heaviest_subtree_fork_choice at time of freezing"); + if heaviest_slot_on_same_voted_fork == last_voted_slot { None } else { Some(heaviest_slot_on_same_voted_fork) diff --git a/core/src/progress_map.rs b/core/src/progress_map.rs index 15fa5d6102..47eba07e36 100644 --- a/core/src/progress_map.rs +++ b/core/src/progress_map.rs @@ -14,7 +14,9 @@ use std::{ sync::{Arc, RwLock}, }; -pub(crate) type LockoutIntervals = BTreeMap)>>; +type VotedSlot = Slot; +type ExpirationSlot = Slot; +pub(crate) type LockoutIntervals = BTreeMap)>>; #[derive(Default)] pub(crate) struct ReplaySlotStats(ConfirmationTiming);