Document lockout_intervals and tiny niceties (#10925)

This commit is contained in:
Ryo Onodera
2020-07-06 17:59:17 +09:00
committed by GitHub
parent 658de5b347
commit 92697973d0
3 changed files with 15 additions and 7 deletions

View File

@ -66,6 +66,8 @@ pub(crate) struct ComputedBankState {
pub voted_stakes: VotedStakes, pub voted_stakes: VotedStakes,
pub total_stake: Stake, pub total_stake: Stake,
pub bank_weight: u128, 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 lockout_intervals: LockoutIntervals,
pub pubkey_votes: Vec<(Pubkey, Slot)>, pub pubkey_votes: Vec<(Pubkey, Slot)>,
} }
@ -456,7 +458,7 @@ impl Tower {
.lockout_intervals; .lockout_intervals;
// Find any locked out intervals in this bank with endpoint >= last_vote, // Find any locked out intervals in this bank with endpoint >= last_vote,
// implies they are locked out at 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 { for (lockout_interval_start, vote_account_pubkey) in value {
// Only count lockouts on slots that are: // Only count lockouts on slots that are:
// 1) Not ancestors of `last_vote` // 1) Not ancestors of `last_vote`
@ -1196,11 +1198,15 @@ pub mod test {
// count toward the switch threshold. This means the other validator's // count toward the switch threshold. This means the other validator's
// vote lockout no longer counts // vote lockout no longer counts
vote_simulator.set_root(43); 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!( assert_eq!(
tower.check_switch_threshold( tower.check_switch_threshold(
110, 110,
&vote_simulator.bank_forks.read().unwrap().ancestors(), &ancestors,
&vote_simulator.bank_forks.read().unwrap().descendants(), &descendants,
&vote_simulator.progress, &vote_simulator.progress,
total_stake, total_stake,
bank0.epoch_vote_accounts(0).unwrap(), bank0.epoch_vote_accounts(0).unwrap(),

View File

@ -580,10 +580,10 @@ impl ForkChoice for HeaviestSubtreeForkChoice {
bank_forks: &RwLock<BankForks>, bank_forks: &RwLock<BankForks>,
) -> (Arc<Bank>, Option<Arc<Bank>>) { ) -> (Arc<Bank>, Option<Arc<Bank>>) {
let last_voted_slot = tower.last_voted_slot(); 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 = 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"); 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_vote { if heaviest_slot_on_same_voted_fork == last_voted_slot {
None None
} else { } else {
Some(heaviest_slot_on_same_voted_fork) Some(heaviest_slot_on_same_voted_fork)

View File

@ -14,7 +14,9 @@ use std::{
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
pub(crate) type LockoutIntervals = BTreeMap<Slot, Vec<(Slot, Rc<Pubkey>)>>; type VotedSlot = Slot;
type ExpirationSlot = Slot;
pub(crate) type LockoutIntervals = BTreeMap<ExpirationSlot, Vec<(VotedSlot, Rc<Pubkey>)>>;
#[derive(Default)] #[derive(Default)]
pub(crate) struct ReplaySlotStats(ConfirmationTiming); pub(crate) struct ReplaySlotStats(ConfirmationTiming);