@@ -906,6 +906,7 @@ where
906906 simulation_state. transition_state = simulation_transition_state;
907907
908908 // Refresh pool txs
909+ let best_txs_start_time = Instant :: now ( ) ;
909910 best_txs. refresh_iterator (
910911 BestPayloadTransactions :: new (
911912 self . pool
@@ -914,7 +915,15 @@ where
914915 ) ,
915916 ctx. flashblock_index ( ) ,
916917 ) ;
918+ let transaction_pool_fetch_time = best_txs_start_time. elapsed ( ) ;
919+ ctx. metrics
920+ . transaction_pool_fetch_duration
921+ . record ( transaction_pool_fetch_time) ;
922+ ctx. metrics
923+ . transaction_pool_fetch_gauge
924+ . set ( transaction_pool_fetch_time) ;
917925
926+ let tx_execution_start_time = Instant :: now ( ) ;
918927 ctx. execute_best_transactions (
919928 & mut simulation_info,
920929 & mut simulation_state,
@@ -923,6 +932,13 @@ where
923932 target_da_for_batch,
924933 )
925934 . wrap_err ( "failed to execute best transactions" ) ?;
935+ let payload_transaction_simulation_time = tx_execution_start_time. elapsed ( ) ;
936+ ctx. metrics
937+ . payload_transaction_simulation_duration
938+ . record ( payload_transaction_simulation_time) ;
939+ ctx. metrics
940+ . payload_transaction_simulation_gauge
941+ . set ( payload_transaction_simulation_time) ;
926942
927943 // Try early return condition
928944 if block_cancel. is_cancelled ( ) {
@@ -953,24 +969,41 @@ where
953969 }
954970
955971 // build block and return new best
956- build_block (
972+ let total_block_built_duration = Instant :: now ( ) ;
973+
974+ let build_result = build_block (
957975 & mut simulation_state,
958976 ctx,
959977 & mut simulation_info,
960978 ctx. extra_ctx . disable_state_root || ctx. attributes ( ) . no_tx_pool ,
961- )
962- . map ( |( payload, mut fb) | {
963- fb. index = ctx. flashblock_index ( ) ;
964- fb. base = None ;
965- Some ( (
966- payload,
967- fb,
968- simulation_info,
969- simulation_state. cache ,
970- simulation_state. transition_state ,
971- ) )
972- } )
973- . wrap_err ( "failed to build payload" )
979+ ) ;
980+
981+ let total_block_built_duration = total_block_built_duration. elapsed ( ) ;
982+ ctx. metrics
983+ . total_block_built_duration
984+ . record ( total_block_built_duration) ;
985+ ctx. metrics
986+ . total_block_built_gauge
987+ . set ( total_block_built_duration) ;
988+
989+ match build_result {
990+ Err ( err) => {
991+ ctx. metrics . invalid_built_blocks_count . increment ( 1 ) ;
992+ Err ( err) . wrap_err ( "failed to build payload" )
993+ }
994+ Ok ( ( payload, mut fb) ) => {
995+ fb. index = ctx. flashblock_index ( ) ;
996+ fb. base = None ;
997+
998+ Ok ( Some ( (
999+ payload,
1000+ fb,
1001+ simulation_info,
1002+ simulation_state. cache ,
1003+ simulation_state. transition_state ,
1004+ ) ) )
1005+ }
1006+ }
9741007 }
9751008
9761009 #[ expect( clippy:: too_many_arguments) ]
@@ -986,13 +1019,27 @@ where
9861019 best_txs : & mut NextBestFlashblocksTxs < Pool > ,
9871020 block_cancel : & CancellationToken ,
9881021 best_payload : & BlockCell < OpBuiltPayload > ,
989- _span : & tracing:: Span ,
1022+ span : & tracing:: Span ,
9901023 ) -> eyre:: Result < Option < FlashblocksExtraCtx > > {
9911024 // 1. --- Prepare shared context ---
9921025
993- // Add top of block builder txns
1026+ let flashblock_index = ctx . flashblock_index ( ) ;
9941027 let mut target_gas_for_batch = ctx. extra_ctx . target_gas_for_batch ;
9951028 let mut target_da_for_batch = ctx. extra_ctx . target_da_for_batch ;
1029+ info ! (
1030+ target: "payload_builder" ,
1031+ block_number = ctx. block_number( ) ,
1032+ flashblock_index,
1033+ target_gas = target_gas_for_batch,
1034+ gas_used = info. cumulative_gas_used,
1035+ target_da = target_da_for_batch,
1036+ da_used = info. cumulative_da_bytes_used,
1037+ block_gas_used = ctx. block_gas_limit( ) ,
1038+ "Building flashblock" ,
1039+ ) ;
1040+ let flashblock_build_start_time = Instant :: now ( ) ;
1041+
1042+ // Add top of block builder txns
9961043 let builder_txs = self
9971044 . builder_tx
9981045 . add_builder_txs ( & state_provider, info, ctx, state, true )
@@ -1016,6 +1063,13 @@ where
10161063 // If main token got canceled in here that means we received get_payload, and we should drop everything and not update best_payload
10171064 // To ensure that we will return same blocks as rollup-boost (to leverage caches)
10181065 if block_cancel. is_cancelled ( ) {
1066+ self . record_flashblocks_metrics (
1067+ ctx,
1068+ info,
1069+ ctx. target_flashblock_count ( ) ,
1070+ span,
1071+ "Payload building complete, channel closed or job cancelled" ,
1072+ ) ;
10191073 return Ok ( None ) ;
10201074 }
10211075 // interval end: abort worker and publish current best immediately (below)
@@ -1053,7 +1107,7 @@ where
10531107 state. transition_state = transition_state;
10541108
10551109 // Send payloads
1056- let _flashblock_byte_size = self
1110+ let flashblock_byte_size = self
10571111 . ws_pub
10581112 . publish ( & fb_payload)
10591113 . wrap_err ( "failed to publish flashblock via websocket" ) ?;
@@ -1072,9 +1126,19 @@ where
10721126 . iter ( )
10731127 . map ( |tx| tx. tx_hash ( ) )
10741128 . collect :: < Vec < _ > > ( ) ;
1075- // warn: it also marks the top of blocks builder_txs
10761129 best_txs. mark_commited ( batch_new_transactions) ;
10771130
1131+ // Record flashblock build duration
1132+ ctx. metrics
1133+ . flashblock_build_duration
1134+ . record ( flashblock_build_start_time. elapsed ( ) ) ;
1135+ ctx. metrics
1136+ . flashblock_byte_size_histogram
1137+ . record ( flashblock_byte_size as f64 ) ;
1138+ ctx. metrics
1139+ . flashblock_num_tx_histogram
1140+ . record ( info. executed_transactions . len ( ) as f64 ) ;
1141+
10781142 // Update context for next iteration
10791143 let target_gas_for_batch = ctx. extra_ctx . target_gas_for_batch + ctx. extra_ctx . gas_per_batch ;
10801144 let target_da_for_batch = ctx
@@ -1087,6 +1151,16 @@ where
10871151 . extra_ctx
10881152 . clone ( )
10891153 . next ( target_gas_for_batch, target_da_for_batch) ;
1154+
1155+ info ! (
1156+ target: "payload_builder" ,
1157+ message = "Flashblock built" ,
1158+ flashblock_index,
1159+ current_gas = info. cumulative_gas_used,
1160+ current_da = info. cumulative_da_bytes_used,
1161+ target_flashblocks = ctx. target_flashblock_count( ) ,
1162+ ) ;
1163+
10901164 Ok ( Some ( next_extra_ctx) )
10911165 }
10921166
0 commit comments