From 24d54a54b8d546e3d5ff0eb8e77f784bc9d4d491 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Wed, 24 Sep 2025 15:50:35 -0300 Subject: [PATCH 01/11] Add max mempool size parameter --- cmd/ethrex/cli.rs | 20 ++++++++++++-- cmd/ethrex/initializers.rs | 10 +++++-- cmd/ethrex/l2/initializers.rs | 7 ++++- cmd/ethrex_replay/src/cli.rs | 11 ++++++-- crates/blockchain/blockchain.rs | 13 ++++++--- crates/blockchain/mempool.rs | 27 ++++++++++--------- crates/blockchain/smoke_test.rs | 15 ++++++----- crates/networking/p2p/sync.rs | 3 +++ tooling/ef_tests/blockchain/test_runner.rs | 9 ++++++- .../state_v2/src/modules/block_runner.rs | 9 ++++++- 10 files changed, 92 insertions(+), 32 deletions(-) diff --git a/cmd/ethrex/cli.rs b/cmd/ethrex/cli.rs index 066fe5dd81..7a5060ddd0 100644 --- a/cmd/ethrex/cli.rs +++ b/cmd/ethrex/cli.rs @@ -167,6 +167,13 @@ pub struct Options { help_heading = "P2P options" )] pub discovery_port: String, + #[arg( + help = "Maximum size of the mempool in number of transactions", + long = "mempool.maxsize", + default_value_t = 10_000, + value_name = "MEMPOOL_MAX_SIZE" + )] + pub mempool_max_size: usize, } impl Options { @@ -229,6 +236,7 @@ impl Default for Options { metrics_enabled: Default::default(), dev: Default::default(), force: false, + mempool_max_size: Default::default(), } } } @@ -322,7 +330,14 @@ impl Subcommand { } else { BlockchainType::L1 }; - import_blocks(&path, &opts.datadir, genesis, blockchain_type).await?; + import_blocks( + &path, + &opts.datadir, + genesis, + blockchain_type, + opts.mempool_max_size, + ) + .await?; } Subcommand::Export { path, first, last } => { export_blocks(&path, &opts.datadir, first, last).await @@ -370,11 +385,12 @@ pub async fn import_blocks( datadir: &Path, genesis: Genesis, blockchain_type: BlockchainType, + max_mempool_size: usize, ) -> Result<(), ChainError> { let start_time = Instant::now(); init_datadir(datadir); let store = init_store(datadir, genesis).await; - let blockchain = init_blockchain(store.clone(), blockchain_type, false); + let blockchain = init_blockchain(store.clone(), blockchain_type, false, max_mempool_size); let path_metadata = metadata(path).expect("Failed to read path"); // If it's an .rlp file it will be just one chain, but if it's a directory there can be multiple chains. diff --git a/cmd/ethrex/initializers.rs b/cmd/ethrex/initializers.rs index 54699aa41d..bd9f92dc3a 100644 --- a/cmd/ethrex/initializers.rs +++ b/cmd/ethrex/initializers.rs @@ -118,12 +118,13 @@ pub fn init_blockchain( store: Store, blockchain_type: BlockchainType, perf_logs_enabled: bool, + max_mempool_size: usize, ) -> Arc { #[cfg(feature = "revm")] info!("Initiating blockchain with revm"); #[cfg(not(feature = "revm"))] info!("Initiating blockchain with levm"); - Blockchain::new(store, blockchain_type, perf_logs_enabled).into() + Blockchain::new(store, blockchain_type, perf_logs_enabled, max_mempool_size).into() } #[allow(clippy::too_many_arguments)] @@ -388,7 +389,12 @@ pub async fn init_l1( #[cfg(feature = "sync-test")] set_sync_block(&store).await; - let blockchain = init_blockchain(store.clone(), BlockchainType::L1, true); + let blockchain = init_blockchain( + store.clone(), + BlockchainType::L1, + true, + opts.mempool_max_size, + ); let signer = get_signer(datadir); diff --git a/cmd/ethrex/l2/initializers.rs b/cmd/ethrex/l2/initializers.rs index 3fb7b489c8..43ec33b468 100644 --- a/cmd/ethrex/l2/initializers.rs +++ b/cmd/ethrex/l2/initializers.rs @@ -170,7 +170,12 @@ pub async fn init_l2( let store = init_store(&datadir, genesis).await; let rollup_store = init_rollup_store(&rollup_store_dir).await; - let blockchain = init_blockchain(store.clone(), BlockchainType::L2, true); + let blockchain = init_blockchain( + store.clone(), + BlockchainType::L2, + true, + opts.node_opts.mempool_max_size, + ); let signer = get_signer(&datadir); diff --git a/cmd/ethrex_replay/src/cli.rs b/cmd/ethrex_replay/src/cli.rs index 39a0852ece..55dd07c4ea 100644 --- a/cmd/ethrex_replay/src/cli.rs +++ b/cmd/ethrex_replay/src/cli.rs @@ -63,6 +63,8 @@ pub const BACKEND: Backend = Backend::RISC0; #[cfg(not(any(feature = "sp1", feature = "risc0")))] pub const BACKEND: Backend = Backend::Exec; +const MAX_MEMPOOL_SIZE: usize = 10_000; + #[derive(Parser)] #[command(name="ethrex-replay", author, version=VERSION_STRING, about, long_about = None)] pub struct EthrexReplayCLI { @@ -571,7 +573,7 @@ async fn replay_no_zkvm(cache: Cache, opts: &EthrexReplayOptions) -> eyre::Resul store.add_block_header(header.hash(), header).await?; } - let blockchain = Blockchain::default_with_store(store); + let blockchain = Blockchain::default_with_store(store, MAX_MEMPOOL_SIZE); info!("Storage preparation finished in {:.2?}", start.elapsed()); @@ -828,7 +830,12 @@ pub async fn replay_custom_l1_blocks( store_inner }; - let blockchain = Arc::new(Blockchain::new(store.clone(), BlockchainType::L1, false)); + let blockchain = Arc::new(Blockchain::new( + store.clone(), + BlockchainType::L1, + false, + MAX_MEMPOOL_SIZE, + )); let blocks = produce_l1_blocks( blockchain.clone(), diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index 02101bae70..c71702d424 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -94,10 +94,15 @@ fn log_batch_progress(batch_size: u32, current_block: u32) { } impl Blockchain { - pub fn new(store: Store, blockchain_type: BlockchainType, perf_logs_enabled: bool) -> Self { + pub fn new( + store: Store, + blockchain_type: BlockchainType, + perf_logs_enabled: bool, + max_mempool_size: usize, + ) -> Self { Self { storage: store, - mempool: Mempool::new(), + mempool: Mempool::new(max_mempool_size), is_synced: AtomicBool::new(false), r#type: blockchain_type, payloads: Arc::new(TokioMutex::new(Vec::new())), @@ -105,10 +110,10 @@ impl Blockchain { } } - pub fn default_with_store(store: Store) -> Self { + pub fn default_with_store(store: Store, max_mempool_size: usize) -> Self { Self { storage: store, - mempool: Mempool::new(), + mempool: Mempool::new(max_mempool_size), is_synced: AtomicBool::new(false), r#type: BlockchainType::default(), payloads: Arc::new(TokioMutex::new(Vec::new())), diff --git a/crates/blockchain/mempool.rs b/crates/blockchain/mempool.rs index b81196f6cd..7ee3bf07d2 100644 --- a/crates/blockchain/mempool.rs +++ b/crates/blockchain/mempool.rs @@ -18,9 +18,6 @@ use ethrex_common::{ use ethrex_storage::error::StoreError; use std::collections::HashSet; -// Max number of transactions in the mempool -const MEMPOOL_MAX_SIZE: usize = 10000; //TODO: Define - #[derive(Debug, Default)] pub struct Mempool { broadcast_pool: RwLock>, @@ -28,11 +25,13 @@ pub struct Mempool { blobs_bundle_pool: Mutex>, txs_by_sender_nonce: RwLock>, txs_order: RwLock>, + max_mempool_size: usize, } impl Mempool { - pub fn new() -> Self { + pub fn new(max_mempool_size: usize) -> Self { Mempool { - txs_order: RwLock::new(Vec::with_capacity(MEMPOOL_MAX_SIZE)), + txs_order: RwLock::new(Vec::with_capacity(max_mempool_size)), + max_mempool_size, ..Default::default() } } @@ -66,7 +65,7 @@ impl Mempool { .transaction_pool .write() .map_err(|error| StoreError::MempoolWriteLock(error.to_string()))?; - if transaction_pool.len() >= MEMPOOL_MAX_SIZE { + if transaction_pool.len() >= self.max_mempool_size { self.remove_oldest_transaction(&mut transaction_pool)?; } self.txs_order @@ -532,6 +531,8 @@ mod tests { use ethrex_storage::EngineType; use ethrex_storage::{Store, error::StoreError}; + const MEMPOOL_MAX_SIZE_TEST: usize = 10_000; + async fn setup_storage(config: ChainConfig, header: BlockHeader) -> Result { let store = Store::new("test", EngineType::InMemory)?; let block_number = header.number; @@ -747,7 +748,7 @@ mod tests { let (config, header) = build_basic_config_and_header(false, true); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store); + let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); let tx = EIP1559Transaction { nonce: 3, @@ -774,7 +775,7 @@ mod tests { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store); + let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); let tx = EIP1559Transaction { nonce: 3, @@ -801,7 +802,7 @@ mod tests { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store); + let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); let tx = EIP1559Transaction { nonce: 3, @@ -827,7 +828,7 @@ mod tests { async fn transaction_with_gas_limit_lower_than_intrinsic_gas_should_fail() { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store); + let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); let intrinsic_gas_cost = TX_GAS_COST; let tx = EIP1559Transaction { @@ -854,7 +855,7 @@ mod tests { async fn transaction_with_blob_base_fee_below_min_should_fail() { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store); + let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); let tx = EIP4844Transaction { nonce: 3, @@ -887,7 +888,7 @@ mod tests { let blob_tx = MempoolTransaction::new(blob_tx_decoded, blob_tx_sender); let plain_tx_hash = plain_tx.hash(); let blob_tx_hash = blob_tx.hash(); - let mempool = Mempool::new(); + let mempool = Mempool::new(MEMPOOL_MAX_SIZE_TEST); let filter = |tx: &Transaction| -> bool { matches!(tx, Transaction::EIP4844Transaction(_)) }; mempool @@ -902,7 +903,7 @@ mod tests { fn blobs_bundle_loadtest() { // Write a bundle of 6 blobs 10 times // If this test fails please adjust the max_size in the DB config - let mempool = Mempool::new(); + let mempool = Mempool::new(MEMPOOL_MAX_SIZE_TEST); for i in 0..300 { let blobs = [[i as u8; BYTES_PER_BLOB]; 6]; let commitments = [[i as u8; 48]; 6]; diff --git a/crates/blockchain/smoke_test.rs b/crates/blockchain/smoke_test.rs index 8f8b508cfe..921883cd63 100644 --- a/crates/blockchain/smoke_test.rs +++ b/crates/blockchain/smoke_test.rs @@ -16,6 +16,8 @@ mod blockchain_integration_test { }; use ethrex_storage::{EngineType, Store}; + const MEMPOOL_MAX_SIZE_TEST: usize = 10_000; + #[tokio::test] async fn test_small_to_long_reorg() { // Store and genesis @@ -24,7 +26,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone()); + let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); // Add first block. We'll make it canonical. let block_1a = new_block(&store, &genesis_header).await; @@ -86,7 +88,7 @@ mod blockchain_integration_test { let genesis_header = store.get_block_header(0).unwrap().unwrap(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone()); + let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); // Build a single valid block. let block_1 = new_block(&store, &genesis_header).await; @@ -121,7 +123,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone()); + let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); // Add first block. Not canonical. let block_1a = new_block(&store, &genesis_header).await; @@ -193,7 +195,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone()); + let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); // Add block at height 1. let block_1 = new_block(&store, &genesis_header).await; @@ -246,7 +248,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone()); + let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); // Add block at height 1. let block_1 = new_block(&store, &genesis_header).await; @@ -309,7 +311,8 @@ mod blockchain_integration_test { }; // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone().clone()); + let blockchain = + Blockchain::default_with_store(store.clone().clone(), MEMPOOL_MAX_SIZE_TEST); let block = create_payload(&args, store).unwrap(); let result = blockchain.build_payload(block).await.unwrap(); diff --git a/crates/networking/p2p/sync.rs b/crates/networking/p2p/sync.rs index 1e03858383..ef6f7b539b 100644 --- a/crates/networking/p2p/sync.rs +++ b/crates/networking/p2p/sync.rs @@ -56,6 +56,8 @@ const BYTECODE_CHUNK_SIZE: usize = 50_000; /// that are unlikely to be re-orged. const MISSING_SLOTS_PERCENTAGE: f64 = 0.8; +const DUMMY_MAX_MEMPOOL_SIZE: usize = 10_000; + #[cfg(feature = "sync-test")] lazy_static::lazy_static! { static ref EXECUTE_BATCH_SIZE: usize = std::env::var("EXECUTE_BATCH_SIZE").map(|var| var.parse().expect("Execute batch size environmental variable is not a number")).unwrap_or(EXECUTE_BATCH_SIZE_DEFAULT); @@ -127,6 +129,7 @@ impl Syncer { cancel_token: CancellationToken::new(), blockchain: Arc::new(Blockchain::default_with_store( Store::new("", EngineType::InMemory).expect("Failed to start Store Engine"), + DUMMY_MAX_MEMPOOL_SIZE, )), datadir: ".".into(), } diff --git a/tooling/ef_tests/blockchain/test_runner.rs b/tooling/ef_tests/blockchain/test_runner.rs index 1fbc2753e2..51be51cd33 100644 --- a/tooling/ef_tests/blockchain/test_runner.rs +++ b/tooling/ef_tests/blockchain/test_runner.rs @@ -24,6 +24,8 @@ use ethrex_vm::EvmError; use guest_program::input::ProgramInput; use regex::Regex; +const MAX_MEMPOOL_SIZE_TEST: usize = 10_000; + pub fn parse_and_execute( path: &Path, skipped_tests: Option<&[&str]>, @@ -105,7 +107,12 @@ pub async fn run_ef_test( check_prestate_against_db(test_key, test, &store); // Blockchain EF tests are meant for L1. - let blockchain = Blockchain::new(store.clone(), BlockchainType::L1, false); + let blockchain = Blockchain::new( + store.clone(), + BlockchainType::L1, + false, + MAX_MEMPOOL_SIZE_TEST, + ); // Early return if the exception is in the rlp decoding of the block for bf in &test.blocks { diff --git a/tooling/ef_tests/state_v2/src/modules/block_runner.rs b/tooling/ef_tests/state_v2/src/modules/block_runner.rs index dc63679a52..536f873870 100644 --- a/tooling/ef_tests/state_v2/src/modules/block_runner.rs +++ b/tooling/ef_tests/state_v2/src/modules/block_runner.rs @@ -21,6 +21,8 @@ use crate::modules::{ utils::load_initial_state, }; +const MAX_MEMPOOL_SIZE_TEST: usize = 10_000; + pub async fn run_tests(tests: Vec) -> Result<(), RunnerError> { for test in &tests { println!("Running test group: {}", test.name); @@ -144,7 +146,12 @@ pub async fn run_test(test: &Test, test_case: &TestCase) -> Result<(), RunnerErr // 3. Create Blockchain and add block. - let blockchain = Blockchain::new(store.clone(), BlockchainType::L1, false); + let blockchain = Blockchain::new( + store.clone(), + BlockchainType::L1, + false, + MAX_MEMPOOL_SIZE_TEST, + ); let result = blockchain.add_block(&block).await; From 63f7605036285e487a4bb3d1d18572c9471ef9bd Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Wed, 24 Sep 2025 17:18:17 -0300 Subject: [PATCH 02/11] Fix cli help --- cmd/ethrex/cli.rs | 15 ++++++++------- docs/CLI.md | 5 +++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/ethrex/cli.rs b/cmd/ethrex/cli.rs index 7a5060ddd0..6f12fadc66 100644 --- a/cmd/ethrex/cli.rs +++ b/cmd/ethrex/cli.rs @@ -107,6 +107,14 @@ pub struct Options { long_help = "Possible values: info, debug, trace, warn, error", help_heading = "Node options")] pub log_level: Level, + #[arg( + help = "Maximum size of the mempool in number of transactions", + long = "mempool.maxsize", + default_value_t = 10_000, + value_name = "MEMPOOL_MAX_SIZE", + help_heading = "Node options" + )] + pub mempool_max_size: usize, #[arg( long = "http.addr", default_value = "0.0.0.0", @@ -167,13 +175,6 @@ pub struct Options { help_heading = "P2P options" )] pub discovery_port: String, - #[arg( - help = "Maximum size of the mempool in number of transactions", - long = "mempool.maxsize", - default_value_t = 10_000, - value_name = "MEMPOOL_MAX_SIZE" - )] - pub mempool_max_size: usize, } impl Options { diff --git a/docs/CLI.md b/docs/CLI.md index ea10f9b0d0..e03746f4d7 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -57,6 +57,11 @@ Node options: [default: INFO] + --mempool.maxsize + Maximum size of the mempool in number of transactions + + [default: 10000] + P2P options: --bootnodes ... Comma separated enode URLs for P2P discovery bootstrap. From 16a42e8af25e23ec459609bdf1a88e74bba8f936 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Wed, 24 Sep 2025 17:23:05 -0300 Subject: [PATCH 03/11] Remove unnecessary max mempool constant --- cmd/ethrex_replay/src/cli.rs | 4 ++-- crates/blockchain/blockchain.rs | 5 +++-- crates/blockchain/mempool.rs | 8 ++++---- crates/blockchain/smoke_test.rs | 13 ++++++------- crates/networking/p2p/sync.rs | 3 --- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cmd/ethrex_replay/src/cli.rs b/cmd/ethrex_replay/src/cli.rs index 55dd07c4ea..d127c7564e 100644 --- a/cmd/ethrex_replay/src/cli.rs +++ b/cmd/ethrex_replay/src/cli.rs @@ -63,7 +63,7 @@ pub const BACKEND: Backend = Backend::RISC0; #[cfg(not(any(feature = "sp1", feature = "risc0")))] pub const BACKEND: Backend = Backend::Exec; -const MAX_MEMPOOL_SIZE: usize = 10_000; +const MAX_MEMPOOL_SIZE: usize = 100_000; #[derive(Parser)] #[command(name="ethrex-replay", author, version=VERSION_STRING, about, long_about = None)] @@ -573,7 +573,7 @@ async fn replay_no_zkvm(cache: Cache, opts: &EthrexReplayOptions) -> eyre::Resul store.add_block_header(header.hash(), header).await?; } - let blockchain = Blockchain::default_with_store(store, MAX_MEMPOOL_SIZE); + let blockchain = Blockchain::default_with_store(store); info!("Storage preparation finished in {:.2?}", start.elapsed()); diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index c71702d424..be6ed2396c 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -48,6 +48,7 @@ use ethrex_metrics::metrics_blocks::METRICS_BLOCKS; use ethrex_common::types::BlobsBundle; const MAX_PAYLOADS: usize = 10; +const MAX_MEMPOOL_SIZE_DEFAULT: usize = 10_000; //TODO: Implement a struct Chain or BlockChain to encapsulate //functionality and canonical chain state and config @@ -110,10 +111,10 @@ impl Blockchain { } } - pub fn default_with_store(store: Store, max_mempool_size: usize) -> Self { + pub fn default_with_store(store: Store) -> Self { Self { storage: store, - mempool: Mempool::new(max_mempool_size), + mempool: Mempool::new(MAX_MEMPOOL_SIZE_DEFAULT), is_synced: AtomicBool::new(false), r#type: BlockchainType::default(), payloads: Arc::new(TokioMutex::new(Vec::new())), diff --git a/crates/blockchain/mempool.rs b/crates/blockchain/mempool.rs index 7ee3bf07d2..9f1a560dee 100644 --- a/crates/blockchain/mempool.rs +++ b/crates/blockchain/mempool.rs @@ -748,7 +748,7 @@ mod tests { let (config, header) = build_basic_config_and_header(false, true); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store); let tx = EIP1559Transaction { nonce: 3, @@ -802,7 +802,7 @@ mod tests { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store); let tx = EIP1559Transaction { nonce: 3, @@ -828,7 +828,7 @@ mod tests { async fn transaction_with_gas_limit_lower_than_intrinsic_gas_should_fail() { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store); let intrinsic_gas_cost = TX_GAS_COST; let tx = EIP1559Transaction { @@ -855,7 +855,7 @@ mod tests { async fn transaction_with_blob_base_fee_below_min_should_fail() { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store); let tx = EIP4844Transaction { nonce: 3, diff --git a/crates/blockchain/smoke_test.rs b/crates/blockchain/smoke_test.rs index 921883cd63..93858d8c12 100644 --- a/crates/blockchain/smoke_test.rs +++ b/crates/blockchain/smoke_test.rs @@ -26,7 +26,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store.clone()); // Add first block. We'll make it canonical. let block_1a = new_block(&store, &genesis_header).await; @@ -88,7 +88,7 @@ mod blockchain_integration_test { let genesis_header = store.get_block_header(0).unwrap().unwrap(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store.clone()); // Build a single valid block. let block_1 = new_block(&store, &genesis_header).await; @@ -123,7 +123,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store.clone()); // Add first block. Not canonical. let block_1a = new_block(&store, &genesis_header).await; @@ -195,7 +195,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store.clone()); // Add block at height 1. let block_1 = new_block(&store, &genesis_header).await; @@ -248,7 +248,7 @@ mod blockchain_integration_test { let genesis_hash = genesis_header.hash(); // Create blockchain - let blockchain = Blockchain::default_with_store(store.clone(), MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store.clone()); // Add block at height 1. let block_1 = new_block(&store, &genesis_header).await; @@ -311,8 +311,7 @@ mod blockchain_integration_test { }; // Create blockchain - let blockchain = - Blockchain::default_with_store(store.clone().clone(), MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store.clone().clone()); let block = create_payload(&args, store).unwrap(); let result = blockchain.build_payload(block).await.unwrap(); diff --git a/crates/networking/p2p/sync.rs b/crates/networking/p2p/sync.rs index ef6f7b539b..1e03858383 100644 --- a/crates/networking/p2p/sync.rs +++ b/crates/networking/p2p/sync.rs @@ -56,8 +56,6 @@ const BYTECODE_CHUNK_SIZE: usize = 50_000; /// that are unlikely to be re-orged. const MISSING_SLOTS_PERCENTAGE: f64 = 0.8; -const DUMMY_MAX_MEMPOOL_SIZE: usize = 10_000; - #[cfg(feature = "sync-test")] lazy_static::lazy_static! { static ref EXECUTE_BATCH_SIZE: usize = std::env::var("EXECUTE_BATCH_SIZE").map(|var| var.parse().expect("Execute batch size environmental variable is not a number")).unwrap_or(EXECUTE_BATCH_SIZE_DEFAULT); @@ -129,7 +127,6 @@ impl Syncer { cancel_token: CancellationToken::new(), blockchain: Arc::new(Blockchain::default_with_store( Store::new("", EngineType::InMemory).expect("Failed to start Store Engine"), - DUMMY_MAX_MEMPOOL_SIZE, )), datadir: ".".into(), } From fa65b1a030ec2eb22ad2597dba2b75c47abd51f8 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Wed, 24 Sep 2025 17:23:35 -0300 Subject: [PATCH 04/11] Remove constant --- crates/blockchain/mempool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/blockchain/mempool.rs b/crates/blockchain/mempool.rs index 9f1a560dee..7b05b1df23 100644 --- a/crates/blockchain/mempool.rs +++ b/crates/blockchain/mempool.rs @@ -775,7 +775,7 @@ mod tests { let (config, header) = build_basic_config_and_header(false, false); let store = setup_storage(config, header).await.expect("Storage setup"); - let blockchain = Blockchain::default_with_store(store, MEMPOOL_MAX_SIZE_TEST); + let blockchain = Blockchain::default_with_store(store); let tx = EIP1559Transaction { nonce: 3, From a8788b77bfc88691a0ff0425452703a8b76749a8 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Wed, 24 Sep 2025 17:29:37 -0300 Subject: [PATCH 05/11] Add blockchain options --- cmd/ethrex/cli.rs | 10 ++++++---- cmd/ethrex/initializers.rs | 10 ++++++---- cmd/ethrex/l2/initializers.rs | 4 +++- cmd/ethrex_replay/src/cli.rs | 4 +--- crates/blockchain/blockchain.rs | 17 +++++++++++++++-- tooling/ef_tests/blockchain/test_runner.rs | 6 ++---- .../state_v2/src/modules/block_runner.rs | 4 +--- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/cmd/ethrex/cli.rs b/cmd/ethrex/cli.rs index 6f12fadc66..360949ac18 100644 --- a/cmd/ethrex/cli.rs +++ b/cmd/ethrex/cli.rs @@ -6,7 +6,7 @@ use std::{ }; use clap::{ArgAction, Parser as ClapParser, Subcommand as ClapSubcommand}; -use ethrex_blockchain::{BlockchainType, error::ChainError}; +use ethrex_blockchain::{BlockchainOptions, BlockchainType, error::ChainError}; use ethrex_common::types::{Block, Genesis}; use ethrex_p2p::sync::SyncMode; use ethrex_p2p::types::Node; @@ -336,7 +336,9 @@ impl Subcommand { &opts.datadir, genesis, blockchain_type, - opts.mempool_max_size, + BlockchainOptions { + max_mempool_size: opts.mempool_max_size, + }, ) .await?; } @@ -386,12 +388,12 @@ pub async fn import_blocks( datadir: &Path, genesis: Genesis, blockchain_type: BlockchainType, - max_mempool_size: usize, + blockchain_opts: BlockchainOptions, ) -> Result<(), ChainError> { let start_time = Instant::now(); init_datadir(datadir); let store = init_store(datadir, genesis).await; - let blockchain = init_blockchain(store.clone(), blockchain_type, false, max_mempool_size); + let blockchain = init_blockchain(store.clone(), blockchain_type, false, blockchain_opts); let path_metadata = metadata(path).expect("Failed to read path"); // If it's an .rlp file it will be just one chain, but if it's a directory there can be multiple chains. diff --git a/cmd/ethrex/initializers.rs b/cmd/ethrex/initializers.rs index bd9f92dc3a..926e7eb658 100644 --- a/cmd/ethrex/initializers.rs +++ b/cmd/ethrex/initializers.rs @@ -5,7 +5,7 @@ use crate::{ read_jwtsecret_file, read_node_config_file, }, }; -use ethrex_blockchain::{Blockchain, BlockchainType}; +use ethrex_blockchain::{Blockchain, BlockchainOptions, BlockchainType}; use ethrex_common::types::Genesis; use ethrex_config::networks::Network; @@ -118,13 +118,13 @@ pub fn init_blockchain( store: Store, blockchain_type: BlockchainType, perf_logs_enabled: bool, - max_mempool_size: usize, + blockchain_opts: BlockchainOptions, ) -> Arc { #[cfg(feature = "revm")] info!("Initiating blockchain with revm"); #[cfg(not(feature = "revm"))] info!("Initiating blockchain with levm"); - Blockchain::new(store, blockchain_type, perf_logs_enabled, max_mempool_size).into() + Blockchain::new(store, blockchain_type, perf_logs_enabled, blockchain_opts).into() } #[allow(clippy::too_many_arguments)] @@ -393,7 +393,9 @@ pub async fn init_l1( store.clone(), BlockchainType::L1, true, - opts.mempool_max_size, + BlockchainOptions { + max_mempool_size: opts.mempool_max_size, + }, ); let signer = get_signer(datadir); diff --git a/cmd/ethrex/l2/initializers.rs b/cmd/ethrex/l2/initializers.rs index 43ec33b468..229bf8801b 100644 --- a/cmd/ethrex/l2/initializers.rs +++ b/cmd/ethrex/l2/initializers.rs @@ -174,7 +174,9 @@ pub async fn init_l2( store.clone(), BlockchainType::L2, true, - opts.node_opts.mempool_max_size, + ethrex_blockchain::BlockchainOptions { + max_mempool_size: opts.node_opts.mempool_max_size, + }, ); let signer = get_signer(&datadir); diff --git a/cmd/ethrex_replay/src/cli.rs b/cmd/ethrex_replay/src/cli.rs index d127c7564e..9744c48c40 100644 --- a/cmd/ethrex_replay/src/cli.rs +++ b/cmd/ethrex_replay/src/cli.rs @@ -63,8 +63,6 @@ pub const BACKEND: Backend = Backend::RISC0; #[cfg(not(any(feature = "sp1", feature = "risc0")))] pub const BACKEND: Backend = Backend::Exec; -const MAX_MEMPOOL_SIZE: usize = 100_000; - #[derive(Parser)] #[command(name="ethrex-replay", author, version=VERSION_STRING, about, long_about = None)] pub struct EthrexReplayCLI { @@ -834,7 +832,7 @@ pub async fn replay_custom_l1_blocks( store.clone(), BlockchainType::L1, false, - MAX_MEMPOOL_SIZE, + ethrex_blockchain::BlockchainOptions::default(), )); let blocks = produce_l1_blocks( diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index be6ed2396c..dfe247870d 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -76,6 +76,19 @@ pub struct Blockchain { pub payloads: Arc>>, } +#[derive(Debug, Clone)] +pub struct BlockchainOptions { + pub max_mempool_size: usize, +} + +impl Default for BlockchainOptions { + fn default() -> Self { + Self { + max_mempool_size: MAX_MEMPOOL_SIZE_DEFAULT, + } + } +} + #[derive(Debug, Clone)] pub struct BatchBlockProcessingFailure { pub last_valid_hash: H256, @@ -99,11 +112,11 @@ impl Blockchain { store: Store, blockchain_type: BlockchainType, perf_logs_enabled: bool, - max_mempool_size: usize, + blockchain_opts: BlockchainOptions, ) -> Self { Self { storage: store, - mempool: Mempool::new(max_mempool_size), + mempool: Mempool::new(blockchain_opts.max_mempool_size), is_synced: AtomicBool::new(false), r#type: blockchain_type, payloads: Arc::new(TokioMutex::new(Vec::new())), diff --git a/tooling/ef_tests/blockchain/test_runner.rs b/tooling/ef_tests/blockchain/test_runner.rs index 51be51cd33..a367cb16de 100644 --- a/tooling/ef_tests/blockchain/test_runner.rs +++ b/tooling/ef_tests/blockchain/test_runner.rs @@ -6,7 +6,7 @@ use crate::{ types::{BlockChainExpectedException, BlockExpectedException, BlockWithRLP, TestUnit}, }; use ethrex_blockchain::{ - Blockchain, BlockchainType, + Blockchain, BlockchainOptions, BlockchainType, error::{ChainError, InvalidBlockError}, fork_choice::apply_fork_choice, }; @@ -24,8 +24,6 @@ use ethrex_vm::EvmError; use guest_program::input::ProgramInput; use regex::Regex; -const MAX_MEMPOOL_SIZE_TEST: usize = 10_000; - pub fn parse_and_execute( path: &Path, skipped_tests: Option<&[&str]>, @@ -111,7 +109,7 @@ pub async fn run_ef_test( store.clone(), BlockchainType::L1, false, - MAX_MEMPOOL_SIZE_TEST, + BlockchainOptions::default(), ); // Early return if the exception is in the rlp decoding of the block diff --git a/tooling/ef_tests/state_v2/src/modules/block_runner.rs b/tooling/ef_tests/state_v2/src/modules/block_runner.rs index 536f873870..cfbc350816 100644 --- a/tooling/ef_tests/state_v2/src/modules/block_runner.rs +++ b/tooling/ef_tests/state_v2/src/modules/block_runner.rs @@ -21,8 +21,6 @@ use crate::modules::{ utils::load_initial_state, }; -const MAX_MEMPOOL_SIZE_TEST: usize = 10_000; - pub async fn run_tests(tests: Vec) -> Result<(), RunnerError> { for test in &tests { println!("Running test group: {}", test.name); @@ -150,7 +148,7 @@ pub async fn run_test(test: &Test, test_case: &TestCase) -> Result<(), RunnerErr store.clone(), BlockchainType::L1, false, - MAX_MEMPOOL_SIZE_TEST, + ethrex_blockchain::BlockchainOptions::default(), ); let result = blockchain.add_block(&block).await; From 3636b0b74642305fb21182601e0c2057de9bac03 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Thu, 25 Sep 2025 13:56:25 -0300 Subject: [PATCH 06/11] Add extra arguments to blockchain options --- cmd/ethrex/cli.rs | 6 ++-- cmd/ethrex/initializers.rs | 13 +++----- cmd/ethrex/l2/initializers.rs | 4 +-- cmd/ethrex_replay/src/cli.rs | 4 +-- crates/blockchain/blockchain.rs | 30 ++++++++----------- crates/blockchain/payload.rs | 5 ++-- .../block_producer/payload_builder.rs | 2 +- tooling/ef_tests/blockchain/test_runner.rs | 9 ++---- .../state_v2/src/modules/block_runner.rs | 4 +-- 9 files changed, 30 insertions(+), 47 deletions(-) diff --git a/cmd/ethrex/cli.rs b/cmd/ethrex/cli.rs index 360949ac18..304d0c662d 100644 --- a/cmd/ethrex/cli.rs +++ b/cmd/ethrex/cli.rs @@ -335,9 +335,10 @@ impl Subcommand { &path, &opts.datadir, genesis, - blockchain_type, BlockchainOptions { max_mempool_size: opts.mempool_max_size, + r#type: blockchain_type, + ..Default::default() }, ) .await?; @@ -387,13 +388,12 @@ pub async fn import_blocks( path: &str, datadir: &Path, genesis: Genesis, - blockchain_type: BlockchainType, blockchain_opts: BlockchainOptions, ) -> Result<(), ChainError> { let start_time = Instant::now(); init_datadir(datadir); let store = init_store(datadir, genesis).await; - let blockchain = init_blockchain(store.clone(), blockchain_type, false, blockchain_opts); + let blockchain = init_blockchain(store.clone(), blockchain_opts); let path_metadata = metadata(path).expect("Failed to read path"); // If it's an .rlp file it will be just one chain, but if it's a directory there can be multiple chains. diff --git a/cmd/ethrex/initializers.rs b/cmd/ethrex/initializers.rs index 926e7eb658..78a16e8bbf 100644 --- a/cmd/ethrex/initializers.rs +++ b/cmd/ethrex/initializers.rs @@ -114,17 +114,12 @@ pub fn open_store(datadir: &Path) -> Store { } } -pub fn init_blockchain( - store: Store, - blockchain_type: BlockchainType, - perf_logs_enabled: bool, - blockchain_opts: BlockchainOptions, -) -> Arc { +pub fn init_blockchain(store: Store, blockchain_opts: BlockchainOptions) -> Arc { #[cfg(feature = "revm")] info!("Initiating blockchain with revm"); #[cfg(not(feature = "revm"))] info!("Initiating blockchain with levm"); - Blockchain::new(store, blockchain_type, perf_logs_enabled, blockchain_opts).into() + Blockchain::new(store, blockchain_opts).into() } #[allow(clippy::too_many_arguments)] @@ -391,10 +386,10 @@ pub async fn init_l1( let blockchain = init_blockchain( store.clone(), - BlockchainType::L1, - true, BlockchainOptions { max_mempool_size: opts.mempool_max_size, + perf_logs_enabled: true, + r#type: BlockchainType::L1, }, ); diff --git a/cmd/ethrex/l2/initializers.rs b/cmd/ethrex/l2/initializers.rs index 229bf8801b..9263ec5abb 100644 --- a/cmd/ethrex/l2/initializers.rs +++ b/cmd/ethrex/l2/initializers.rs @@ -172,10 +172,10 @@ pub async fn init_l2( let blockchain = init_blockchain( store.clone(), - BlockchainType::L2, - true, ethrex_blockchain::BlockchainOptions { max_mempool_size: opts.node_opts.mempool_max_size, + r#type: BlockchainType::L2, + perf_logs_enabled: true, }, ); diff --git a/cmd/ethrex_replay/src/cli.rs b/cmd/ethrex_replay/src/cli.rs index 9744c48c40..6cd961ad5e 100644 --- a/cmd/ethrex_replay/src/cli.rs +++ b/cmd/ethrex_replay/src/cli.rs @@ -1,6 +1,6 @@ use clap::{ArgGroup, Parser, Subcommand, ValueEnum}; use ethrex_blockchain::{ - Blockchain, BlockchainType, + Blockchain, fork_choice::apply_fork_choice, payload::{BuildPayloadArgs, PayloadBuildResult, create_payload}, }; @@ -830,8 +830,6 @@ pub async fn replay_custom_l1_blocks( let blockchain = Arc::new(Blockchain::new( store.clone(), - BlockchainType::L1, - false, ethrex_blockchain::BlockchainOptions::default(), )); diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index dfe247870d..5782369849 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -68,9 +68,7 @@ pub struct Blockchain { /// This will be set to true once the initial sync has taken place and wont be set to false after /// This does not reflect whether there is an ongoing sync process is_synced: AtomicBool, - /// Whether performance logs should be emitted - pub perf_logs_enabled: bool, - pub r#type: BlockchainType, + pub options: BlockchainOptions, /// Mapping from a payload id to either a complete payload or a payload build task /// We need to keep completed payloads around in case consensus requests them twice pub payloads: Arc>>, @@ -79,12 +77,17 @@ pub struct Blockchain { #[derive(Debug, Clone)] pub struct BlockchainOptions { pub max_mempool_size: usize, + /// Whether performance logs should be emitted + pub perf_logs_enabled: bool, + pub r#type: BlockchainType, } impl Default for BlockchainOptions { fn default() -> Self { Self { max_mempool_size: MAX_MEMPOOL_SIZE_DEFAULT, + perf_logs_enabled: false, + r#type: BlockchainType::default(), } } } @@ -108,19 +111,13 @@ fn log_batch_progress(batch_size: u32, current_block: u32) { } impl Blockchain { - pub fn new( - store: Store, - blockchain_type: BlockchainType, - perf_logs_enabled: bool, - blockchain_opts: BlockchainOptions, - ) -> Self { + pub fn new(store: Store, blockchain_opts: BlockchainOptions) -> Self { Self { storage: store, mempool: Mempool::new(blockchain_opts.max_mempool_size), is_synced: AtomicBool::new(false), - r#type: blockchain_type, payloads: Arc::new(TokioMutex::new(Vec::new())), - perf_logs_enabled, + options: blockchain_opts, } } @@ -129,9 +126,8 @@ impl Blockchain { storage: store, mempool: Mempool::new(MAX_MEMPOOL_SIZE_DEFAULT), is_synced: AtomicBool::new(false), - r#type: BlockchainType::default(), payloads: Arc::new(TokioMutex::new(Vec::new())), - perf_logs_enabled: false, + options: BlockchainOptions::default(), } } @@ -223,7 +219,7 @@ impl Blockchain { let vm_db: DynVmDatabase = Box::new(StoreVmDatabase::new(self.storage.clone(), parent_hash)); let logger = Arc::new(DatabaseLogger::new(Arc::new(Mutex::new(Box::new(vm_db))))); - let mut vm = match self.r#type { + let mut vm = match self.options.r#type { BlockchainType::L1 => Evm::new_from_db_for_l1(logger.clone()), BlockchainType::L2 => Evm::new_from_db_for_l2(logger.clone()), }; @@ -441,7 +437,7 @@ impl Blockchain { let result = self.store_block(block, account_updates_list, res).await; let stored = Instant::now(); - if self.perf_logs_enabled { + if self.options.perf_logs_enabled { Self::print_add_block_logs(block, since, executed, merkleized, stored); } result @@ -632,7 +628,7 @@ impl Blockchain { METRICS_BLOCKS.set_latest_gigagas(throughput); ); - if self.perf_logs_enabled { + if self.options.perf_logs_enabled { info!( "[METRICS] Executed and stored: Range: {}, Last block num: {}, Last block gas limit: {}, Total transactions: {}, Total Gas: {}, Throughput: {} Gigagas/s", blocks_len, @@ -902,7 +898,7 @@ impl Blockchain { } pub fn new_evm(&self, vm_db: StoreVmDatabase) -> Result { - let evm = match self.r#type { + let evm = match self.options.r#type { BlockchainType::L1 => Evm::new_for_l1(vm_db), BlockchainType::L2 => Evm::new_for_l2(vm_db)?, }; diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 44abde2cf6..f53c72ca03 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -386,9 +386,10 @@ impl Blockchain { debug!("Building payload"); let base_fee = payload.header.base_fee_per_gas.unwrap_or_default(); - let mut context = PayloadBuildContext::new(payload, &self.storage, self.r#type.clone())?; + let mut context = + PayloadBuildContext::new(payload, &self.storage, self.options.r#type.clone())?; - if let BlockchainType::L1 = self.r#type { + if let BlockchainType::L1 = self.options.r#type { self.apply_system_operations(&mut context)?; } self.apply_withdrawals(&mut context)?; diff --git a/crates/l2/sequencer/block_producer/payload_builder.rs b/crates/l2/sequencer/block_producer/payload_builder.rs index 984fcbfc09..8d1340b937 100644 --- a/crates/l2/sequencer/block_producer/payload_builder.rs +++ b/crates/l2/sequencer/block_producer/payload_builder.rs @@ -45,7 +45,7 @@ pub async fn build_payload( let gas_limit = payload.header.gas_limit; debug!("Building payload"); - let mut context = PayloadBuildContext::new(payload, store, blockchain.r#type.clone())?; + let mut context = PayloadBuildContext::new(payload, store, blockchain.options.r#type.clone())?; fill_transactions( blockchain.clone(), diff --git a/tooling/ef_tests/blockchain/test_runner.rs b/tooling/ef_tests/blockchain/test_runner.rs index a367cb16de..301b01d423 100644 --- a/tooling/ef_tests/blockchain/test_runner.rs +++ b/tooling/ef_tests/blockchain/test_runner.rs @@ -6,7 +6,7 @@ use crate::{ types::{BlockChainExpectedException, BlockExpectedException, BlockWithRLP, TestUnit}, }; use ethrex_blockchain::{ - Blockchain, BlockchainOptions, BlockchainType, + Blockchain, BlockchainOptions, error::{ChainError, InvalidBlockError}, fork_choice::apply_fork_choice, }; @@ -105,12 +105,7 @@ pub async fn run_ef_test( check_prestate_against_db(test_key, test, &store); // Blockchain EF tests are meant for L1. - let blockchain = Blockchain::new( - store.clone(), - BlockchainType::L1, - false, - BlockchainOptions::default(), - ); + let blockchain = Blockchain::new(store.clone(), BlockchainOptions::default()); // Early return if the exception is in the rlp decoding of the block for bf in &test.blocks { diff --git a/tooling/ef_tests/state_v2/src/modules/block_runner.rs b/tooling/ef_tests/state_v2/src/modules/block_runner.rs index cfbc350816..ed579f332f 100644 --- a/tooling/ef_tests/state_v2/src/modules/block_runner.rs +++ b/tooling/ef_tests/state_v2/src/modules/block_runner.rs @@ -1,6 +1,6 @@ use bytes::Bytes; +use ethrex_blockchain::Blockchain; use ethrex_blockchain::get_total_blob_gas; -use ethrex_blockchain::{Blockchain, BlockchainType}; use ethrex_common::constants::DEFAULT_REQUESTS_HASH; use ethrex_common::types::{ Block, BlockBody, BlockHeader, Fork, Receipt, Transaction, compute_receipts_root, @@ -146,8 +146,6 @@ pub async fn run_test(test: &Test, test_case: &TestCase) -> Result<(), RunnerErr let blockchain = Blockchain::new( store.clone(), - BlockchainType::L1, - false, ethrex_blockchain::BlockchainOptions::default(), ); From e448f7b936fca56311877c2a8fdd99c97fd524bd Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Thu, 25 Sep 2025 13:57:21 -0300 Subject: [PATCH 07/11] Move to a var --- cmd/ethrex/l2/initializers.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/ethrex/l2/initializers.rs b/cmd/ethrex/l2/initializers.rs index 9263ec5abb..8d256352bd 100644 --- a/cmd/ethrex/l2/initializers.rs +++ b/cmd/ethrex/l2/initializers.rs @@ -170,14 +170,13 @@ pub async fn init_l2( let store = init_store(&datadir, genesis).await; let rollup_store = init_rollup_store(&rollup_store_dir).await; - let blockchain = init_blockchain( - store.clone(), - ethrex_blockchain::BlockchainOptions { - max_mempool_size: opts.node_opts.mempool_max_size, - r#type: BlockchainType::L2, - perf_logs_enabled: true, - }, - ); + let blockchain_opts = ethrex_blockchain::BlockchainOptions { + max_mempool_size: opts.node_opts.mempool_max_size, + r#type: BlockchainType::L2, + perf_logs_enabled: true, + }; + + let blockchain = init_blockchain(store.clone(), blockchain_opts); let signer = get_signer(&datadir); From c7ba92a589034f61cc92d5198d999df10dcfd889 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:26:01 -0300 Subject: [PATCH 08/11] Add capacity to pools --- crates/blockchain/mempool.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/blockchain/mempool.rs b/crates/blockchain/mempool.rs index 7b05b1df23..3dc8bf55a0 100644 --- a/crates/blockchain/mempool.rs +++ b/crates/blockchain/mempool.rs @@ -31,6 +31,8 @@ impl Mempool { pub fn new(max_mempool_size: usize) -> Self { Mempool { txs_order: RwLock::new(Vec::with_capacity(max_mempool_size)), + transaction_pool: RwLock::new(HashMap::with_capacity(max_mempool_size)), + blobs_bundle_pool: Mutex::new(HashMap::with_capacity(max_mempool_size)), max_mempool_size, ..Default::default() } From 24f1cde126c9fc71619431aa231a77a3d2d95e7e Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Thu, 25 Sep 2025 17:37:35 -0300 Subject: [PATCH 09/11] Remove capacity for blobs --- crates/blockchain/mempool.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/blockchain/mempool.rs b/crates/blockchain/mempool.rs index 3dc8bf55a0..30114daf2e 100644 --- a/crates/blockchain/mempool.rs +++ b/crates/blockchain/mempool.rs @@ -32,7 +32,6 @@ impl Mempool { Mempool { txs_order: RwLock::new(Vec::with_capacity(max_mempool_size)), transaction_pool: RwLock::new(HashMap::with_capacity(max_mempool_size)), - blobs_bundle_pool: Mutex::new(HashMap::with_capacity(max_mempool_size)), max_mempool_size, ..Default::default() } From acbd323b0fc775d514decc4dfea2477b4fbbe652 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Fri, 26 Sep 2025 18:31:45 -0300 Subject: [PATCH 10/11] Remove unused const --- crates/blockchain/smoke_test.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/blockchain/smoke_test.rs b/crates/blockchain/smoke_test.rs index 93858d8c12..8f8b508cfe 100644 --- a/crates/blockchain/smoke_test.rs +++ b/crates/blockchain/smoke_test.rs @@ -16,8 +16,6 @@ mod blockchain_integration_test { }; use ethrex_storage::{EngineType, Store}; - const MEMPOOL_MAX_SIZE_TEST: usize = 10_000; - #[tokio::test] async fn test_small_to_long_reorg() { // Store and genesis From 0013d0b5094f245477c6a303db113eb2f50b646d Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Fri, 26 Sep 2025 18:55:49 -0300 Subject: [PATCH 11/11] Fix l2 clippy --- cmd/ethrex/bench/build_block_benchmark.rs | 9 ++++++--- cmd/ethrex/bench/import_blocks_benchmark.rs | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/ethrex/bench/build_block_benchmark.rs b/cmd/ethrex/bench/build_block_benchmark.rs index ffcb72241b..7089bd471c 100644 --- a/cmd/ethrex/bench/build_block_benchmark.rs +++ b/cmd/ethrex/bench/build_block_benchmark.rs @@ -11,7 +11,7 @@ use criterion::{ measurement::{Measurement, ValueFormatter}, }; use ethrex_blockchain::{ - Blockchain, BlockchainType, + Blockchain, BlockchainOptions, BlockchainType, payload::{BuildPayloadArgs, PayloadBuildResult, create_payload}, }; use ethrex_common::{ @@ -236,8 +236,11 @@ pub fn build_block_benchmark(c: &mut Criterion) { let (store_with_genesis, genesis) = setup_genesis(&addresses).await; let block_chain = Blockchain::new( store_with_genesis.clone(), - BlockchainType::L1, // TODO: Should we support L2? - false, + BlockchainOptions { + r#type: BlockchainType::L1, // TODO: Should we support L2? + perf_logs_enabled: false, + ..Default::default() + }, ); fill_mempool(&block_chain, accounts).await; diff --git a/cmd/ethrex/bench/import_blocks_benchmark.rs b/cmd/ethrex/bench/import_blocks_benchmark.rs index 81c7f4e2a2..22451ae5f9 100644 --- a/cmd/ethrex/bench/import_blocks_benchmark.rs +++ b/cmd/ethrex/bench/import_blocks_benchmark.rs @@ -3,7 +3,7 @@ use ethrex::{ cli::{import_blocks, remove_db}, utils::{default_datadir, init_datadir}, }; -use ethrex_blockchain::BlockchainType; +use ethrex_blockchain::{BlockchainOptions, BlockchainType}; use ethrex_config::networks::Network; #[inline] @@ -23,7 +23,10 @@ fn block_import() { "../../fixtures/blockchain/l2-1k-erc20.rlp", &datadir, genesis, - blockchain_type, + BlockchainOptions { + r#type: blockchain_type, + ..Default::default() + }, )) .expect("Failed to import blocks on the Tokio runtime"); }