@@ -261,7 +261,7 @@ static LEAN_COMMITTEE_SIGNATURES_AGGREGATION_TIME_SECONDS: std::sync::LazyLock<H
261261 register_histogram ! (
262262 "lean_committee_signatures_aggregation_time_seconds" ,
263263 "Time taken to aggregate committee signatures" ,
264- vec![ 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 0.75 , 1 .0]
264+ vec![ 0.05 , 0.1 , 0.25 , 0.5 , 0.75 , 1.0 , 2.0 , 3.0 , 4 .0]
265265 )
266266 . unwrap ( )
267267 } ) ;
@@ -276,6 +276,77 @@ static LEAN_FORK_CHOICE_REORG_DEPTH: std::sync::LazyLock<Histogram> =
276276 . unwrap ( )
277277 } ) ;
278278
279+ // --- Block Production ---
280+
281+ static LEAN_BLOCK_AGGREGATED_PAYLOADS : std:: sync:: LazyLock < Histogram > =
282+ std:: sync:: LazyLock :: new ( || {
283+ register_histogram ! (
284+ "lean_block_aggregated_payloads" ,
285+ "Number of aggregated_payloads in a block" ,
286+ vec![ 1.0 , 2.0 , 4.0 , 8.0 , 16.0 , 32.0 , 64.0 , 128.0 ]
287+ )
288+ . unwrap ( )
289+ } ) ;
290+
291+ static LEAN_BLOCK_BUILDING_PAYLOAD_AGGREGATION_TIME_SECONDS : std:: sync:: LazyLock < Histogram > =
292+ std:: sync:: LazyLock :: new ( || {
293+ register_histogram ! (
294+ "lean_block_building_payload_aggregation_time_seconds" ,
295+ "Time taken to build aggregated_payloads during block building" ,
296+ vec![ 0.1 , 0.25 , 0.5 , 0.75 , 1.0 , 2.0 , 3.0 , 4.0 ]
297+ )
298+ . unwrap ( )
299+ } ) ;
300+
301+ static LEAN_BLOCK_BUILDING_TIME_SECONDS : std:: sync:: LazyLock < Histogram > =
302+ std:: sync:: LazyLock :: new ( || {
303+ register_histogram ! (
304+ "lean_block_building_time_seconds" ,
305+ "Time taken to build a block" ,
306+ vec![ 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 0.75 , 1.0 ]
307+ )
308+ . unwrap ( )
309+ } ) ;
310+
311+ static LEAN_BLOCK_BUILDING_SUCCESS_TOTAL : std:: sync:: LazyLock < IntCounter > =
312+ std:: sync:: LazyLock :: new ( || {
313+ register_int_counter ! (
314+ "lean_block_building_success_total" ,
315+ "Successful block builds"
316+ )
317+ . unwrap ( )
318+ } ) ;
319+
320+ static LEAN_BLOCK_BUILDING_FAILURES_TOTAL : std:: sync:: LazyLock < IntCounter > =
321+ std:: sync:: LazyLock :: new ( || {
322+ register_int_counter ! ( "lean_block_building_failures_total" , "Failed block builds" ) . unwrap ( )
323+ } ) ;
324+
325+ // --- Sync Status ---
326+
327+ /// Node synchronization status.
328+ pub enum SyncStatus {
329+ Idle ,
330+ Syncing ,
331+ Synced ,
332+ }
333+
334+ impl SyncStatus {
335+ fn as_str ( & self ) -> & ' static str {
336+ match self {
337+ SyncStatus :: Idle => "idle" ,
338+ SyncStatus :: Syncing => "syncing" ,
339+ SyncStatus :: Synced => "synced" ,
340+ }
341+ }
342+
343+ const ALL : & [ & str ] = & [ "idle" , "syncing" , "synced" ] ;
344+ }
345+
346+ static LEAN_NODE_SYNC_STATUS : std:: sync:: LazyLock < IntGaugeVec > = std:: sync:: LazyLock :: new ( || {
347+ register_int_gauge_vec ! ( "lean_node_sync_status" , "Node sync status" , & [ "status" ] ) . unwrap ( )
348+ } ) ;
349+
279350// --- Initialization ---
280351
281352/// Register all metrics with the Prometheus registry so they appear in `/metrics` from startup.
@@ -315,6 +386,14 @@ pub fn init() {
315386 std:: sync:: LazyLock :: force ( & LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VERIFICATION_TIME_SECONDS ) ;
316387 std:: sync:: LazyLock :: force ( & LEAN_COMMITTEE_SIGNATURES_AGGREGATION_TIME_SECONDS ) ;
317388 std:: sync:: LazyLock :: force ( & LEAN_FORK_CHOICE_REORG_DEPTH ) ;
389+ // Block production
390+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_AGGREGATED_PAYLOADS ) ;
391+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_PAYLOAD_AGGREGATION_TIME_SECONDS ) ;
392+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_TIME_SECONDS ) ;
393+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_SUCCESS_TOTAL ) ;
394+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_FAILURES_TOTAL ) ;
395+ // Sync status
396+ std:: sync:: LazyLock :: force ( & LEAN_NODE_SYNC_STATUS ) ;
318397}
319398
320399// --- Public API ---
@@ -476,3 +555,38 @@ pub fn set_attestation_committee_count(count: u64) {
476555pub fn observe_fork_choice_reorg_depth ( depth : u64 ) {
477556 LEAN_FORK_CHOICE_REORG_DEPTH . observe ( depth as f64 ) ;
478557}
558+
559+ /// Observe the number of aggregated payloads in a built block.
560+ pub fn observe_block_aggregated_payloads ( count : usize ) {
561+ LEAN_BLOCK_AGGREGATED_PAYLOADS . observe ( count as f64 ) ;
562+ }
563+
564+ /// Start timing payload aggregation during block building. Records duration when the guard is dropped.
565+ pub fn time_block_building_payload_aggregation ( ) -> TimingGuard {
566+ TimingGuard :: new ( & LEAN_BLOCK_BUILDING_PAYLOAD_AGGREGATION_TIME_SECONDS )
567+ }
568+
569+ /// Start timing block building. Records duration when the guard is dropped.
570+ pub fn time_block_building ( ) -> TimingGuard {
571+ TimingGuard :: new ( & LEAN_BLOCK_BUILDING_TIME_SECONDS )
572+ }
573+
574+ /// Increment the successful block builds counter.
575+ pub fn inc_block_building_success ( ) {
576+ LEAN_BLOCK_BUILDING_SUCCESS_TOTAL . inc ( ) ;
577+ }
578+
579+ /// Increment the failed block builds counter.
580+ pub fn inc_block_building_failures ( ) {
581+ LEAN_BLOCK_BUILDING_FAILURES_TOTAL . inc ( ) ;
582+ }
583+
584+ /// Set the node sync status. Sets the given status label to 1 and all others to 0.
585+ pub fn set_node_sync_status ( status : SyncStatus ) {
586+ let active = status. as_str ( ) ;
587+ for label in SyncStatus :: ALL {
588+ LEAN_NODE_SYNC_STATUS
589+ . with_label_values ( & [ label] )
590+ . set ( i64:: from ( * label == active) ) ;
591+ }
592+ }
0 commit comments