@@ -22,6 +22,7 @@ use reth_optimism_payload_builder::payload_id_optimism;
2222use  serde:: { Deserialize ,  Serialize } ; 
2323use  std:: io; 
2424use  std:: sync:: Arc ; 
25+ use  std:: sync:: atomic:: { AtomicU64 ,  Ordering } ; 
2526use  thiserror:: Error ; 
2627use  tokio:: sync:: RwLock ; 
2728use  tokio:: sync:: mpsc; 
@@ -187,7 +188,12 @@ pub struct FlashblocksService {
187188    /// Websocket publisher for sending valid pre-confirmations to clients. 
188189     ws_pub :  Arc < WebSocketPublisher > , 
189190
191+     /// Metrics 
190192     metrics :  FlashblocksServiceMetrics , 
193+ 
194+     /// Atomic to track absolute maximum number of flashblocks used is block building. 
195+      /// This used to measures the reduction in flashblocks issued. 
196+      max_flashblocks :  Arc < AtomicU64 > , 
191197} 
192198
193199impl  FlashblocksService  { 
@@ -200,6 +206,7 @@ impl FlashblocksService {
200206            best_payload :  Arc :: new ( RwLock :: new ( FlashblockBuilder :: new ( ) ) ) , 
201207            ws_pub, 
202208            metrics :  Default :: default ( ) , 
209+             max_flashblocks :  Arc :: new ( AtomicU64 :: new ( 0 ) ) , 
203210        } ) 
204211    } 
205212
@@ -219,10 +226,13 @@ impl FlashblocksService {
219226        // consume the best payload and reset the builder 
220227        let  payload = { 
221228            let  mut  builder = self . best_payload . write ( ) . await ; 
222-             let  flashblocks_number = builder. flashblocks . len ( ) ; 
229+             let  flashblocks_number = builder. flashblocks . len ( )  as  u64 ; 
230+             let  max_flashblocks = self 
231+                 . max_flashblocks 
232+                 . fetch_max ( flashblocks_number,  Ordering :: Relaxed ) 
233+                 . max ( flashblocks_number) ; 
223234            self . metrics 
224-                 . flashblocks_used 
225-                 . record ( flashblocks_number as  f64 ) ; 
235+                 . record_flashblocks ( flashblocks_number,  max_flashblocks) ; 
226236            tracing:: Span :: current ( ) . record ( "flashblocks_count" ,  flashblocks_number) ; 
227237            // Take payload and place new one in its place in one go to avoid double locking 
228238            std:: mem:: replace ( & mut  * builder,  FlashblockBuilder :: new ( ) ) . into_envelope ( version) ?
0 commit comments