From 1e0c3e012687820722a7aa3e124c035088ff18a7 Mon Sep 17 00:00:00 2001 From: bomanaps Date: Tue, 17 Mar 2026 10:14:31 +0100 Subject: [PATCH] Fix devnet0 fork and connected peers metric --- lean_client/fork_choice/src/handlers.rs | 5 ++- lean_client/networking/src/network/service.rs | 33 +++++++++++++++---- lean_client/networking/src/req_resp.rs | 16 +++++++-- lean_client/src/main.rs | 2 +- lean_client/validator/src/lib.rs | 5 ++- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/lean_client/fork_choice/src/handlers.rs b/lean_client/fork_choice/src/handlers.rs index 4f94e1e..26a56c6 100644 --- a/lean_client/fork_choice/src/handlers.rs +++ b/lean_client/fork_choice/src/handlers.rs @@ -94,7 +94,10 @@ fn validate_attestation_data(store: &Store, data: &AttestationData) -> Result<() /// Returns the first block root (source, target, or head) referenced by `attestation_data` /// that is not yet present in the store, or `None` if all are known. -fn find_unknown_attestation_block(store: &Store, attestation_data: &AttestationData) -> Option { +fn find_unknown_attestation_block( + store: &Store, + attestation_data: &AttestationData, +) -> Option { [ attestation_data.source.root, attestation_data.target.root, diff --git a/lean_client/networking/src/network/service.rs b/lean_client/networking/src/network/service.rs index 34b112b..d684231 100644 --- a/lean_client/networking/src/network/service.rs +++ b/lean_client/networking/src/network/service.rs @@ -414,7 +414,11 @@ where } METRICS.get().map(|metrics| { - metrics.register_peer_connection_success(endpoint.is_listener()) + metrics.register_peer_connection_success(endpoint.is_listener()); + metrics + .lean_connected_peers + .with_label_values(&["unknown"]) + .set(connected as i64); }); None @@ -452,7 +456,11 @@ where Some(ConnectionError::KeepAliveTimeout) => DisconnectReason::Timeout, }; - metrics.register_peer_disconnect(endpoint.is_listener(), reason) + metrics.register_peer_disconnect(endpoint.is_listener(), reason); + metrics + .lean_connected_peers + .with_label_values(&["unknown"]) + .set(connected as i64); }); Some(NetworkEvent::PeerDisconnected(peer_id)) @@ -644,7 +652,14 @@ where } => { use crate::req_resp::{LeanRequest, LeanResponse}; - let (response, peer_finalized_slot, peer_head_root, peer_head_slot, our_finalized_slot, our_head_slot) = match request { + let ( + response, + peer_finalized_slot, + peer_head_root, + peer_head_slot, + our_finalized_slot, + our_head_slot, + ) = match request { LeanRequest::Status(peer_status) => { let status = self.status_provider.read().clone(); let our_finalized = status.finalized.slot.0; @@ -653,7 +668,14 @@ where let pf = peer_status.finalized.slot.0; let ph = peer_status.head.root; let phs = peer_status.head.slot.0; - (LeanResponse::Status(status), pf, ph, phs, our_finalized, our_head) + ( + LeanResponse::Status(status), + pf, + ph, + phs, + our_finalized, + our_head, + ) } _ => { warn!(peer = %peer, "Unexpected request type on Status protocol"); @@ -1063,8 +1085,7 @@ where let our_finalized = self.status_provider.read().finalized.slot.0; info!( num_peers = peers.len(), - our_finalized, - "Periodic sync check: sending status to all connected peers" + our_finalized, "Periodic sync check: sending status to all connected peers" ); for peer_id in peers { self.send_status_request(peer_id); diff --git a/lean_client/networking/src/req_resp.rs b/lean_client/networking/src/req_resp.rs index d85ec7d..1768e09 100644 --- a/lean_client/networking/src/req_resp.rs +++ b/lean_client/networking/src/req_resp.rs @@ -320,7 +320,10 @@ impl LeanCodec { if declared_len as usize > MAX_PAYLOAD_SIZE { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Declared length too large: {} > {}", declared_len, MAX_PAYLOAD_SIZE), + format!( + "Declared length too large: {} > {}", + declared_len, MAX_PAYLOAD_SIZE + ), )); } @@ -336,7 +339,11 @@ impl LeanCodec { if ssz_bytes.len() != declared_len as usize { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Length mismatch: declared {}, got {}", declared_len, ssz_bytes.len()), + format!( + "Length mismatch: declared {}, got {}", + declared_len, + ssz_bytes.len() + ), )); } @@ -377,7 +384,10 @@ impl LeanCodec { offset += consumed; if code != RESPONSE_SUCCESS { - warn!(response_code = code, "BlocksByRoot non-success response chunk"); + warn!( + response_code = code, + "BlocksByRoot non-success response chunk" + ); continue; } if ssz_bytes.is_empty() { diff --git a/lean_client/src/main.rs b/lean_client/src/main.rs index 445074b..15a1937 100644 --- a/lean_client/src/main.rs +++ b/lean_client/src/main.rs @@ -576,7 +576,7 @@ async fn main() -> Result<()> { }); } - let fork = "devnet3".to_string(); + let fork = "devnet0".to_string(); // Subscribe to topics based on validator role: // - Aggregators: all attestation subnets // - Non-aggregator validators: only their own subnet diff --git a/lean_client/validator/src/lib.rs b/lean_client/validator/src/lib.rs index c1cdc9f..5bf6157 100644 --- a/lean_client/validator/src/lib.rs +++ b/lean_client/validator/src/lib.rs @@ -5,8 +5,8 @@ use std::path::Path; use anyhow::{Context, Result, anyhow, bail}; use containers::{ AggregatedSignatureProof, AggregationBits, Attestation, AttestationData, AttestationSignatures, - Block, BlockSignatures, BlockWithAttestation, - SignedAggregatedAttestation, SignedAttestation, SignedBlockWithAttestation, Slot, + Block, BlockSignatures, BlockWithAttestation, SignedAggregatedAttestation, SignedAttestation, + SignedBlockWithAttestation, Slot, }; use fork_choice::store::Store; use metrics::{METRICS, stop_and_discard, stop_and_record}; @@ -407,5 +407,4 @@ impl ValidatorService { }) .collect() } - }