feat(cli): make stopping on invalid block the default for reth import#21403
Merged
feat(cli): make stopping on invalid block the default for reth import#21403
Conversation
When importing blocks, the import now stops at the last valid block by default if an invalid block is encountered during execution or validation. The database is left at the last valid block state. This is the expected behavior for Hive consensus tests that import chains with intentionally invalid blocks. From the Hive consensus test documentation: > The client should start even if the blocks are invalid, i.e. after the import, > the client's 'best block' should be the last valid, imported block. A new `--fail-on-invalid-block` flag is provided to restore the original behavior of failing entirely when an invalid block is encountered. Changes: - Modified ImportConfig to use `fail_on_invalid_block` field (default: false) - Extended ImportResult with `stopped_on_invalid_block`, `bad_block`, and `last_valid_block` fields - Added `is_successful()` method to ImportResult - Use `Pipeline::run_loop()` by default to handle unwinds gracefully - Use `Pipeline::run()` when `--fail-on-invalid-block` is set - Updated CLI documentation and book Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019bf0be-bb94-77f8-9c69-3f1c51e55fbd
89d45fd to
3d89619
Compare
yongkangc
approved these changes
Jan 26, 2026
rakita
pushed a commit
that referenced
this pull request
Jan 26, 2026
…#21403) Co-authored-by: Amp <amp@ampcode.com>
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.
Summary
When importing blocks, the import now stops at the last valid block by default if an invalid block is encountered during execution or validation. The database is left at the last valid block state.
A new
--fail-on-invalid-blockflag is provided to restore the original behavior of failing entirely when an invalid block is encountered.Motivation
This is the expected behavior for Hive consensus tests that import chains with intentionally invalid blocks. From the Hive consensus test documentation:
Previously, reth failed entirely when encountering invalid blocks during import, causing these Hive tests to fail. Now this behavior is the default, and the old behavior can be restored with
--fail-on-invalid-block.Implementation
ImportConfigto usefail_on_invalid_blockfield (default: false)ImportResultwithstopped_on_invalid_block,bad_block, andlast_valid_blockfieldsis_successful()method toImportResultPipeline::run_loop()by default to handleControlFlow::UnwindgracefullyPipeline::run()when--fail-on-invalid-blockis setmake update-book-cliUsage
Default behavior (stop at last valid block):
Old behavior (fail on invalid block):
Testing
bcInvalidHeaderTestsuite (22/22 tests passing includingwrongStateRoot,wrongGasUsed,wrongParentHash, etc.)