diff --git a/crates/net/p2p/src/lib.rs b/crates/net/p2p/src/lib.rs index d82036b..f482cd3 100644 --- a/crates/net/p2p/src/lib.rs +++ b/crates/net/p2p/src/lib.rs @@ -209,12 +209,11 @@ pub fn build_swarm( // attestation_committee_count is validated to be >= 1 by clap at CLI parse time. let subnet_id = config .validator_id - .map(|vid| vid % config.attestation_committee_count); - let attestation_topic_kind = match subnet_id { - Some(id) => format!("{ATTESTATION_SUBNET_TOPIC_PREFIX}_{id}"), - // Non-validators use subnet 0 for publishing - None => format!("{ATTESTATION_SUBNET_TOPIC_PREFIX}_0"), - }; + .map(|vid| vid % config.attestation_committee_count) + .unwrap_or(0); + metrics::set_attestation_committee_subnet(subnet_id); + + let attestation_topic_kind = format!("{ATTESTATION_SUBNET_TOPIC_PREFIX}_{subnet_id}"); let attestation_topic_str = format!("/leanconsensus/{network}/{attestation_topic_kind}/ssz_snappy"); let attestation_topic = libp2p::gossipsub::IdentTopic::new(attestation_topic_str); diff --git a/crates/net/p2p/src/metrics.rs b/crates/net/p2p/src/metrics.rs index 00224d7..0fb89c5 100644 --- a/crates/net/p2p/src/metrics.rs +++ b/crates/net/p2p/src/metrics.rs @@ -68,6 +68,18 @@ static LEAN_PEER_DISCONNECTION_EVENTS_TOTAL: LazyLock = LazyLock: .unwrap() }); +/// Set the attestation committee subnet gauge. +pub fn set_attestation_committee_subnet(subnet_id: u64) { + static LEAN_ATTESTATION_COMMITTEE_SUBNET: LazyLock = LazyLock::new(|| { + register_int_gauge!( + "lean_attestation_committee_subnet", + "Node's attestation committee subnet" + ) + .unwrap() + }); + LEAN_ATTESTATION_COMMITTEE_SUBNET.set(subnet_id.try_into().unwrap_or_default()); +} + /// Notify that a peer connection event occurred. /// /// If `result` is "success", the connected peer count is incremented. diff --git a/docs/metrics.md b/docs/metrics.md index 5094b72..778a333 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -74,6 +74,7 @@ The exposed metrics follow [the leanMetrics specification](https://github.com/le | Name | Type | Usage | Sample collection event | Labels | Supported | |--------|-------|-------|-------------------------|--------|-----------| |`lean_attestation_committee_count`| Gauge | Number of attestation committees | On node start | | ✅ | +|`lean_attestation_committee_subnet`| Gauge | Node's attestation committee subnet | On node start | | ✅ | |`lean_connected_peers`| Gauge | Number of connected peers | On scrape | client=ethlambda,grandine,lantern,lighthouse,qlean,ream,zeam | ✅(*) | |`lean_peer_connection_events_total`| Counter | Total number of peer connection events | On peer connection | direction=inbound,outbound
result=success,timeout,error | ✅ | |`lean_peer_disconnection_events_total`| Counter | Total number of peer disconnection events | On peer disconnection | direction=inbound,outbound
reason=timeout,remote_close,local_close,error | ✅ |