Skip to content

feat(cli): make stopping on invalid block the default for reth import#21403

Merged
mattsse merged 1 commit intomainfrom
fix/stop-on-invalid-block-import
Jan 26, 2026
Merged

feat(cli): make stopping on invalid block the default for reth import#21403
mattsse merged 1 commit intomainfrom
fix/stop-on-invalid-block-import

Conversation

@mattsse
Copy link
Collaborator

@mattsse mattsse commented Jan 24, 2026

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-block flag 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:

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.

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

  • 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 ControlFlow::Unwind gracefully
  • Use Pipeline::run() when --fail-on-invalid-block is set
  • Updated CLI documentation and book via make update-book-cli

Usage

Default behavior (stop at last valid block):

reth import chain.rlp

Old behavior (fail on invalid block):

reth import --fail-on-invalid-block chain.rlp

Testing

  • All unit tests pass (40/40)
  • Clippy passes with no warnings
  • Code is properly formatted
  • Hive consensus tests pass: Tested with bcInvalidHeaderTest suite (22/22 tests passing including wrongStateRoot, wrongGasUsed, wrongParentHash, etc.)

@mattsse mattsse added the A-cli Related to the reth CLI label Jan 24, 2026
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Jan 24, 2026
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
@mattsse mattsse force-pushed the fix/stop-on-invalid-block-import branch from 89d45fd to 3d89619 Compare January 24, 2026 16:22
@mattsse mattsse requested a review from gakonst as a code owner January 24, 2026 16:22
@mattsse mattsse changed the title feat(cli): add --stop-on-invalid-block flag to reth import feat(cli): make stopping on invalid block the default for reth import Jan 24, 2026
@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Jan 26, 2026
@mattsse mattsse added this pull request to the merge queue Jan 26, 2026
Merged via the queue into main with commit 934f462 Jan 26, 2026
47 checks passed
@mattsse mattsse deleted the fix/stop-on-invalid-block-import branch January 26, 2026 12:51
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Jan 26, 2026
rakita pushed a commit that referenced this pull request Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Related to the reth CLI

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants