@@ -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,58 @@ 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+ static LEAN_NODE_SYNC_STATUS : std:: sync:: LazyLock < IntGaugeVec > = std:: sync:: LazyLock :: new ( || {
328+ register_int_gauge_vec ! ( "lean_node_sync_status" , "Node sync status" , & [ "status" ] ) . unwrap ( )
329+ } ) ;
330+
279331// --- Initialization ---
280332
281333/// Register all metrics with the Prometheus registry so they appear in `/metrics` from startup.
@@ -315,6 +367,14 @@ pub fn init() {
315367 std:: sync:: LazyLock :: force ( & LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VERIFICATION_TIME_SECONDS ) ;
316368 std:: sync:: LazyLock :: force ( & LEAN_COMMITTEE_SIGNATURES_AGGREGATION_TIME_SECONDS ) ;
317369 std:: sync:: LazyLock :: force ( & LEAN_FORK_CHOICE_REORG_DEPTH ) ;
370+ // Block production
371+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_AGGREGATED_PAYLOADS ) ;
372+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_PAYLOAD_AGGREGATION_TIME_SECONDS ) ;
373+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_TIME_SECONDS ) ;
374+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_SUCCESS_TOTAL ) ;
375+ std:: sync:: LazyLock :: force ( & LEAN_BLOCK_BUILDING_FAILURES_TOTAL ) ;
376+ // Sync status
377+ std:: sync:: LazyLock :: force ( & LEAN_NODE_SYNC_STATUS ) ;
318378}
319379
320380// --- Public API ---
@@ -476,3 +536,37 @@ pub fn set_attestation_committee_count(count: u64) {
476536pub fn observe_fork_choice_reorg_depth ( depth : u64 ) {
477537 LEAN_FORK_CHOICE_REORG_DEPTH . observe ( depth as f64 ) ;
478538}
539+
540+ /// Observe the number of aggregated payloads in a built block.
541+ pub fn observe_block_aggregated_payloads ( count : usize ) {
542+ LEAN_BLOCK_AGGREGATED_PAYLOADS . observe ( count as f64 ) ;
543+ }
544+
545+ /// Start timing payload aggregation during block building. Records duration when the guard is dropped.
546+ pub fn time_block_building_payload_aggregation ( ) -> TimingGuard {
547+ TimingGuard :: new ( & LEAN_BLOCK_BUILDING_PAYLOAD_AGGREGATION_TIME_SECONDS )
548+ }
549+
550+ /// Start timing block building. Records duration when the guard is dropped.
551+ pub fn time_block_building ( ) -> TimingGuard {
552+ TimingGuard :: new ( & LEAN_BLOCK_BUILDING_TIME_SECONDS )
553+ }
554+
555+ /// Increment the successful block builds counter.
556+ pub fn inc_block_building_success ( ) {
557+ LEAN_BLOCK_BUILDING_SUCCESS_TOTAL . inc ( ) ;
558+ }
559+
560+ /// Increment the failed block builds counter.
561+ pub fn inc_block_building_failures ( ) {
562+ LEAN_BLOCK_BUILDING_FAILURES_TOTAL . inc ( ) ;
563+ }
564+
565+ /// Set the node sync status. Sets the given status label to 1 and all others to 0.
566+ pub fn set_node_sync_status ( status : & str ) {
567+ for label in & [ "idle" , "syncing" , "synced" ] {
568+ LEAN_NODE_SYNC_STATUS
569+ . with_label_values ( & [ label] )
570+ . set ( i64:: from ( * label == status) ) ;
571+ }
572+ }
0 commit comments