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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

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
.join("../rollup_store")
.join("./rollup_store")
Copy link
Contributor

Choose a reason for hiding this comment

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

Create an issue to make this an ethrex_l2 stack reconstruct flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we could rename store_path to data_dir and place both store and rollup_store under that directory?

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #2656

Comment on lines 153 to 157
// Get the pending deposits from the contract.
let pending_deposits = self
.eth_client
.get_pending_deposit_logs(self.address)
.await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's execute this only if the first if condition of deposit_already_processed is false and avoid doing this otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in c5512fe!

Comment on lines 161 to 168
mint_value,
to_address,
deposit_id,
recipient,
from,
gas_limit,
calldata,
deposit_hash,
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think of using a struct for this elements?
Something like DepositValues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created DepositData here 75e327e

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We should do 3. in the other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 1201ab4!

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