Skip to content

Commit 18680ad

Browse files
fkrause98Oppenjrchatruc
committed
feat(l1,l2): add log messages for block building and execution throughput (#1996)
**Motivation** <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #issue_number --------- Co-authored-by: Mario Rugiero <[email protected]> Co-authored-by: Javier Chatruc <[email protected]>
1 parent fbc1fea commit 18680ad

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

cmd/ethrex_l2/src/commands/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use ethrex_rpc::{
1212
use itertools::Itertools;
1313
use keccak_hash::keccak;
1414
use secp256k1::{PublicKey, SecretKey};
15+
use std::time::Instant;
1516
use std::{
1617
fs::File,
1718
io::{self, BufRead},
@@ -390,6 +391,7 @@ impl Command {
390391

391392
println!("Sending to: {to_address:#x}");
392393

394+
let now = Instant::now();
393395
let mut threads = vec![];
394396
for pk in lines.map_while(Result::ok) {
395397
let thread = tokio::spawn(transfer_from(
@@ -410,6 +412,8 @@ impl Command {
410412
}
411413

412414
println!("Total retries: {retries}");
415+
println!("Total time elapsed: {:.2?}", now.elapsed());
416+
413417
Ok(())
414418
}
415419
Command::ERC20 {

crates/blockchain/blockchain.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ pub mod mempool;
55
pub mod payload;
66
mod smoke_test;
77

8+
use std::{ops::Div, time::Instant};
9+
use tracing::info;
10+
811
use error::{ChainError, InvalidBlockError};
912
use ethrex_common::constants::GAS_PER_BLOB;
1013
use ethrex_common::types::requests::{compute_requests_hash, EncodedRequests, Requests};
@@ -29,6 +32,8 @@ use ethrex_vm::{backends::BlockExecutionResult, get_evm_backend_or_default};
2932
///
3033
/// Performs pre and post execution validation, and updates the database with the post state.
3134
pub fn add_block(block: &Block, storage: &Store) -> Result<(), ChainError> {
35+
let since = Instant::now();
36+
3237
let block_hash = block.header.compute_block_hash();
3338

3439
// 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> {
6974
store_block(storage, block.clone())?;
7075
store_receipts(storage, receipts, block_hash)?;
7176

77+
let interval = Instant::now().duration_since(since).as_millis();
78+
if interval != 0 {
79+
let as_gigas = (block.header.gas_used as f64).div(10_f64.powf(9_f64));
80+
let throughput = (as_gigas) / (interval as f64) * 1000_f64;
81+
info!("[METRIC] BLOCK EXECUTION THROUGHPUT: {throughput} Gigagas/s TIME SPENT: {interval} msecs");
82+
}
83+
7284
Ok(())
7385
}
7486

crates/blockchain/payload.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::{
22
cmp::{max, Ordering},
33
collections::HashMap,
4+
ops::Div,
5+
time::Instant,
46
};
57

68
use ethrex_common::{
@@ -238,14 +240,31 @@ pub fn build_payload(
238240
payload: &mut Block,
239241
store: &Store,
240242
) -> Result<(BlobsBundle, U256), ChainError> {
243+
let since = Instant::now();
244+
let gas_limit = payload.header.gas_limit;
241245
debug!("Building payload");
242246
let mut evm_state = evm_state(store.clone(), payload.header.parent_hash);
243247
let mut context = PayloadBuildContext::new(payload, &mut evm_state)?;
248+
244249
apply_system_operations(&mut context)?;
245250
apply_withdrawals(&mut context)?;
246251
fill_transactions(&mut context)?;
247252
extract_requests(&mut context)?;
248253
finalize_payload(&mut context)?;
254+
255+
let interval = Instant::now().duration_since(since).as_millis();
256+
tracing::info!("[METRIC] BUILDING PAYLOAD TOOK: {interval} ms");
257+
if let Some(gas_used) = gas_limit.checked_sub(context.remaining_gas) {
258+
let as_gigas = (gas_used as f64).div(10_f64.powf(9_f64));
259+
260+
if interval != 0 {
261+
let throughput = (as_gigas) / (interval as f64) * 1000_f64;
262+
tracing::info!(
263+
"[METRIC] BLOCK BUILDING THROUGHPUT: {throughput} Gigagas/s TIME SPENT: {interval} msecs"
264+
);
265+
}
266+
}
267+
249268
Ok((context.blobs_bundle, context.block_value))
250269
}
251270

0 commit comments

Comments
 (0)