diff --git a/cmd/ethrex_l2/src/commands/test.rs b/cmd/ethrex_l2/src/commands/test.rs index 4912e28d671..429d037e962 100644 --- a/cmd/ethrex_l2/src/commands/test.rs +++ b/cmd/ethrex_l2/src/commands/test.rs @@ -7,6 +7,7 @@ use ethrex_l2_sdk::calldata::{self, Value}; use ethrex_rpc::clients::eth::{eth_sender::Overrides, EthClient}; use keccak_hash::keccak; use secp256k1::SecretKey; +use std::time::Instant; use std::{ fs::File, io::{self, BufRead}, @@ -206,6 +207,7 @@ impl Command { println!("Sending to: {to_address:#x}"); + let now = Instant::now(); let mut threads = vec![]; for pk in lines.map_while(Result::ok) { let thread = tokio::spawn(transfer_from( @@ -226,6 +228,8 @@ impl Command { } println!("Total retries: {retries}"); + println!("Total time elapsed: {:.2?}", now.elapsed()); + Ok(()) } } diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index eb11447dd37..7decd11641e 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -5,6 +5,9 @@ pub mod mempool; pub mod payload; mod smoke_test; +use std::{ops::Div, time::Instant}; +use tracing::info; + use error::{ChainError, InvalidBlockError}; use ethrex_common::constants::GAS_PER_BLOB; use ethrex_common::types::requests::{compute_requests_hash, EncodedRequests, Requests}; @@ -29,6 +32,8 @@ use ethrex_vm::{backends::BlockExecutionResult, get_evm_backend_or_default}; /// /// Performs pre and post execution validation, and updates the database with the post state. pub fn add_block(block: &Block, storage: &Store) -> Result<(), ChainError> { + let since = Instant::now(); + let block_hash = block.header.compute_block_hash(); // Validate if it can be the new head and find the parent @@ -69,6 +74,13 @@ pub fn add_block(block: &Block, storage: &Store) -> Result<(), ChainError> { store_block(storage, block.clone())?; store_receipts(storage, receipts, block_hash)?; + let interval = Instant::now().duration_since(since).as_millis(); + if interval != 0 { + let as_gigas = (block.header.gas_used as f64).div(10_f64.powf(9_f64)); + let throughput = (as_gigas) / (interval as f64) * 1000_f64; + info!("[METRIC] BLOCK EXECUTION THROUGHPUT: {throughput} Gigagas/s TIME SPENT: {interval} msecs"); + } + Ok(()) } diff --git a/crates/blockchain/payload.rs b/crates/blockchain/payload.rs index 97c21d62027..78e12154666 100644 --- a/crates/blockchain/payload.rs +++ b/crates/blockchain/payload.rs @@ -1,6 +1,8 @@ use std::{ cmp::{max, Ordering}, collections::HashMap, + ops::Div, + time::Instant, }; use ethrex_common::{ @@ -238,14 +240,31 @@ pub fn build_payload( payload: &mut Block, store: &Store, ) -> Result<(BlobsBundle, U256), ChainError> { + let since = Instant::now(); + let gas_limit = payload.header.gas_limit; debug!("Building payload"); let mut evm_state = evm_state(store.clone(), payload.header.parent_hash); let mut context = PayloadBuildContext::new(payload, &mut evm_state)?; + apply_system_operations(&mut context)?; apply_withdrawals(&mut context)?; fill_transactions(&mut context)?; extract_requests(&mut context)?; finalize_payload(&mut context)?; + + let interval = Instant::now().duration_since(since).as_millis(); + tracing::info!("[METRIC] BUILDING PAYLOAD TOOK: {interval} ms"); + if let Some(gas_used) = gas_limit.checked_sub(context.remaining_gas) { + let as_gigas = (gas_used as f64).div(10_f64.powf(9_f64)); + + if interval != 0 { + let throughput = (as_gigas) / (interval as f64) * 1000_f64; + tracing::info!( + "[METRIC] BLOCK BUILDING THROUGHPUT: {throughput} Gigagas/s TIME SPENT: {interval} msecs" + ); + } + } + Ok((context.blobs_bundle, context.block_value)) }