Skip to content

Commit 4b172bf

Browse files
authored
Fixed finalize/roothash metrics (#812)
## 📝 Summary Metrics were wrong since finalize_adjust_time and finalize_time were always updated no matter if it was the first finalize call or an update. Not we differentiate the cases and combined the metrics in a single one with a label "mode". Did the same differentiation for root hash times (label "mode") so we can tell the difference between the first root hash and an adjustment. ## ✅ I have completed the following steps: * [X] Run `make lint` * [X] Run `make test` * [ ] Added tests (if applicable)
1 parent 6ad2507 commit 4b172bf

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

crates/rbuilder/src/building/builders/block_building_helper.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl<
304304
building_ctx: &BlockBuildingContext,
305305
built_block_trace: &BuiltBlockTrace,
306306
sim_gas_used: u64,
307+
block_was_adjusted: bool,
307308
) {
308309
let txs = finalized_block.sealed_block.body().transactions.len();
309310
let gas_used = finalized_block.sealed_block.gas_used;
@@ -317,6 +318,7 @@ impl<
317318
sim_gas_used,
318319
builder_name,
319320
building_ctx.timestamp(),
321+
block_was_adjusted,
320322
);
321323

322324
trace!(
@@ -468,6 +470,7 @@ impl<
468470
&self.building_ctx,
469471
&self.built_block_trace,
470472
sim_gas_used,
473+
adjust_finalized_block,
471474
);
472475

473476
self.finalize_adjustment_state = Some(finalize_adjustment_state);

crates/rbuilder/src/telemetry/metrics/mod.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ use tracing::error;
3232
pub mod scope_meter;
3333
mod tracing_metrics;
3434
pub use tracing_metrics::*;
35+
36+
const FINALIZE_MODE_ADJUSTED: &str = "adjusted";
37+
const FINALIZE_MODE_NORMAL: &str = "normal";
38+
39+
fn finalize_mode_label(adjusted: bool) -> &'static str {
40+
if adjusted {
41+
FINALIZE_MODE_ADJUSTED
42+
} else {
43+
FINALIZE_MODE_NORMAL
44+
}
45+
}
46+
3547
const SUBSIDY_ATTEMPT: &str = "attempt";
3648
const SUBSIDY_LANDED: &str = "landed";
3749

@@ -342,20 +354,14 @@ register_metrics! {
342354
.unwrap();
343355
pub static BLOCK_FINALIZE_TIME: HistogramVec = HistogramVec::new(
344356
HistogramOpts::new("block_finalize_time", "Block Finalize Times (ms)")
345-
.buckets(exponential_buckets_range(0.01, 3000.0, 200)),
346-
&[]
347-
)
348-
.unwrap();
349-
pub static BLOCK_FINALIZE_ADJUST_TIME: HistogramVec = HistogramVec::new(
350-
HistogramOpts::new("block_finalize_adjust_time", "Block Finalize Adjust Times (ms)")
351-
.buckets(exponential_buckets_range(0.01, 300.0, 200)),
352-
&[]
357+
.buckets(exponential_buckets_range(0.01, 2000.0, 200)),
358+
&["mode"]
353359
)
354360
.unwrap();
355361
pub static BLOCK_ROOT_HASH_TIME: HistogramVec = HistogramVec::new(
356362
HistogramOpts::new("block_root_hash_time", "Block Root Hash Time (ms)")
357363
.buckets(exponential_buckets_range(0.01, 2000.0, 200)),
358-
&[]
364+
&["mode"]
359365
)
360366
.unwrap();
361367
pub static BLOCK_MULTI_BID_COPY_DURATION: HistogramVec = HistogramVec::new(
@@ -504,19 +510,22 @@ pub fn add_finalized_block_metrics(
504510
sim_gas_used: u64,
505511
builder_name: &str,
506512
block_timestamp: OffsetDateTime,
513+
block_was_adjusted: bool,
507514
) {
508515
if !is_now_close_to_slot_end(block_timestamp) {
509516
return;
510517
}
511518

512519
BLOCK_FINALIZE_TIME
513-
.with_label_values(&[])
514-
.observe(duration_ms(built_block_trace.finalize_time));
515-
BLOCK_FINALIZE_ADJUST_TIME
516-
.with_label_values(&[])
517-
.observe(duration_ms(built_block_trace.finalize_adjust_time));
520+
.with_label_values(&[finalize_mode_label(block_was_adjusted)])
521+
.observe(duration_ms(if block_was_adjusted {
522+
built_block_trace.finalize_adjust_time
523+
} else {
524+
built_block_trace.finalize_time
525+
}));
526+
518527
BLOCK_ROOT_HASH_TIME
519-
.with_label_values(&[])
528+
.with_label_values(&[finalize_mode_label(block_was_adjusted)])
520529
.observe(duration_ms(built_block_trace.root_hash_time));
521530

522531
BLOCK_BUILT_TXS

0 commit comments

Comments
 (0)