Skip to content

feat(l2): batch reversion #3136

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 4 commits into
base: main
Choose a base branch
from
Open

feat(l2): batch reversion #3136

wants to merge 4 commits into from

Conversation

iovoid
Copy link
Contributor

@iovoid iovoid commented Jun 11, 2025

Motivation

As outlined in #3124, sometimes a committed batch can't be verified or the operator wants to prevent it from going though.

Description

This PR implements a revertBatch function that allows reverting back to any batch, as long as no verified batches are being discarded.

There's also a l2 CLI subcommand, revert-batch that lets you revert a batch and remove it from the local database.

Usage on local network:

PRIVATE_KEY=key cargo run --features l2,rollup_storage_libmdbx -- l2 revert-batch \
  <batch to revert to> <OnChainProposer address> \
  --datadir dev_ethrex_l2 --network test_data/genesis-l2.json

Closes #3124

Copy link

github-actions bot commented Jun 11, 2025

Lines of code report

Total lines added: 232
Total lines removed: 0
Total lines changed: 232

Detailed view
+----------------------------------------------------+-------+------+
| File                                               | Lines | Diff |
+----------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/l2/command.rs                    | 458   | +90  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/src/sdk.rs                    | 507   | +16  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/api.rs                | 74    | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store.rs              | 259   | +3   |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/in_memory.rs | 193   | +18  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/libmdbx.rs   | 291   | +29  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/redb.rs      | 292   | +27  |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/api.rs                       | 269   | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs                     | 1362  | +3   |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/in_memory.rs        | 672   | +11  |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/libmdbx.rs          | 1475  | +18  |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/redb.rs             | 1306  | +15  |
+----------------------------------------------------+-------+------+

@iovoid iovoid marked this pull request as ready for review June 12, 2025 19:07
@iovoid iovoid requested review from jrchatruc, ManuelBilbao and a team as code owners June 12, 2025 19:07
@iovoid iovoid force-pushed the feat/revert-batch branch from fcb4138 to 622f6d6 Compare June 12, 2025 19:08
Comment on lines 509 to 528
async fn call_contract(
client: &EthClient,
private_key: &SecretKey,
to: Address,
signature: &str,
parameters: Vec<Value>,
) -> eyre::Result<()> {
let calldata = encode_calldata(signature, &parameters)?.into();
let from = get_address_from_secret_key(private_key)?;
let tx = client
.build_eip1559_transaction(to, from, calldata, Default::default())
.await?;

let tx_hash = client.send_eip1559_transaction(&tx, private_key).await?;

info!("TxID: {tx_hash:#x}",);

wait_for_transaction_receipt(tx_hash, client, 100).await?;
Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should go in the SDK

Copy link
Contributor

Choose a reason for hiding this comment

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

+1. We may have something like this already, I don't remember.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilitteri
Copy link
Contributor

I'd add some integration tests or file an issue for doing so in the future.

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: Batch Reversion
3 participants