Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 9269797

Browse files
authored
Document lockout_intervals and tiny niceties (#10925)
1 parent 658de5b commit 9269797

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

core/src/consensus.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pub(crate) struct ComputedBankState {
6666
pub voted_stakes: VotedStakes,
6767
pub total_stake: Stake,
6868
pub bank_weight: u128,
69+
// Tree of intervals of lockouts of the form [slot, slot + slot.lockout],
70+
// keyed by end of the range
6971
pub lockout_intervals: LockoutIntervals,
7072
pub pubkey_votes: Vec<(Pubkey, Slot)>,
7173
}
@@ -456,7 +458,7 @@ impl Tower {
456458
.lockout_intervals;
457459
// Find any locked out intervals in this bank with endpoint >= last_vote,
458460
// implies they are locked out at last_vote
459-
for (_, value) in lockout_intervals.range((Included(last_voted_slot), Unbounded)) {
461+
for (_lockout_ineterval_end, value) in lockout_intervals.range((Included(last_voted_slot), Unbounded)) {
460462
for (lockout_interval_start, vote_account_pubkey) in value {
461463
// Only count lockouts on slots that are:
462464
// 1) Not ancestors of `last_vote`
@@ -1196,11 +1198,15 @@ pub mod test {
11961198
// count toward the switch threshold. This means the other validator's
11971199
// vote lockout no longer counts
11981200
vote_simulator.set_root(43);
1201+
// Refresh ancestors and descendants for new root.
1202+
let ancestors = vote_simulator.bank_forks.read().unwrap().ancestors();
1203+
let descendants = vote_simulator.bank_forks.read().unwrap().descendants();
1204+
11991205
assert_eq!(
12001206
tower.check_switch_threshold(
12011207
110,
1202-
&vote_simulator.bank_forks.read().unwrap().ancestors(),
1203-
&vote_simulator.bank_forks.read().unwrap().descendants(),
1208+
&ancestors,
1209+
&descendants,
12041210
&vote_simulator.progress,
12051211
total_stake,
12061212
bank0.epoch_vote_accounts(0).unwrap(),

core/src/heaviest_subtree_fork_choice.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,10 @@ impl ForkChoice for HeaviestSubtreeForkChoice {
580580
bank_forks: &RwLock<BankForks>,
581581
) -> (Arc<Bank>, Option<Arc<Bank>>) {
582582
let last_voted_slot = tower.last_voted_slot();
583-
let heaviest_slot_on_same_voted_fork = last_voted_slot.map(|last_vote| {
583+
let heaviest_slot_on_same_voted_fork = last_voted_slot.map(|last_voted_slot| {
584584
let heaviest_slot_on_same_voted_fork =
585-
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");
586-
if heaviest_slot_on_same_voted_fork == last_vote {
585+
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");
586+
if heaviest_slot_on_same_voted_fork == last_voted_slot {
587587
None
588588
} else {
589589
Some(heaviest_slot_on_same_voted_fork)

core/src/progress_map.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use std::{
1414
sync::{Arc, RwLock},
1515
};
1616

17-
pub(crate) type LockoutIntervals = BTreeMap<Slot, Vec<(Slot, Rc<Pubkey>)>>;
17+
type VotedSlot = Slot;
18+
type ExpirationSlot = Slot;
19+
pub(crate) type LockoutIntervals = BTreeMap<ExpirationSlot, Vec<(VotedSlot, Rc<Pubkey>)>>;
1820

1921
#[derive(Default)]
2022
pub(crate) struct ReplaySlotStats(ConfirmationTiming);

0 commit comments

Comments
 (0)