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
30 changes: 30 additions & 0 deletions crates/blockchain/metrics/metrics_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub struct MetricsBlocks {
gas_limit: Gauge,
block_number: IntGauge,
gigagas: Gauge,
gigagas_block_building: Gauge,
block_building_ms: IntGauge,
block_building_base_fee: IntGauge,
gas_used: Gauge,
}

Expand All @@ -34,9 +37,24 @@ impl MetricsBlocks {
.unwrap(),
gigagas: Gauge::new(
"gigagas",
"Keeps track of the block execution throughput through gigagas/s",
)
.unwrap(),
gigagas_block_building: Gauge::new(
"gigagas_block_building",
"Keeps track of the block building throughput through gigagas/s",
)
.unwrap(),
block_building_ms: IntGauge::new(
"block_building_ms",
"Keeps track of the block building throughput through miliseconds",
)
.unwrap(),
block_building_base_fee: IntGauge::new(
"block_building_base_fee",
"Keeps track of the block building base fee",
)
.unwrap(),
gas_used: Gauge::new(
"gas_used",
"Keeps track of the gas used in the latest block",
Expand All @@ -53,6 +71,18 @@ impl MetricsBlocks {
self.gigagas.set(gigagas);
}

pub fn set_latest_gigagas_block_building(&self, gigagas: f64) {
self.gigagas_block_building.set(gigagas);
}

pub fn set_block_building_ms(&self, ms: i64) {
self.block_building_ms.set(ms);
}

pub fn set_block_building_base_fee(&self, base_fee: i64) {
self.block_building_base_fee.set(base_fee);
}

pub fn set_block_number(&self, block_number: u64) -> Result<(), MetricsError> {
self.block_number.set(block_number.try_into()?);
Ok(())
Expand Down
13 changes: 7 additions & 6 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use sha3::{Digest, Keccak256};

use ethrex_metrics::metrics;

#[cfg(feature = "metrics")]
use ethrex_metrics::metrics_blocks::METRICS_BLOCKS;
#[cfg(feature = "metrics")]
use ethrex_metrics::metrics_transactions::{METRICS_TX, MetricsTxType};
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -401,21 +403,20 @@ impl Blockchain {
self.finalize_payload(&mut context).await?;

let interval = Instant::now().duration_since(since).as_millis();
// TODO: expose as a proper metric
// Commented out because we build multiple blocks per request
// each one printing this metric can be spammy

tracing::debug!(
"[METRIC] BUILDING PAYLOAD TOOK: {interval} ms, base fee {}",
base_fee
);
metrics!(METRICS_BLOCKS.set_block_building_ms(interval as i64));
metrics!(METRICS_BLOCKS.set_block_building_base_fee(base_fee as i64));
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;
// TODO: expose as a proper metric
// Commented out because we build multiple blocks per request
// each one printing this metric can be spammy
metrics!(METRICS_BLOCKS.set_latest_gigagas_block_building(throughput));

tracing::debug!(
"[METRIC] BLOCK BUILDING THROUGHPUT: {throughput} Gigagas/s TIME SPENT: {interval} msecs"
);
Expand Down
Loading