Commit c6060d5
Implement lean_attestation_committee_subnet metric (#243)
## Motivation
The [leanMetrics
specification](https://github.com/leanEthereum/leanMetrics/blob/main/metrics.md)
defines `lean_attestation_committee_subnet` as a Network Metric (Gauge,
set on node start) that all lean clients should expose. ethlambda
already computes the subnet ID at startup (`validator_id %
attestation_committee_count`) for gossipsub topic subscription, but does
not expose it as a Prometheus gauge.
This brings ethlambda closer to full leanMetrics compliance and helps
operators verify subnet assignments via Grafana dashboards.
## Description
Register a new `lean_attestation_committee_subnet` Prometheus `IntGauge`
in the P2P metrics module and set it at startup with the computed subnet
ID.
### Changes
- **`crates/net/p2p/src/metrics.rs`**: New
`set_attestation_committee_subnet(subnet_id: u64)` function with a
function-scoped `LazyLock<IntGauge>`, following the same pattern used by
`set_attestation_committee_count` in the blockchain metrics module.
- **`crates/net/p2p/src/lib.rs`**: Call the setter after computing
`subnet_id` (line 213), passing `subnet_id.unwrap_or(0)`. Non-validator
nodes default to subnet 0, which matches their fanout publishing
behavior.
- **`docs/metrics.md`**: Added row to the Network Metrics table
documenting the new metric as supported.
### Design decisions
- **Placed in P2P metrics** (not blockchain metrics): The subnet is a
network-layer concept — it governs gossipsub topic subscription and is
computed within the P2P module.
- **Non-validator nodes expose subnet 0**: The leanMetrics spec says "on
node start" with no validator-only qualifier. Non-validators use subnet
0 for fanout publishing, so exposing 0 is accurate.
## How to Test
```bash
make fmt # passes
make lint # passes
make test # all tests pass
```
To verify at runtime: start a node and check `curl
http://localhost:5054/metrics | grep lean_attestation_committee_subnet`.
---------
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>1 parent 455611c commit c6060d5
3 files changed
+18
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
71 | 83 | | |
72 | 84 | | |
73 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
0 commit comments