Guard rebranch_to against empty target_chain#3703
Merged
Conversation
74465e4 to
db675f3
Compare
viquezclaudio
approved these changes
Apr 22, 2026
`verify_inferior_chain_macro_block_proposal` calls `fork_chain.remove(0)` to strip the proposed block before invoking `rebranch_to`. If the proposal's parent is the common ancestor, `fork_chain` becomes empty, and `rebranch_to` would panic on `target_chain.last().unwrap()` when updating `main_chain_successor`. This state is not reachable under normal protocol invariants (the non-inferior path would be taken, or `verify_macro_successor` would reject the proposal), but guard defensively so a broken invariant elsewhere cannot turn into a validator-wide crash. Returning `Err(vec![])` funnels into the existing error handling in both callers, which abort the write transaction and surface `PushError::InvalidFork`.
db675f3 to
96d22fa
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
verify_inferior_chain_macro_block_proposalcallsfork_chain.remove(0)to strip the proposed block before invokingrebranch_to. If the proposal's parent is the common ancestor,fork_chainbecomes empty, andrebranch_towould panic ontarget_chain.last().unwrap()when updatingmain_chain_successor.This state is not reachable under normal protocol invariants (the non-inferior path would be taken, or
verify_macro_successorwould reject the proposal), but guard defensively so a broken invariant elsewhere cannot turn into a validator-wide crash. ReturningErr(vec![])funnels into the existing error handling in both callers, which abort the write transaction and surfacePushError::InvalidFork.Pull request checklist
clippyandrustfmtwarnings.