Skip to content

Commit bb31c69

Browse files
authored
fix: record missing flashblocks (#225)
* record missing flashblocks in more places * code cleanup * edit log message
1 parent 0ec0644 commit bb31c69

File tree

1 file changed

+42
-30
lines changed
  • crates/op-rbuilder/src/builders/flashblocks

1 file changed

+42
-30
lines changed

crates/op-rbuilder/src/builders/flashblocks/payload.rs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,12 @@ where
456456
// We got block cancelled, we won't need anything from the block at this point
457457
// Caution: this assume that block cancel token only cancelled when new FCU is received
458458
if block_cancel.is_cancelled() {
459-
ctx.metrics.block_built_success.increment(1);
460-
ctx.metrics
461-
.flashblock_count
462-
.record(ctx.flashblock_index() as f64);
463-
debug!(
464-
target: "payload_builder",
465-
message = "Payload building complete, job cancelled during execution"
459+
self.record_flashblocks_metrics(
460+
&ctx,
461+
flashblocks_per_block,
462+
&span,
463+
"Payload building complete, channel closed or job cancelled",
466464
);
467-
span.record("flashblock_count", ctx.flashblock_index());
468465
return Ok(());
469466
}
470467

@@ -514,15 +511,12 @@ where
514511
// If main token got canceled in here that means we received get_payload and we should drop everything and now update best_payload
515512
// To ensure that we will return same blocks as rollup-boost (to leverage caches)
516513
if block_cancel.is_cancelled() {
517-
ctx.metrics.block_built_success.increment(1);
518-
ctx.metrics
519-
.flashblock_count
520-
.record(ctx.flashblock_index() as f64);
521-
debug!(
522-
target: "payload_builder",
523-
message = "Payload building complete, job cancelled during execution"
514+
self.record_flashblocks_metrics(
515+
&ctx,
516+
flashblocks_per_block,
517+
&span,
518+
"Payload building complete, channel closed or job cancelled",
524519
);
525-
span.record("flashblock_count", ctx.flashblock_index());
526520
return Ok(());
527521
}
528522
self.ws_pub
@@ -563,27 +557,45 @@ where
563557
}
564558
}
565559
None => {
566-
// Exit loop if channel closed or cancelled
567-
ctx.metrics.block_built_success.increment(1);
568-
ctx.metrics
569-
.flashblock_count
570-
.record(ctx.flashblock_index() as f64);
571-
ctx.metrics
572-
.missing_flashblocks_count
573-
.record(flashblocks_per_block.saturating_sub(ctx.flashblock_index()) as f64);
574-
debug!(
575-
target: "payload_builder",
576-
message = "Payload building complete, channel closed or job cancelled",
577-
missing_falshblocks = flashblocks_per_block.saturating_sub(ctx.flashblock_index()),
578-
reduced_flashblocks = self.config.flashblocks_per_block().saturating_sub(flashblocks_per_block),
560+
self.record_flashblocks_metrics(
561+
&ctx,
562+
flashblocks_per_block,
563+
&span,
564+
"Payload building complete, channel closed or job cancelled",
579565
);
580-
span.record("flashblock_count", ctx.flashblock_index());
581566
return Ok(());
582567
}
583568
}
584569
}
585570
}
586571

572+
/// Do some logging and metric recording when we stop build flashblocks
573+
fn record_flashblocks_metrics(
574+
&self,
575+
ctx: &OpPayloadBuilderCtx<FlashblocksExtraCtx>,
576+
flashblocks_per_block: u64,
577+
span: &tracing::Span,
578+
message: &str,
579+
) {
580+
ctx.metrics.block_built_success.increment(1);
581+
ctx.metrics
582+
.flashblock_count
583+
.record(ctx.flashblock_index() as f64);
584+
ctx.metrics
585+
.missing_flashblocks_count
586+
.record(flashblocks_per_block.saturating_sub(ctx.flashblock_index()) as f64);
587+
588+
debug!(
589+
target: "payload_builder",
590+
message = message,
591+
flashblocks_per_block = flashblocks_per_block,
592+
flashblock_index = ctx.flashblock_index(),
593+
config_flashblocks_per_block = self.config.flashblocks_per_block(),
594+
);
595+
596+
span.record("flashblock_count", ctx.flashblock_index());
597+
}
598+
587599
/// Spawn task that will send new flashblock level cancel token in steady intervals (first interval
588600
/// may vary if --flashblocks.dynamic enabled)
589601
pub fn spawn_timer_task(

0 commit comments

Comments
 (0)