Skip to content
Closed
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
13 changes: 12 additions & 1 deletion crates/op-rbuilder/src/builders/flashblocks/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,16 @@ where
);

// Process flashblocks - block on async channel receive
let mut wait_start: Option<Instant> = None;
loop {
// Wait for signal before building flashblock.
if let Ok(new_fb_cancel) = rx.recv() {
if let Some(start) = wait_start {
ctx.metrics.record_flashblock_wait_for_next_tick(
ctx.flashblock_index(),
start.elapsed(),
);
}
debug!(
target: "payload_builder",
id = %fb_payload.payload_id,
Expand Down Expand Up @@ -585,6 +592,7 @@ where
}
};

wait_start = Some(Instant::now());
ctx = ctx.with_extra_ctx(next_flashblocks_ctx);
}
}
Expand Down Expand Up @@ -759,15 +767,18 @@ where
best_payload.set(new_payload);

// Record flashblock build duration
let flashblock_build_duration = flashblock_build_start_time.elapsed();
ctx.metrics
.flashblock_build_duration
.record(flashblock_build_start_time.elapsed());
.record(flashblock_build_duration);
ctx.metrics
.flashblock_byte_size_histogram
.record(flashblock_byte_size as f64);
ctx.metrics
.flashblock_num_tx_histogram
.record(info.executed_transactions.len() as f64);
ctx.metrics
.record_flashblock_indexed_metrics(flashblock_index, flashblock_build_duration);

// Update bundle_state for next iteration
if let Some(da_limit) = ctx.extra_ctx.da_per_batch {
Expand Down
38 changes: 37 additions & 1 deletion crates/op-rbuilder/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::time::Duration;

use alloy_primitives::{Address, hex};
use metrics::IntoF64;
use reth_metrics::{
Metrics,
metrics::{Counter, Gauge, Histogram, gauge},
metrics::{Counter, Gauge, Histogram, SharedString, counter, gauge, histogram},
};

use crate::{
Expand Down Expand Up @@ -194,6 +196,40 @@ impl OpRBuilderMetrics {
self.bundles_reverted.record(num_bundles_reverted);
self.payload_reverted_tx_gas_used.set(reverted_gas_used);
}

/// Record per-flashblock-index metrics for build duration and emission.
pub fn record_flashblock_indexed_metrics(
&self,
flashblock_index: u64,
build_duration: Duration,
) {
let index_label: SharedString = flashblock_index.to_string().into();
histogram!(
"op_rbuilder_flashblock_build_duration_seconds_by_index",
"flashblock_index" => index_label.clone()
)
.record(build_duration.as_secs_f64());
counter!(
"op_rbuilder_flashblock_emitted_total",
"flashblock_index" => index_label
)
.increment(1);
}

/// Record the time spent waiting between finishing a flashblock build and
/// receiving the next tick from the scheduler.
pub fn record_flashblock_wait_for_next_tick(
&self,
flashblock_index: u64,
wait_duration: Duration,
) {
let index_label: SharedString = flashblock_index.to_string().into();
histogram!(
"op_rbuilder_flashblock_wait_for_next_tick_duration_seconds",
"flashblock_index" => index_label
)
.record(wait_duration.as_secs_f64());
}
}

/// Set gauge metrics for some flags so we can inspect which ones are set
Expand Down
Loading