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

Commit addc85f

Browse files
committed
Allow resetting to duplicate was confirmed
1 parent 094a420 commit addc85f

1 file changed

Lines changed: 28 additions & 32 deletions

File tree

core/src/heaviest_subtree_fork_choice.rs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -858,37 +858,32 @@ impl HeaviestSubtreeForkChoice {
858858
tower
859859
.last_voted_slot_hash()
860860
.and_then(|last_voted_slot_hash| {
861-
let heaviest_slot_hash_on_same_voted_fork = self.best_slot(&last_voted_slot_hash);
862-
if heaviest_slot_hash_on_same_voted_fork.is_none() {
863-
if !tower.is_stray_last_vote() {
864-
// Unless last vote is stray and stale, self.bast_slot(last_voted_slot) must return
865-
// Some(_), justifying to panic! here.
866-
// Also, adjust_lockouts_after_replay() correctly makes last_voted_slot None,
867-
// if all saved votes are ancestors of replayed_root_slot. So this code shouldn't be
868-
// touched in that case as well.
869-
// In other words, except being stray, all other slots have been voted on while this
870-
// validator has been running, so we must be able to fetch best_slots for all of
871-
// them.
872-
panic!(
873-
"a bank at last_voted_slot({:?}) is a frozen bank so must have been \
874-
added to heaviest_subtree_fork_choice at time of freezing",
875-
last_voted_slot_hash,
876-
)
877-
} else {
878-
// fork_infos doesn't have corresponding data for the stale stray last vote,
879-
// meaning some inconsistency between saved tower and ledger.
880-
// (newer snapshot, or only a saved tower is moved over to new setup?)
881-
return None;
861+
match self.is_candidate(&last_voted_slot_hash) {
862+
Some(true) => self.best_slot(&last_voted_slot_hash),
863+
Some(false) => None,
864+
None => {
865+
if !tower.is_stray_last_vote() {
866+
// Unless last vote is stray and stale, self.bast_slot(last_voted_slot) must return
867+
// Some(_), justifying to panic! here.
868+
// Also, adjust_lockouts_after_replay() correctly makes last_voted_slot None,
869+
// if all saved votes are ancestors of replayed_root_slot. So this code shouldn't be
870+
// touched in that case as well.
871+
// In other words, except being stray, all other slots have been voted on while this
872+
// validator has been running, so we must be able to fetch best_slots for all of
873+
// them.
874+
panic!(
875+
"a bank at last_voted_slot({:?}) is a frozen bank so must have been \
876+
added to heaviest_subtree_fork_choice at time of freezing",
877+
last_voted_slot_hash,
878+
)
879+
} else {
880+
// fork_infos doesn't have corresponding data for the stale stray last vote,
881+
// meaning some inconsistency between saved tower and ledger.
882+
// (newer snapshot, or only a saved tower is moved over to new setup?)
883+
None
884+
}
882885
}
883886
}
884-
let heaviest_slot_hash_on_same_voted_fork =
885-
heaviest_slot_hash_on_same_voted_fork.unwrap();
886-
887-
if heaviest_slot_hash_on_same_voted_fork == last_voted_slot_hash {
888-
None
889-
} else {
890-
Some(heaviest_slot_hash_on_same_voted_fork)
891-
}
892887
})
893888
}
894889

@@ -2957,9 +2952,10 @@ mod test {
29572952

29582953
// After marking the last vote in the tower as invalid, `heaviest_slot_on_same_voted_fork()`
29592954
// should disregard all descendants of that invalid vote
2960-
assert!(heaviest_subtree_fork_choice
2961-
.heaviest_slot_on_same_voted_fork(&tower)
2962-
.is_none());
2955+
assert_eq!(
2956+
heaviest_subtree_fork_choice.heaviest_slot_on_same_voted_fork(&tower),
2957+
None
2958+
);
29632959

29642960
// Adding another descendant to the invalid candidate won't
29652961
// update the best slot, even if it contains votes

0 commit comments

Comments
 (0)