Skip to content

Commit 8765196

Browse files
Manav-Aggarwalalpe
andauthored
fix: Panic instead of logging error of failing header validation (#2231)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview Closes: #2182 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved error handling during block publishing to ensure immediate termination if block header validation fails, enhancing system reliability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>
1 parent 480e151 commit 8765196

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎block/manager.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,6 @@ func (m *Manager) publishBlockInternal(ctx context.Context) error {
559559
}
560560
}
561561

562-
newState, err := m.applyBlock(ctx, header, data)
563-
if err != nil {
564-
if ctx.Err() != nil {
565-
return err
566-
}
567-
// if call to applyBlock fails, we halt the node, see https://github.com/cometbft/cometbft/pull/496
568-
panic(err)
569-
}
570-
571562
signature, err = m.getSignature(header.Header)
572563
if err != nil {
573564
return err
@@ -577,8 +568,17 @@ func (m *Manager) publishBlockInternal(ctx context.Context) error {
577568
header.Signature = signature
578569

579570
if err := header.ValidateBasic(); err != nil {
580-
// TODO(tzdybal): I think this is could be even a panic, because if this happens, header is FUBAR
581-
m.logger.Error("header validation error", "error", err)
571+
// If this ever happens, for recovery, check for a mismatch between the configured signing key and the proposer address in the genesis file
572+
panic(fmt.Errorf("critical: newly produced header failed validation: %w", err))
573+
}
574+
575+
newState, err := m.applyBlock(ctx, header, data)
576+
if err != nil {
577+
if ctx.Err() != nil {
578+
return err
579+
}
580+
// if call to applyBlock fails, we halt the node, see https://github.com/cometbft/cometbft/pull/496
581+
panic(err)
582582
}
583583

584584
// append metadata to Data before validating and saving

0 commit comments

Comments
 (0)