From cfb3ebcfe7dd497b3dd9a2b12871be17a9b639f4 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Mon, 1 Jul 2024 12:49:03 +1000 Subject: [PATCH] Add metrics and update code comment. --- .../src/peer_manager/peerdb/peer_info.rs | 4 +--- beacon_node/lighthouse_network/src/types/globals.rs | 6 +++++- beacon_node/network/src/metrics.rs | 5 +++++ beacon_node/network/src/sync/range_sync/chain.rs | 13 +++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs b/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs index 2ce13e277a8..b0d28cc835e 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs @@ -95,9 +95,7 @@ impl PeerInfo { .map_or(false, |s| s.get(**id as usize).unwrap_or(false)) } Subnet::DataColumn(_) => { - // There's no metadata field for data column subnets, we use the `csc` enr field - // along with `node_id` to determine whether peer SHOULD be subscribed to a - // given subnet. + // TODO(das): Pending spec PR https://github.com/ethereum/consensus-specs/pull/3821 return true; } } diff --git a/beacon_node/lighthouse_network/src/types/globals.rs b/beacon_node/lighthouse_network/src/types/globals.rs index 934ff276b6b..83ff9be5421 100644 --- a/beacon_node/lighthouse_network/src/types/globals.rs +++ b/beacon_node/lighthouse_network/src/types/globals.rs @@ -271,7 +271,11 @@ mod test { drop(peers_db_write_lock); let custody_subnets = (0..spec.data_column_sidecar_subnet_count) - .filter(|col_index| !globals.custody_peers_for_column(*col_index, &spec).is_empty()) + .filter(|col_index| { + !globals + .custody_peers_for_column(*col_index, &spec) + .is_empty() + }) .count(); // The single peer's custody subnet should match custody_requirement. diff --git a/beacon_node/network/src/metrics.rs b/beacon_node/network/src/metrics.rs index 56af9833f1a..dd5e359af37 100644 --- a/beacon_node/network/src/metrics.rs +++ b/beacon_node/network/src/metrics.rs @@ -239,6 +239,11 @@ lazy_static! { "Number of connected peers per sync status type", &["sync_status"] ); + pub static ref PEERS_PER_COLUMN_SUBNET: Result = try_create_int_gauge_vec( + "peers_per_column_subnet", + "Number of connected peers per column subnet", + &["subnet_id"] + ); pub static ref SYNCING_CHAINS_COUNT: Result = try_create_int_gauge_vec( "sync_range_chains", "Number of Syncing chains in range, per range type", diff --git a/beacon_node/network/src/sync/range_sync/chain.rs b/beacon_node/network/src/sync/range_sync/chain.rs index 5ee0b16e029..071d634a39f 100644 --- a/beacon_node/network/src/sync/range_sync/chain.rs +++ b/beacon_node/network/src/sync/range_sync/chain.rs @@ -1,4 +1,5 @@ use super::batch::{BatchInfo, BatchProcessingResult, BatchState}; +use crate::metrics::PEERS_PER_COLUMN_SUBNET; use crate::network_beacon_processor::ChainSegmentProcessId; use crate::sync::network_context::RangeRequestId; use crate::sync::{ @@ -7,6 +8,7 @@ use crate::sync::{ use beacon_chain::block_verification_types::RpcBlock; use beacon_chain::BeaconChainTypes; use fnv::FnvHashMap; +use lighthouse_metrics::set_int_gauge; use lighthouse_network::{PeerAction, PeerId, Subnet}; use rand::seq::SliceRandom; use slog::{crit, debug, o, warn}; @@ -397,7 +399,9 @@ impl SyncingChain { } } } else if !self.good_peers_on_custody_subnets(self.processing_target, network) { - // If there's no good custody peers for this epoch, batch won't be created + // This is to handle the case where no batch was sent for the current processing + // target when there is no custody peers available. This is a valid state and should not + // return an error. return Ok(KeepChain); } else { return Err(RemoveChain::WrongChainState(format!( @@ -1044,7 +1048,12 @@ impl SyncingChain { .read() .good_peers_on_subnet(Subnet::DataColumn(subnet_id)) .count(); - debug!(self.log, "Peers found on custody subnet"; "subnet_id" => ?subnet_id, "peer_count" => peer_count); + + set_int_gauge( + &PEERS_PER_COLUMN_SUBNET, + &[&subnet_id.to_string()], + peer_count as i64, + ); peer_count > 0 }); peers_on_all_custody_subnets