-
Notifications
You must be signed in to change notification settings - Fork 234
fix: Validate block headers against state #2763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest Buf updates on your PR. Results from workflow CI and Release / buf-check (pull_request).
|
|
Claude finished @alpe's task —— View job Comprehensive Code Review ✓I've completed a thorough review of the PR "fix: Validate block headers against state". Here are my findings organized by focus area: SummaryThis PR adds state-based validation of block headers by introducing a Critical Issues1. Inconsistent Error Handling in
|
block/internal/syncing/syncer.go
Outdated
| return nil | ||
| } | ||
| // Validate header against state | ||
| if header.Height() != state.LastBlockHeight+1 { |
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.
good sanity check, but this is validated prior to calling trySyncNextBlock
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.
I have moved this into the AssertValidForNextState method. In context of the State object, it makes more sense and is used by Executor as well.
d3aa64e to
74cc608
Compare
| case errors.Is(err, errInvalidBlock): | ||
| // do not reschedule | ||
| case errors.Is(err, errInvalidState): | ||
| s.logger.Fatal().Uint64("block_height", event.Header.Height()). |
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.
Fatal send an os.Exit(1), which will shortcut all cleanup logic we have
| // errInvalidBlock is returned when a block is failing validation | ||
| errInvalidBlock = errors.New("invalid block") | ||
| // errInvalidState is returned when the state has diverged from the DA blocks | ||
| errInvalidState = errors.New("invalid state") |
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.
This error isn't used anymore
| switch { | ||
| case errors.Is(err, errInvalidBlock): | ||
| // do not reschedule | ||
| case errors.Is(err, errInvalidState): |
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.
Ditto
| if err := s.validateBlock(currentState, data, header); err != nil { | ||
| // remove header as da included (not per se needed, but keep cache clean) | ||
| s.cache.RemoveHeaderDAIncluded(header.Hash().String()) | ||
| return errors.Join(errInvalidBlock, fmt.Errorf("failed to validate block: %w", err)) |
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 just keep this
No description provided.