Skip to content

feat(l2): commit blocks in batches#2397

Merged
jrchatruc merged 116 commits into
mainfrom
l2/feat/commit_in_batches
Apr 29, 2025
Merged

feat(l2): commit blocks in batches#2397
jrchatruc merged 116 commits into
mainfrom
l2/feat/commit_in_batches

Conversation

@avilagaston9

@avilagaston9 avilagaston9 commented Apr 3, 2025

Copy link
Copy Markdown
Contributor

Motivation

To reduce the number of times we go to the L1 to commit/verify blocks.

Description

  • Modifies l1_committer to merge as many blocks as possible into a single StateDiff before committing, limited by the blob size.
  • Modifies StateDiff to now contain both the resulting AccountUpdates from executing all blocks in the batch and the header of the last block.
  • Adapts contracts to use batchNumbers instead of blockNumbers.
  • Adds a new RPC endpoint, ethrex_getWithdrawalProof, which returns all necessary data to claim an L1 withdrawal for a given L2 withdrawal transaction hash.
  • Implements apply_account_updates for the ExecutionDB to prepare the db for executing the next block in the batch.
  • Adds a L2/storage with the following tables:
    • block_number => batch_number: Maps block numbers to batches (used by the endpoint to locate a withdrawal's batch).
    • batch_number => Vec<block_number>: Lists all block numbers included in a given batch.
    • batch_number => withdrawal_hashes: Stores withdrawal hashes per batch (used to construct merkle proofs).

Closes None

Created issues:

@github-actions

github-actions Bot commented Apr 3, 2025

Copy link
Copy Markdown

Lines of code report

Total lines added: 1238
Total lines removed: 328
Total lines changed: 1566

Detailed view
+--------------------------------------------------------------+-------+------+
| File                                                         | Lines | Diff |
+--------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/ethrex.rs                                  | 88    | +4   |
+--------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/initializers.rs                            | 374   | +22  |
+--------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/l2.rs                                      | 256   | +4   |
+--------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_l2/src/commands/stack.rs                   | 403   | +42  |
+--------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_l2/src/commands/wallet.rs                  | 564   | -54  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/src/backends/exec.rs                 | 81    | +20  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/pico/src/main.rs      | 63    | +18  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/risc0/src/main.rs     | 69    | +23  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/sp1/src/main.rs       | 70    | +21  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/src/sdk.rs                              | 214   | -81  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/block_producer/payload_builder.rs | 227   | +2   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_committer.rs                   | 505   | +82  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_proof_sender.rs                | 165   | -1   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_watcher.rs                     | 281   | +1   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/metrics.rs                        | 81    | -1   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/mod.rs                            | 65    | +5   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/proof_coordinator.rs              | 293   | +29  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/state_diff.rs                     | 469   | +3   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/api.rs                          | 34    | +34  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/lib.rs                          | 5     | +5   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/rlp.rs                          | 74    | +74  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store.rs                        | 121   | +121 |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/in_memory.rs           | 97    | +97  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/libmdbx.rs             | 141   | +141 |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/mod.rs                 | 5     | +5   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/redb.rs                | 151   | +151 |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/l2/utils/test_data_io.rs                       | 87    | +1   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/clients/eth/errors.rs           | 209   | +13  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/clients/eth/mod.rs              | 1039  | +46  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/filter.rs                   | 542   | -63  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/gas_price.rs                | 112   | -27  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/max_priority_fee.rs         | 129   | +5   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/l2/mod.rs                       | 2     | +1   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/l2/withdrawal.rs                | 82    | +82  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/rpc.rs                          | 643   | -78  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/utils.rs                        | 411   | +77  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/storage/account_update.rs                      | 39    | +39  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/storage/lib.rs                                 | 12    | +1   |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs                               | 1225  | -23  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/db.rs                         | 193   | +13  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs                        | 648   | +21  |
+--------------------------------------------------------------+-------+------+
| ethrex/crates/vm/db.rs                                       | 81    | +35  |
+--------------------------------------------------------------+-------+------+

@avilagaston9 avilagaston9 changed the title feat(l2): commit and verify block in batches feat(l2): commit and verify blocks in batches Apr 3, 2025
@avilagaston9 avilagaston9 self-assigned this Apr 3, 2025
@avilagaston9 avilagaston9 force-pushed the l2/feat/commit_in_batches branch from 54a1e03 to 3af5fc3 Compare April 7, 2025 19:10
@avilagaston9 avilagaston9 changed the title feat(l2): commit and verify blocks in batches feat(l2): commit blocks in batches Apr 9, 2025
@avilagaston9 avilagaston9 mentioned this pull request Apr 10, 2025
@avilagaston9 avilagaston9 force-pushed the l2/feat/commit_in_batches branch from 5f1ff8e to 25ec922 Compare April 10, 2025 22:31
@avilagaston9 avilagaston9 force-pushed the l2/feat/commit_in_batches branch from 7a90f20 to 2facbef Compare April 25, 2025 18:05
@avilagaston9 avilagaston9 force-pushed the l2/feat/commit_in_batches branch from fb8f0b2 to 1eeb1eb Compare April 25, 2025 18:50
Comment thread crates/l2/docs/state_diffs.md
Comment thread crates/l2/sequencer/block_producer/payload_builder.rs Outdated
Comment thread crates/networking/rpc/clients/eth/mod.rs Outdated
Comment thread crates/l2/sequencer/l1_committer.rs Outdated
Comment thread crates/l2/sequencer/l1_committer.rs Outdated
Comment thread crates/l2/sequencer/l1_committer.rs Outdated
@jrchatruc jrchatruc added this pull request to the merge queue Apr 29, 2025
Merged via the queue into main with commit a8d2ec4 Apr 29, 2025
@jrchatruc jrchatruc deleted the l2/feat/commit_in_batches branch April 29, 2025 16:05
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
**Motivation**

In lambdaclass#2397, we are having issues with Pico dependencies. Since we are not
using it at the moment, we prefer to temporarily disable the job until
we focus on it later.

**Description**

- Disable pico job renaming `pr-main_l2_prover_nightly.yaml` to
`.github/workflows/pr-main_l2_prover_nightly.yaml.disabled`.
- Create lambdaclass#2550.

Closes None
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
**Motivation**

To reduce the number of times we go to the L1 to commit/verify blocks.

**Description**

- Modifies `l1_committer` to merge as many blocks as possible into a
single `StateDiff` before committing, limited by the blob size.
- Modifies `StateDiff` to now contain both the resulting
`AccountUpdates` from executing all blocks in the batch and the header
of the last block.
- Adapts contracts to use `batchNumbers` instead of `blockNumbers`.
- Adds a new RPC endpoint, `ethrex_getWithdrawalProof`, which returns
all necessary data to claim an L1 withdrawal for a given L2 withdrawal
transaction hash.
- Implements `apply_account_updates` for the `ExecutionDB` to prepare
the db for executing the next block in the batch.
- Adds a `L2/storage` with the following tables:
- `block_number` => `batch_number`: Maps block numbers to batches (used
by the endpoint to locate a withdrawal's batch).
- `batch_number` => `Vec<block_number>`: Lists all block numbers
included in a given batch.
- `batch_number` => `withdrawal_hashes`: Stores withdrawal hashes per
batch (used to construct merkle proofs).

Closes None

Created issues:
- lambdaclass#2563
- lambdaclass#2578 
- lambdaclass#2579 
- lambdaclass#2617

---------

Co-authored-by: Edgar <git@edgl.dev>
Co-authored-by: VolodymyrBg <aqdrgg19@gmail.com>
Co-authored-by: Tomás Paradelo <112426153+tomip01@users.noreply.github.com>
Co-authored-by: Javier Rodríguez Chatruc <49622509+jrchatruc@users.noreply.github.com>
Co-authored-by: Mauro Toscano <12560266+MauroToscano@users.noreply.github.com>
Co-authored-by: Martin Paulucci <martin.c.paulucci@gmail.com>
Co-authored-by: Jeremías Salomón <48994069+JereSalo@users.noreply.github.com>
Co-authored-by: Lucas Fiegl <iovoid@users.noreply.github.com>
Co-authored-by: Cypher Pepe <125112044+cypherpepe@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

None yet

Development

Successfully merging this pull request may close these issues.