This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Correctly handle the only root case #13352
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1005,7 +1005,9 @@ impl Tower { | |
|
|
||
| checked_slot = Some(*slot_in_tower); | ||
|
|
||
| retain_flags_for_each_vote_in_reverse.push(anchored_slot.is_none()); | ||
| let is_still_unanchored = anchored_slot.is_none(); | ||
| // not anchored slots must be retained | ||
| retain_flags_for_each_vote_in_reverse.push(is_still_unanchored); | ||
| } | ||
|
|
||
| // Check for errors if not anchored | ||
|
|
@@ -1027,7 +1029,13 @@ impl Tower { | |
| retain_flags_for_each_vote_in_reverse.into_iter().rev(); | ||
|
|
||
| let original_votes_len = self.lockouts.votes.len(); | ||
| self.initialize_lockouts(move |_| retain_flags_for_each_vote.next().unwrap()); | ||
| let keep_the_only_root_vote_for_no_double_vote = | ||
| self.lockouts.votes.len() == 1 && self.last_voted_slot().unwrap() == tower_root; | ||
| if !keep_the_only_root_vote_for_no_double_vote { | ||
| self.initialize_lockouts(|_| retain_flags_for_each_vote.next().unwrap()); | ||
| // we should have fully consumed the iterator. | ||
| assert!(retain_flags_for_each_vote.next().is_none()); | ||
| } | ||
|
|
||
| if self.lockouts.votes.is_empty() { | ||
| info!("All restored votes were behind; resetting root_slot and last_vote in tower!"); | ||
|
|
@@ -3136,6 +3144,21 @@ pub mod test { | |
| assert_eq!(tower.unwrap().voted_slots(), [43, 44]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_adjust_lockouts_after_replay_vote_on_only_root() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also add future tower version of this test? |
||
| let mut tower = Tower::new_for_tests(10, 0.9); | ||
| tower.lockouts.root_slot = Some(42); | ||
| tower.lockouts.votes.push_back(Lockout::new(42)); | ||
| let vote = Vote::new(vec![42], 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(), [42]); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also assert root |
||
| } | ||
|
|
||
| #[test] | ||
| fn test_adjust_lockouts_after_replay_vote_on_genesis() { | ||
| let mut tower = Tower::new_for_tests(10, 0.9); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment here why this must be accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we start to vote on root....
also, it's very very rare to see this on the wild. I've just come up with this possibility while working on #12671.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also augment the check here https://github.com/solana-labs/solana/blob/master/core/src/consensus.rs#L454 to check that the vote slot > root so the
is_locked_outcheck will fail