Skip to content

Commit 96d22fa

Browse files
committed
Guard rebranch_to against empty target_chain
`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`.
1 parent 01cc6db commit 96d22fa

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

blockchain/src/blockchain/rebranch_utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ impl Blockchain {
9292
(Vec<(Blake2bHash, ChainInfo)>, Vec<BlockLog>),
9393
Vec<(Blake2bHash, ChainInfo, Option<TrieDiff>)>,
9494
> {
95+
// Rebranching to an empty target chain is not meaningful: there is nothing
96+
// to apply and the ancestor would become the new head, which the callers
97+
// do not handle. Reject so the proposal/push is treated as an invalid fork.
98+
if target_chain.is_empty() {
99+
return Err(vec![]);
100+
}
101+
95102
// Keeps track of the currently investigated block
96103
let mut current = (self.state.head_hash.clone(), self.state.main_chain.clone());
97104
// Collects the reverted blocks

0 commit comments

Comments
 (0)