Skip to content

fix(l2): ignore deposits after state reconstruction #2642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 5, 2025

Conversation

avilagaston9
Copy link
Contributor

@avilagaston9 avilagaston9 commented Apr 29, 2025

Motivation

Currently, If we start our l2 node with a reconstructed state, the node will process all deposit logs from l1 and mint them again in l2. This is because, in a reconstructed store, we don't have the included transactions to determine whether a deposit was previously processed or not.

Description

  • Fixes the reconstruct algorithm to start from batch_number=1.
  • Fixes the l2MintTxHash emitted in the CommonBridge contract.
  • Adds an additional check to the integration_test to wait for the deposit receipt on L2.
  • Reuses the emitted l2MintTxHash instead of recalculating it in the watcher.
  • Checks, in the CommonBridge contract, whether a deposit is pending or not before minting the transaction.
  • Creates DepositData struct in l1_watcher

How to test

Here we are going to run the integration test on a node with a reconstructed state.
You may want to lower the commit_time_ms.

  1. Start the prover and network with:
make init-prover
make init
  1. Wait until batch 6 is verified and stop the l2 node with ctrl + c:
INFO ethrex_l2::sequencer::l1_proof_sender: Sent proof for batch 6...
ctrl + c

Note

This is because we are going to use already created blobs with 6 batches and we need
to advance the L1 until that point.

  1. Clean db:
make rm-db-l2
  1. Reconstruct the state choosing a path_to_store:
cargo run --release --manifest-path ../../cmd/ethrex_l2/Cargo.toml --bin ethrex_l2 -- stack reconstruct -g ../../test_data/genesis-l2.json -b ../../test_data/blobs/ -s path_to_store -c 0x0007a881CD95B1484fca47615B64803dad620C8d
  1. Start the l2 node using path_to_store:
make init-l2 ethrex_L2_DEV_LIBMDBX=path_to_store

You should observe that all deposits are skipped now.

  1. In a new terminal, run the integration test:
cd crates/l2
make test

Warning

Before running the integration test, wait for 20 blocks to be built in the L2.
This is because the test currently uses estimate_gas_tip that needs at least 20 blocks to estimate the gas price.

Closes #1279

@avilagaston9 avilagaston9 self-assigned this Apr 29, 2025
Copy link

github-actions bot commented Apr 29, 2025

Lines of code report

Total lines added: 44
Total lines removed: 0
Total lines changed: 44

Detailed view
+-------------------------------------------------+-------+------+
| File                                            | Lines | Diff |
+-------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_l2/src/commands/stack.rs      | 404   | +1   |
+-------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_watcher.rs        | 301   | +20  |
+-------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/clients/eth/mod.rs | 1099  | +23  |
+-------------------------------------------------+-------+------+

@avilagaston9 avilagaston9 marked this pull request as ready for review April 30, 2025 17:59
@avilagaston9 avilagaston9 requested a review from a team as a code owner April 30, 2025 17:59
ilitteri
ilitteri previously approved these changes Apr 30, 2025
@ilitteri ilitteri dismissed their stale review April 30, 2025 20:02

We should wait for the deposit in the 3 L2 tests

@ilitteri ilitteri added this pull request to the merge queue May 5, 2025
Merged via the queue into main with commit b817a9a May 5, 2025
27 checks passed
@ilitteri ilitteri deleted the l2/fix/deposits_after_reconstruct branch May 5, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

L2: improve and refactor l1_watcher
3 participants