Skip to content

feat(l2): commit blocks in batches #2397

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 116 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
e1b15dc
Commit stateDiffs in batches
avilagaston9 Apr 3, 2025
f7dac5a
Modify stack to read batches
avilagaston9 Apr 3, 2025
0f5b31d
fix: use state root from headers
avilagaston9 Apr 3, 2025
1ebf86d
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 4, 2025
da7cafe
Fix linter
avilagaston9 Apr 4, 2025
6c29e0c
Update OnChainProposer
avilagaston9 Apr 4, 2025
720b06c
Update contracts to work with batchNumbers
avilagaston9 Apr 4, 2025
9b17446
Finalize the committing process
avilagaston9 Apr 6, 2025
82c0e43
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 6, 2025
a142a0a
Use only last header in StateDiff
avilagaston9 Apr 6, 2025
426babc
Update stack to reconstruct from the new state diff
avilagaston9 Apr 7, 2025
3af5fc3
Modify dev logic in prover_server
avilagaston9 Apr 7, 2025
bc48f76
Some fixes
avilagaston9 Apr 7, 2025
290f14e
Add l2 storage
avilagaston9 Apr 10, 2025
8881003
Implement withdrawal endpoint for integration test
avilagaston9 Apr 10, 2025
25ec922
Add missing changes
avilagaston9 Apr 10, 2025
fb0f735
Fix integration test
avilagaston9 Apr 10, 2025
7d31c24
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 10, 2025
cc8fe3d
Fix stack
avilagaston9 Apr 11, 2025
a241b39
Fix state reconstruct
avilagaston9 Apr 11, 2025
73b5774
Fix reconstruction test
avilagaston9 Apr 11, 2025
aee4d98
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 11, 2025
68b17fc
Add missing update
avilagaston9 Apr 11, 2025
dfb30cc
Fix linter
avilagaston9 Apr 11, 2025
f074da6
Fix linter
avilagaston9 Apr 13, 2025
360434f
Restore dev mode
avilagaston9 Apr 14, 2025
c69be4d
Fix test
avilagaston9 Apr 14, 2025
6f4cd08
Restore blobs
avilagaston9 Apr 14, 2025
0beff71
Add new genesis
avilagaston9 Apr 14, 2025
e1a58e0
Clean PR
avilagaston9 Apr 14, 2025
63562b9
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 14, 2025
4fe1208
Fix linter
avilagaston9 Apr 14, 2025
5e70f3b
Update error
avilagaston9 Apr 14, 2025
6b73ae5
Store batch when reconstructing state
avilagaston9 Apr 15, 2025
e29a6ba
Update wallet to use sdk
avilagaston9 Apr 15, 2025
8308833
Small improvements
avilagaston9 Apr 15, 2025
6ac802d
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 15, 2025
d73467b
Fix dependences
avilagaston9 Apr 15, 2025
f7eafa4
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 15, 2025
7d89cae
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 15, 2025
46b0b29
Update overview and contracts docs
avilagaston9 Apr 16, 2025
34199df
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 16, 2025
fb57d89
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 16, 2025
0626349
Restore genesis-l2.json
avilagaston9 Apr 16, 2025
f0653cb
Verify in batches
avilagaston9 Apr 22, 2025
2d3b8ca
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 22, 2025
f3a8762
Fix linter
avilagaston9 Apr 22, 2025
3b72e5c
Update readme
avilagaston9 Apr 22, 2025
321088c
Fix readme
avilagaston9 Apr 22, 2025
cfd4e8a
Update pico and risc0
avilagaston9 Apr 22, 2025
4882284
Update blobs
avilagaston9 Apr 22, 2025
305ec8b
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 22, 2025
6e7bd4c
Remove first and last block from contract
avilagaston9 Apr 22, 2025
5b95493
Fix prover
avilagaston9 Apr 22, 2025
be137b9
Make db mutable
avilagaston9 Apr 23, 2025
78858e2
Trigger CI build
avilagaston9 Apr 23, 2025
51b62dd
Fix pico
avilagaston9 Apr 23, 2025
9075a0e
Fix prover
avilagaston9 Apr 23, 2025
9520bf0
Trigger CI
avilagaston9 Apr 23, 2025
e9749e7
Improve stack readability
avilagaston9 Apr 23, 2025
479c13f
Improve readability for prepare_batch_from_block
avilagaston9 Apr 23, 2025
07f6494
Fix some typos
avilagaston9 Apr 23, 2025
ea4f57d
perf(core): transform the inline variant of NodeHash to a const sized…
edg-l Apr 23, 2025
283375b
Add --metrics flag to enable/disable metrics collection (#2497)
VolodymyrBg Apr 23, 2025
b862498
fix(l2): adapt parsing signature to dynamic types (#2487)
tomip01 Apr 23, 2025
0ea129f
fix(l2): add missing requirements to run the L2 (#2512)
MauroToscano Apr 23, 2025
ec500e6
fix(levm): improve get state transitions LEVM (#2518)
JereSalo Apr 23, 2025
79c3a98
fix(levm): also use config chain_id (#2537)
iovoid Apr 23, 2025
9a17797
fix(l1): validate incoming payloads even when the node is syncing. (#…
mpaulucci Apr 23, 2025
2dd185c
docs(l2): remove `proposer` in README.md (#2470)
cypherpepe Apr 23, 2025
266bccf
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 23, 2025
cbdb030
Update payload_builder with the new size of StateDiff
avilagaston9 Apr 23, 2025
5956d11
Update docs
avilagaston9 Apr 23, 2025
251b16d
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 23, 2025
efdf7a5
Merge main
avilagaston9 Apr 23, 2025
02b667e
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 23, 2025
73df73c
Fix merge
avilagaston9 Apr 23, 2025
8e40117
Fix linter
avilagaston9 Apr 23, 2025
f2ec6c4
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 24, 2025
fb9f8b3
Fix merge
avilagaston9 Apr 24, 2025
b680cfb
Correctly get the last block of batch
avilagaston9 Apr 24, 2025
b713d28
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 24, 2025
d72bd7c
Fix errors
avilagaston9 Apr 24, 2025
83b8fa5
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 24, 2025
4f21f4c
Remove prover server
avilagaston9 Apr 24, 2025
ecad4ae
Update LatestBlocks command
avilagaston9 Apr 24, 2025
ef87b0f
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 24, 2025
c29368e
Rename l2_store to rollup_store
avilagaston9 Apr 24, 2025
78c7b0b
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 24, 2025
697f939
Remove setting engine before panic
avilagaston9 Apr 24, 2025
98a4169
Rename tx_hash to l2_withdrawal_tx_hash
avilagaston9 Apr 24, 2025
64064cd
refactor: make get_last_[committed|verified]_block a method
avilagaston9 Apr 24, 2025
69126ce
Remove state_root from state_diff
avilagaston9 Apr 24, 2025
0f2104d
Restore blobs
avilagaston9 Apr 24, 2025
0aa19e6
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 24, 2025
f394811
Remove cumulative gas used from pico
avilagaston9 Apr 24, 2025
1be6290
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 24, 2025
1fee017
Refactor state reconstruct
avilagaston9 Apr 25, 2025
c298043
Rename storage-l2 to storage-rollup
avilagaston9 Apr 25, 2025
0e45d8d
Create rollup_storage_libmdbx feature flag
avilagaston9 Apr 25, 2025
7fa2787
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 25, 2025
1eeb1eb
Fix flags
avilagaston9 Apr 25, 2025
a6cbaaa
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 28, 2025
77a00eb
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 28, 2025
89d4a16
Make get_last_fetched_l1_block a method
avilagaston9 Apr 28, 2025
004e332
Move statediff constants to state_diff
avilagaston9 Apr 28, 2025
68e2a54
Init rollup_store with the batch 0
avilagaston9 Apr 28, 2025
2543264
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 28, 2025
b755fd2
Fix bench
avilagaston9 Apr 28, 2025
0529b51
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 28, 2025
133e9c5
Stop storing empty blocks on reconstruction
avilagaston9 Apr 28, 2025
459074a
Restore blobs
avilagaston9 Apr 28, 2025
445d28b
Merge branch 'main' into l2/feat/commit_in_batches
avilagaston9 Apr 28, 2025
d63d1d5
Increment commit time to 1 minute
avilagaston9 Apr 28, 2025
37646a7
Warn when the batch size limit is reached.
avilagaston9 Apr 28, 2025
65bb86f
Merge branch 'main' into l2/feat/commit_in_batches
jrchatruc Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"crates/l2/contracts",
"crates/l2/prover",
"crates/l2/sdk",
"crates/l2/storage",
"crates/networking/p2p",
"crates/networking/rpc",
"crates/storage",
Expand Down Expand Up @@ -48,6 +49,7 @@ ethrex-rlp = { path = "./crates/common/rlp" }
ethrex-l2 = { path = "./crates/l2" }
ethrex-sdk = { path = "./crates/l2/sdk" }
ethrex-prover = { path = "./crates/l2/prover" }
ethrex-storage-l2 = { path = "./crates/l2/storage" }

tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
Expand Down
16 changes: 9 additions & 7 deletions cmd/ethrex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ethrex-p2p.workspace = true
ethrex-storage.workspace = true
ethrex-vm.workspace = true
ethrex-rlp.workspace = true
ethrex-storage-l2 = { workspace = true, optional = true }
ethrex-l2 = { workspace = true, optional = true }

bytes.workspace = true
Expand Down Expand Up @@ -59,15 +60,16 @@ c-kzg = [
"ethrex-p2p/c-kzg",
]
metrics = ["ethrex-blockchain/metrics"]
libmdbx = ["ethrex-storage/libmdbx"]
redb = ["dep:redb", "ethrex-storage/redb"]
libmdbx = ["ethrex-storage/libmdbx", "ethrex-storage-l2/libmdbx"]
redb = ["dep:redb", "ethrex-storage/redb", "ethrex-storage-l2/redb"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this import ethrex-storage-l2 when the l2 feature is unset?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this, I defined the rollup_storage_libmdbx and rollup_storage_redb feature flags in 0e45d8d. I'm not happy with this approach, but if you have a better idea, I'd be glad to change it.

blst = ["ethrex-vm/blst"]
l2 = [
"dep:ethrex-l2",
"ethrex-vm/l2",
"ethrex-blockchain/l2",
"ethrex-rpc/l2",
"dep:secp256k1",
"dep:ethrex-l2",
"ethrex-vm/l2",
"ethrex-blockchain/l2",
"ethrex-rpc/l2",
"dep:secp256k1",
"ethrex-storage-l2"
]
based = ["l2", "ethrex-rpc/based"]

Expand Down
4 changes: 4 additions & 0 deletions cmd/ethrex/ethrex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use tracing::info;

#[cfg(any(feature = "l2", feature = "based"))]
use ethrex::l2::L2Options;
#[cfg(feature = "l2")]
use ethrex_storage_l2::StoreL2;

#[tokio::main]
async fn main() -> eyre::Result<()> {
Expand Down Expand Up @@ -55,6 +57,8 @@ async fn main() -> eyre::Result<()> {
blockchain.clone(),
cancel_token.clone(),
tracker.clone(),
#[cfg(feature = "l2")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[cfg(feature = "l2")]
#[cfg(any(feature = "l2", feature = "based"))]

StoreL2::default(),
)
.await;

Expand Down
25 changes: 25 additions & 0 deletions cmd/ethrex/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::l2::L2Options;
use ::{
ethrex_common::Address,
ethrex_l2::utils::config::{read_env_file_by_config, ConfigMode},
ethrex_storage_l2::{EngineTypeL2, StoreL2},
secp256k1::SecretKey,
};

Expand Down Expand Up @@ -94,6 +95,27 @@ pub async fn init_store(data_dir: &str, network: &str) -> Store {
store
}

#[cfg(feature = "l2")]
pub async fn init_l2_store(data_dir: &str) -> StoreL2 {
let path = PathBuf::from(data_dir);
if path.ends_with("memory") {
StoreL2::new(data_dir, EngineTypeL2::InMemory).expect("Failed to create StoreL2")
} else {
cfg_if::cfg_if! {
if #[cfg(feature = "redb")] {
let engine_type = EngineTypeL2::RedB;
} else if #[cfg(feature = "libmdbx")] {
let engine_type = EngineTypeL2::Libmdbx;
} else {
let engine_type = EngineTypeL2::InMemory;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you specify in memory if you're going to panic in the next line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a legacy from init_store. Removed from both functions in 697f939!

error!("No database specified. The feature flag `redb` or `libmdbx` should've been set while building.");
panic!("Specify the desired database engine.");
}
}
StoreL2::new(data_dir, engine_type).expect("Failed to create StoreL2")
}
}

pub fn init_blockchain(evm_engine: EvmEngine, store: Store) -> Arc<Blockchain> {
Blockchain::new(evm_engine, store).into()
}
Expand All @@ -109,6 +131,7 @@ pub async fn init_rpc_api(
blockchain: Arc<Blockchain>,
cancel_token: CancellationToken,
tracker: TaskTracker,
#[cfg(feature = "l2")] l2_store: StoreL2,
) {
let enr_seq = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand Down Expand Up @@ -146,6 +169,8 @@ pub async fn init_rpc_api(
get_valid_delegation_addresses(l2_opts),
#[cfg(feature = "l2")]
get_sponsor_pk(l2_opts),
#[cfg(feature = "l2")]
l2_store,
)
.into_future();

Expand Down
20 changes: 12 additions & 8 deletions cmd/ethrex/l2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
cli::{self as ethrex_cli, Options},
initializers::{
get_local_p2p_node, get_network, get_signer, init_blockchain, init_metrics, init_network,
init_rpc_api, init_store,
get_local_p2p_node, get_network, get_signer, init_blockchain, init_l2_store, init_metrics,
init_network, init_rpc_api, init_store,
},
utils::{self, set_datadir, store_known_peers},
DEFAULT_L2_DATADIR,
Expand Down Expand Up @@ -121,12 +121,14 @@ impl Command {
match self {
Command::Init { opts } => {
let data_dir = set_datadir(&opts.node_opts.datadir);
let l2_store_dir = data_dir.clone() + "/l2_store";

let network = get_network(&opts.node_opts);

let store = init_store(&data_dir, &network).await;
let l1_store = init_store(&data_dir, &network).await;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not the L1 store.

Copy link
Contributor

@tomip01 tomip01 Apr 24, 2025

Choose a reason for hiding this comment

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

Agree, I think I would keep the l1_store as store and name l2_store as something like the commiter_store

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to rollup_store as discussed offline in c29368e!

let l2_store = init_l2_store(&l2_store_dir).await;

let blockchain = init_blockchain(opts.node_opts.evm, store.clone());
let blockchain = init_blockchain(opts.node_opts.evm, l1_store.clone());

let signer = get_signer(&data_dir);

Expand All @@ -145,10 +147,11 @@ impl Command {
&signer,
peer_table.clone(),
local_p2p_node,
store.clone(),
l1_store.clone(),
blockchain.clone(),
cancel_token.clone(),
tracker.clone(),
l2_store.clone(),
)
.await;

Expand All @@ -165,7 +168,7 @@ impl Command {
local_p2p_node,
signer,
peer_table.clone(),
store.clone(),
l1_store.clone(),
tracker.clone(),
blockchain.clone(),
)
Expand All @@ -174,7 +177,8 @@ impl Command {
info!("P2P is disabled");
}

let l2_sequencer = ethrex_l2::start_l2(store, blockchain).into_future();
let l2_sequencer =
ethrex_l2::start_l2(l1_store, l2_store, blockchain).into_future();

tracker.spawn(l2_sequencer);

Expand Down Expand Up @@ -219,7 +223,7 @@ impl Command {
.checked_sub(U256::from(64))
.ok_or_eyre("Cannot get finalized block")?;

let event_signature = keccak("BlockCommitted(bytes32)");
let event_signature = keccak("BatchCommitted(bytes32)");

loop {
// Wait for a block
Expand Down
1 change: 1 addition & 0 deletions cmd/ethrex_l2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ethrex-blockchain = { workspace = true, features = ["l2"] }
ethrex-rlp.workspace = true
ethrex-rpc.workspace = true
ethrex-storage = { workspace = true, features = ["libmdbx"] }
ethrex-storage-l2 = { workspace = true, features = ["libmdbx"] }

serde_json.workspace = true
serde.workspace = true
Expand Down
16 changes: 8 additions & 8 deletions cmd/ethrex_l2/src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ impl Command {
let on_chain_proposer_address = cfg.contracts.on_chain_proposer;
match self {
Command::LatestBlocks => {
let last_committed_block =
EthClient::get_last_committed_block(&eth_client, on_chain_proposer_address)
let last_committed_batch =
EthClient::get_last_committed_batch(&eth_client, on_chain_proposer_address)
.await?;

let last_verified_block =
EthClient::get_last_verified_block(&eth_client, on_chain_proposer_address)
let last_verified_batch =
EthClient::get_last_verified_batch(&eth_client, on_chain_proposer_address)
.await?;

println!(
"latestCommittedBlock: {}",
format!("{last_committed_block}").bright_cyan()
"latestCommittedBatch: {}",
format!("{last_committed_batch}").bright_cyan()
);

println!(
"latestVerifiedBlock: {}",
format!("{last_verified_block}").bright_cyan()
"latestVerifiedBatch: {}",
format!("{last_verified_batch}").bright_cyan()
);
}
Command::BlockNumber { l2, l1 } => {
Expand Down
Loading