Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

feat(protocol): add BatchDropReason enum for improved batch validation#3147

Merged
theochap merged 5 commits intoop-rs:mainfrom
Himess:feat/batch-drop-reasons
Jan 8, 2026
Merged

feat(protocol): add BatchDropReason enum for improved batch validation#3147
theochap merged 5 commits intoop-rs:mainfrom
Himess:feat/batch-drop-reasons

Conversation

@Himess
Copy link
Contributor

@Himess Himess commented Dec 5, 2025

Closes #3127
Previously, batch validation failures could only be diagnosed by parsing log messages, which is fragile and not programmatically testable. This change enables:

  • Precise programmatic testing of batch validation logic
  • Better error messages with structured drop reasons
  • Improved debugging experience for node operators

Changes

  • BatchDropReason enum with variants for all drop scenarios:
    • Timestamp related: FutureTimestampHolocene, PastTimestampPreHolocene
    • Parent/origin: ParentHashMismatch, IncludedTooLate, EpochTooOld, EpochTooFarInFuture, EpochHashMismatch
    • Sequencer drift: TimestampBeforeL1Origin, SequencerDriftOverflow, SequencerDriftExceeded, SequencerDriftNotAdoptedNextOrigin
    • Transaction validation: EmptyTransaction, DepositTransaction, Eip7702PreIsthmus, NonEmptyTransitionBlock
    • Span batch specific: SpanBatchPreDelta, SpanBatchNoNewBlocksPreHolocene, SpanBatchMisalignedTimestamp, SpanBatchNotOverlappedExactly
    • Overlap validation: L1OriginBeforeSafeHead, MissingL1Origin, OverlappedTxCountMismatch, OverlappedTxMismatch, L2BlockInfoExtractionFailed, OverlappedL1OriginMismatch

…n error handling

## Summary
- Added `BatchDropReason` enum with 24 variants covering all possible batch drop scenarios
- Modified `BatchValidity::Drop` to include the reason: `Drop(BatchDropReason)`
- Updated `SingleBatch::check_batch` to return specific drop reasons
- Updated `SpanBatch::check_batch` and `check_batch_prefix` to return specific drop reasons
- Updated downstream consumers in `kona-derive` to handle the new signature
- Enhanced logging to include drop reasons for better debugging

## Motivation
Previously, batch validation failures could only be diagnosed by parsing log messages,
which is fragile and not programmatically testable. This change enables:
- Precise programmatic testing of batch validation logic
- Better error messages with structured drop reasons
- Improved debugging experience for node operators

Closes op-rs#3127
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 80.26316% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.3%. Comparing base (d7d4b5d) to head (70ca2af).
⚠️ Report is 32 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/protocol/protocol/src/batch/validity.rs 59.6% 21 Missing ⚠️
crates/protocol/protocol/src/batch/single.rs 46.6% 8 Missing ⚠️
crates/protocol/protocol/src/batch/span.rs 98.7% 1 Missing ⚠️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Use inline format args in Display impl (clippy::uninlined_format_args)
- Fix test expectation: test_check_batch_block_timestamp_lt_l1_origin
  should expect TimestampBeforeL1Origin, not OverlappedTxMismatch
The test expects "batch exceeded sequencer time drift without adopting
next origin" log message, which corresponds to SequencerDriftNotAdoptedNextOrigin,
not EpochTooOld.
- Replace .init() with set_default() in span batch tests to avoid
  global subscriber conflicts when running tests in parallel
- Add missing vec import in block.rs tests
- Fix expected BatchDropReason values in tests:
  - test_check_batch_no_new_blocks: FutureTimestampHolocene -> SpanBatchNoNewBlocksPreHolocene
  - test_check_sequence_window_expired: ParentHashMismatch -> IncludedTooLate
  - test_starting_epoch_too_far_ahead: IncludedTooLate -> EpochTooFarInFuture
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has been inactive for 3 weeks.
It will be closed in 1 week if no further activity occurs.
If you believe this PR should remain open, please add the M-prevent-stale label or leave a comment.

@github-actions github-actions bot added M-stale and removed M-stale labels Dec 30, 2025
Copy link
Member

@theochap theochap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for taking care of that

@theochap
Copy link
Member

theochap commented Jan 8, 2026

@Himess can you fix the deny CI job?

@theochap theochap added this pull request to the merge queue Jan 8, 2026
Merged via the queue into op-rs:main with commit 494722b Jan 8, 2026
42 of 47 checks passed
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Jan 15, 2026
op-rs/kona#3147)

Closes #3127
Previously, batch validation failures could only be diagnosed by parsing
log messages, which is fragile and not programmatically testable. This
change enables:
- Precise programmatic testing of batch validation logic
- Better error messages with structured drop reasons
- Improved debugging experience for node operators

## Changes

- `BatchDropReason` enum with variants for all drop scenarios:
- Timestamp related: `FutureTimestampHolocene`,
`PastTimestampPreHolocene`
- Parent/origin: `ParentHashMismatch`, `IncludedTooLate`, `EpochTooOld`,
`EpochTooFarInFuture`, `EpochHashMismatch`
- Sequencer drift: `TimestampBeforeL1Origin`, `SequencerDriftOverflow`,
`SequencerDriftExceeded`, `SequencerDriftNotAdoptedNextOrigin`
- Transaction validation: `EmptyTransaction`, `DepositTransaction`,
`Eip7702PreIsthmus`, `NonEmptyTransitionBlock`
- Span batch specific: `SpanBatchPreDelta`,
`SpanBatchNoNewBlocksPreHolocene`, `SpanBatchMisalignedTimestamp`,
`SpanBatchNotOverlappedExactly`
- Overlap validation: `L1OriginBeforeSafeHead`, `MissingL1Origin`,
`OverlappedTxCountMismatch`, `OverlappedTxMismatch`,
`L2BlockInfoExtractionFailed`, `OverlappedL1OriginMismatch`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

protocol: Improve result/error contexts and testability

2 participants