Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions crates/net/p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions crates/net/p2p/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ static LEAN_PEER_DISCONNECTION_EVENTS_TOTAL: LazyLock<IntCounterVec> = LazyLock:
.unwrap()
});

/// Set the attestation committee subnet gauge.
pub fn set_attestation_committee_subnet(subnet_id: u64) {
static LEAN_ATTESTATION_COMMITTEE_SUBNET: LazyLock<IntGauge> = 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.
Expand Down
1 change: 1 addition & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br>result=success,timeout,error | ✅ |
|`lean_peer_disconnection_events_total`| Counter | Total number of peer disconnection events | On peer disconnection | direction=inbound,outbound<br>reason=timeout,remote_close,local_close,error | ✅ |
Expand Down
Loading