@@ -456,18 +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+ self . record_flashblocks_metrics (
460+ & ctx,
461+ flashblocks_per_block,
462+ & span,
463+ "Payload building complete, channel closed or job cancelled" ,
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 ( ) ) ;
471465 return Ok ( ( ) ) ;
472466 }
473467
@@ -517,19 +511,12 @@ where
517511 // If main token got canceled in here that means we received get_payload and we should drop everything and now update best_payload
518512 // To ensure that we will return same blocks as rollup-boost (to leverage caches)
519513 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"
514+ self . record_flashblocks_metrics (
515+ & ctx,
516+ flashblocks_per_block,
517+ & span,
518+ "Payload building complete, channel closed or job cancelled" ,
531519 ) ;
532- span. record ( "flashblock_count" , ctx. flashblock_index ( ) ) ;
533520 return Ok ( ( ) ) ;
534521 }
535522 self . ws_pub
@@ -570,27 +557,44 @@ where
570557 }
571558 }
572559 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) ,
560+ self . record_flashblocks_metrics (
561+ & ctx,
562+ flashblocks_per_block,
563+ & span,
564+ "Payload building complete, channel closed or job cancelled" ,
586565 ) ;
587- span. record ( "flashblock_count" , ctx. flashblock_index ( ) ) ;
588566 return Ok ( ( ) ) ;
589567 }
590568 }
591569 }
592570 }
593571
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+ missing_flashblocks = flashblocks_per_block. saturating_sub( ctx. flashblock_index( ) ) ,
592+ reduced_flashblocks = self . config. flashblocks_per_block( ) . saturating_sub( flashblocks_per_block) ,
593+ ) ;
594+
595+ span. record ( "flashblock_count" , ctx. flashblock_index ( ) ) ;
596+ }
597+
594598 /// Spawn task that will send new flashblock level cancel token in steady intervals (first interval
595599 /// may vary if --flashblocks.dynamic enabled)
596600 pub fn spawn_timer_task (
0 commit comments