Skip to content

Guard rebranch_to against empty target_chain#3703

Merged
jsdanielh merged 1 commit intoalbatrossfrom
jsdanielh/rebranch
Apr 22, 2026
Merged

Guard rebranch_to against empty target_chain#3703
jsdanielh merged 1 commit intoalbatrossfrom
jsdanielh/rebranch

Conversation

@jsdanielh
Copy link
Copy Markdown
Member

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.

Pull request checklist

  • All tests pass. The project builds and runs.
  • I have resolved any merge conflicts.
  • I have resolved all clippy and rustfmt warnings.

@jsdanielh jsdanielh force-pushed the jsdanielh/rebranch branch 2 times, most recently from 74465e4 to db675f3 Compare April 21, 2026 19:25
`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`.
@jsdanielh jsdanielh force-pushed the jsdanielh/rebranch branch from db675f3 to 96d22fa Compare April 22, 2026 00:40
@jsdanielh jsdanielh merged commit 96d22fa into albatross Apr 22, 2026
7 checks passed
@jsdanielh jsdanielh deleted the jsdanielh/rebranch branch April 22, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants