Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,12 @@ impl Tower {
}

if let Some(checked_slot) = checked_slot {
// This is really special, only if tower is initialized (root = slot 0) for genesis and contains
// a vote (= slot 0) for the genesis, the slot 0 can repeat only once
let voting_from_genesis = *slot_in_tower == checked_slot && *slot_in_tower == 0;
// This is really special, only if tower is initialized and contains
// a vote for the root, the root slot can repeat only once
let voting_for_root =
*slot_in_tower == checked_slot && *slot_in_tower == tower_root;

if !voting_from_genesis {
Comment on lines -924 to -928
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering this false panic, it's so tempting to just give up this asserting entirely and call self.initialize_lockouts(|v| v.slot > tower_root); and get done by forcibly erasing any odd state. But, I rather want to keep this assertion by tweaking like this.

This is to catch a really ill-state of badly ordered vote account / tower if it ever happens in the future.

if !voting_for_root {
// Unless we're voting since genesis, slots_in_tower must always be older than last checked_slot
// including all vote slot and the root slot.
assert!(
Expand Down Expand Up @@ -3038,6 +3039,23 @@ pub mod test {
.unwrap();
}

#[test]
fn test_adjust_lockouts_after_replay_vote_on_root() {
let mut tower = Tower::new_for_tests(10, 0.9);
tower.lockouts.root_slot = Some(42);
tower.lockouts.votes.push_back(Lockout::new(42));
tower.lockouts.votes.push_back(Lockout::new(43));
tower.lockouts.votes.push_back(Lockout::new(44));
let vote = Vote::new(vec![44], Hash::default());
tower.last_vote = vote;

let mut slot_history = SlotHistory::default();
slot_history.add(42);

let tower = tower.adjust_lockouts_after_replay(42, &slot_history);
assert_eq!(tower.unwrap().voted_slots(), [43, 44]);
}

#[test]
fn test_adjust_lockouts_after_replay_vote_on_genesis() {
let mut tower = Tower::new_for_tests(10, 0.9);
Expand Down