Skip to content

Conversation

@tomip01
Copy link
Contributor

@tomip01 tomip01 commented Nov 12, 2025

Motivation

The L2 was failing when trying to commit the first batch that was empty.
Inside produce_batch_from_block when doing the metrics we do:

let first_block_of_batch = last_added_block_number + 1;
// Rest of the code ...
let batch_size = (last_added_block_number - first_block_of_batch).try_into()?; // batch_size is an `i64`

This could end up in u64::max and failing the conversion because if there are no blocks in the batch we never do last_added_block_number += 1; inside the loop.

Description

  • Handle the empty batch before doing the metrics
  • Change produce_batch_from_block to return an Option<T>

@github-actions
Copy link

github-actions bot commented Nov 12, 2025

Lines of code report

Total lines added: 4
Total lines removed: 0
Total lines changed: 4

Detailed view
+--------------------------------------------+-------+------+
| File                                       | Lines | Diff |
+--------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_committer.rs | 1077  | +4   |
+--------------------------------------------+-------+------+

This reverts commit 6420c7b.
@tomip01 tomip01 changed the title [TEST] debuginf l2 --dev flaky fix(l2): handle empty batches earlier Nov 12, 2025
@github-actions github-actions bot added the L2 Rollup client label Nov 12, 2025
@tomip01 tomip01 changed the title fix(l2): handle empty batches earlier fix(l2): handle committing empty batches earlier Nov 12, 2025
@tomip01 tomip01 marked this pull request as ready for review November 12, 2025 19:22
Copilot AI review requested due to automatic review settings November 12, 2025 19:22
@tomip01 tomip01 requested a review from a team as a code owner November 12, 2025 19:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug where the L2 sequencer would crash when attempting to commit an empty batch. The issue occurred during metrics calculation where an underflow would happen in the batch_size computation when no blocks were added to the batch.

  • Changed prepare_batch_from_block to return Option<T> to handle empty batches gracefully
  • Added early detection of empty batches before metrics calculation
  • Updated the caller to properly handle the None case with pattern matching

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tomip01 tomip01 marked this pull request as draft November 12, 2025 19:28
@tomip01 tomip01 changed the title fix(l2): handle committing empty batches earlier fix(l2): handle better when producing an empty batch Nov 12, 2025
@tomip01 tomip01 marked this pull request as ready for review November 12, 2025 19:41
@tomip01 tomip01 force-pushed the debug_l2_dev_flaky branch 2 times, most recently from 6e0447b to 79aec4a Compare November 12, 2025 21:03
@ilitteri ilitteri added this pull request to the merge queue Nov 12, 2025
Merged via the queue into main with commit cbb1fe5 Nov 13, 2025
36 checks passed
@ilitteri ilitteri deleted the debug_l2_dev_flaky branch November 13, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants