Skip to content

Commit 5ab320e

Browse files
committed
code cleanup
1 parent 53157ac commit 5ab320e

File tree

1 file changed

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

1 file changed

+42
-40
lines changed

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

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -456,19 +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-
ctx.metrics.missing_flashblocks_count.record(
464-
flashblocks_per_block.saturating_sub(ctx.flashblock_index()) as f64,
459+
return self.exit_flashblock_building(
460+
&ctx,
461+
flashblocks_per_block,
462+
&span,
463+
"Payload building complete, job cancelled during execution",
465464
);
466-
debug!(
467-
target: "payload_builder",
468-
message = "Payload building complete, job cancelled during execution"
469-
);
470-
span.record("flashblock_count", ctx.flashblock_index());
471-
return Ok(());
472465
}
473466

474467
let payload_tx_simulation_time = tx_execution_start_time.elapsed();
@@ -517,20 +510,12 @@ where
517510
// If main token got canceled in here that means we received get_payload and we should drop everything and now update best_payload
518511
// To ensure that we will return same blocks as rollup-boost (to leverage caches)
519512
if block_cancel.is_cancelled() {
520-
ctx.metrics.block_built_success.increment(1);
521-
ctx.metrics
522-
.flashblock_count
523-
.record(ctx.flashblock_index() as f64);
524-
ctx.metrics.missing_flashblocks_count.record(
525-
flashblocks_per_block.saturating_sub(ctx.flashblock_index())
526-
as f64,
527-
);
528-
debug!(
529-
target: "payload_builder",
530-
message = "Payload building complete, job cancelled during execution"
513+
return self.exit_flashblock_building(
514+
&ctx,
515+
flashblocks_per_block,
516+
&span,
517+
"Payload building complete, job cancelled during execution",
531518
);
532-
span.record("flashblock_count", ctx.flashblock_index());
533-
return Ok(());
534519
}
535520
self.ws_pub
536521
.publish(&fb_payload)
@@ -570,27 +555,44 @@ where
570555
}
571556
}
572557
None => {
573-
// Exit loop if channel closed or cancelled
574-
ctx.metrics.block_built_success.increment(1);
575-
ctx.metrics
576-
.flashblock_count
577-
.record(ctx.flashblock_index() as f64);
578-
ctx.metrics
579-
.missing_flashblocks_count
580-
.record(flashblocks_per_block.saturating_sub(ctx.flashblock_index()) as f64);
581-
debug!(
582-
target: "payload_builder",
583-
message = "Payload building complete, channel closed or job cancelled",
584-
missing_falshblocks = flashblocks_per_block.saturating_sub(ctx.flashblock_index()),
585-
reduced_flashblocks = self.config.flashblocks_per_block().saturating_sub(flashblocks_per_block),
558+
return self.exit_flashblock_building(
559+
&ctx,
560+
flashblocks_per_block,
561+
&span,
562+
"Payload building complete, channel closed or job cancelled",
586563
);
587-
span.record("flashblock_count", ctx.flashblock_index());
588-
return Ok(());
589564
}
590565
}
591566
}
592567
}
593568

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

0 commit comments

Comments
 (0)