Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions cmd/ethrex_l2/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(
Expand All @@ -226,6 +228,8 @@ impl Command {
}

println!("Total retries: {retries}");
println!("Total time elapsed: {:.2?}", now.elapsed());

Ok(())
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand Down Expand Up @@ -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(())
}

Expand Down
19 changes: 19 additions & 0 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{
cmp::{max, Ordering},
collections::HashMap,
ops::Div,
time::Instant,
};

use ethrex_common::{
Expand Down Expand Up @@ -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))
}

Expand Down
Loading