Commit 873ddf8
feat: add attestation aggregate coverage metrics (lambdaclass#386)
## Description / Motivation
Ports two upstream changes that together add attestation aggregate
coverage observability:
- [leanSpec #735](leanEthereum/leanSpec#735):
metric registration (mirrors [zeam
#898](blockblaz/zeam#898)).
- [zeam #876](blockblaz/zeam#876): per-slot
coverage computation and emission.
After this PR, all 14 coverage series receive real per-slot updates from
chain activity.
## What Changed
### Registration (`crates/blockchain/src/metrics.rs`)
- Two `pub const &[&str]` label-set constants — single source of truth
for sections and directions.
- Three `IntGaugeVec` statics:
- `lean_attestation_aggregate_coverage_validators{section, subnet}` —
`subnet="combined"` is the section total; `subnet="subnet_N"` is
per-subnet coverage (lazy).
- `lean_attestation_aggregate_coverage_subnets{section}` —
covered-subnet count per section.
- `lean_attestation_aggregate_coverage_diff_validators{direction}` —
symmetric difference between block-included and locally-aggregated
pre-merge aggregates.
- `init()` forces the statics and seeds 14 default zero-valued series.
**Sections:** `timely`, `late`, `block`, `combined`, `agg_start_new`,
`proposal_combined`.
**Directions:** `block_only`, `timely_only`.
### Emission (4 sites)
Every per-slot section is keyed by the attestation `data.slot` (the
voting round being reported), so `timely`/`late`/`block`/`combined`
describe the **same cohort** (matching zeam #876).
- **`accept_new_attestations` (blockchain/store.rs)** — before each
promote, snapshots `new_payloads` participant bits, tagged **per entry
with their `data.slot`**, stashed on the Store. Read at the next slot
boundary to populate the `timely` section ("prev_new" in zeam).
- **`on_tick` interval 1 (blockchain/lib.rs)** — emits the post-block
report for `slot - 1`. Fired at **interval 1, not 0**, so the block
carrying that round's votes (proposed at interval 0 of this slot) has
typically been received and processed, letting the `block` section
observe the same round. Computes `timely` (pre-merge snapshot filtered
to the round), `late` (current `new_payloads` for the round), `block`
(attestations in the **canonical head block** filtered to the round —
canonical by construction, so a fork block can't poison it), and
`combined` (their union); then emits `diff_validators` as the symmetric
difference between `block` and `timely`. **Emits nothing** when no
section has coverage for the round, so a missed slot doesn't surface as
a misleading `block_only=0, timely_only=N`.
- **`start_aggregation_session` (blockchain/lib.rs)** — emits
`agg_start_new` from current `new_payloads` right before fork-choice
aggregation at interval 2.
- **`propose_block` (blockchain/lib.rs)** — emits `proposal_combined`
(the full set of validators included across the block's aggregated
attestations) after the block is built. (A payload-vs-gossip split was
considered but dropped: ethlambda builds blocks exclusively from
`known_aggregated_payloads`, so every included validator is
payload-sourced by construction — `proposal_gossip` would always be 0
and `proposal_payloads` would always equal `proposal_combined`.)
### Supporting changes
- The three emitters live as private free `fn`s at the bottom of
`blockchain/src/lib.rs`. They use `Vec<bool>` locals (`seen` for
validators, `has_subnet` for subnets) plus three small helpers
(`cov_add`, `cov_record`, `or_into`). Subnet derivation is `vid %
committee_count`, matching the gossip subnet assignment in
`crates/net/p2p/src/lib.rs`.
- `Store` gets a single `CoverageSnapshot` field
(`pre_merge_new_coverage`) holding `(data.slot, AggregationBits)`
entries captured before each promote — only participant bits, no proof
duplication. The `block` section needs no stored state: it is read from
the canonical head block at report time.
- `BlockChain::spawn` now takes `attestation_committee_count` (resolved
in `main.rs` from CLI > validator-config.yaml > 1; previously only known
to P2P for subnet subscriptions).
## Operator interpretation of `diff_validators`
The aggregation pipeline produces two pools for the same slot: `timely`
(locally aggregated pre-merge) and `block` (what the proposer included).
The diff counts validators in the symmetric difference:
- `block_only` persistently high → this node was slow to
receive/aggregate via gossip; proposer had a better view.
- `timely_only` persistently high → proposer omitted attestations the
network had time to gossip.
- Both near zero → local aggregation tracks proposers; the network is
converging.
## Correctness / Behavior Guarantees
- **No fork-choice or state-transition change.** Coverage snapshots are
pure observability and do not feed back into block processing.
- The `diff_validators` help text **intentionally diverges** from
upstream's terse phrasing to spell out the symmetric-difference
semantics. Metric name, labels, and values are unchanged; dashboards
built against any client's schema work as-is.
- Cardinality: 14 series at registration; per-subnet series appear
lazily when written. Even with full per-subnet instrumentation at 64
subnets, the validators gauge tops out at `6 × 65 = 390` series.
## Tests Added / Run
No new unit tests. The earlier draft of this PR included unit tests for
an internal `Coverage` bitset wrapper; once the wrapper was inlined as
`Vec<bool>` locals, those tests were exercising trivial iterator ops
rather than the emission contract, so they were dropped.
Commands run:
- `cargo fmt --all -- --check` — clean
- `make lint` (clippy `-D warnings`) — clean
- `cargo test -p ethlambda-blockchain --release --lib --bins` — 21
passed
- `cargo test -p ethlambda-storage --release` — 38 passed
- `cargo test -p ethlambda-blockchain --release --test
forkchoice_spectests` — 62 passed, 8 failed (all
`AttestationTooFarInFuture`, pre-existing fixture flakes on `main`,
unrelated to this PR).
## Related Issues / PRs
- Ports: leanEthereum/leanSpec#735
- Mirrors: blockblaz/zeam#898 + blockblaz/zeam#876
## ✅ Verification Checklist
- [x] Ran `make fmt` — clean
- [x] Ran `make lint` (clippy with `-D warnings`) — clean
- [x] Ran `cargo test --workspace --release` — passing modulo 8
pre-existing forkchoice fixture flakes documented above (unrelated to
this PR)
---------
Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>1 parent e4aa0d1 commit 873ddf8
5 files changed
Lines changed: 373 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
225 | 230 | | |
226 | 231 | | |
227 | 232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
| 101 | + | |
| 102 | + | |
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
| |||
149 | 153 | | |
150 | 154 | | |
151 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
152 | 167 | | |
153 | 168 | | |
154 | 169 | | |
| |||
190 | 205 | | |
191 | 206 | | |
192 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
193 | 225 | | |
194 | 226 | | |
195 | 227 | | |
| |||
198 | 230 | | |
199 | 231 | | |
200 | 232 | | |
| 233 | + | |
201 | 234 | | |
202 | 235 | | |
203 | 236 | | |
| |||
210 | 243 | | |
211 | 244 | | |
212 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
213 | 258 | | |
214 | 259 | | |
215 | 260 | | |
| |||
351 | 396 | | |
352 | 397 | | |
353 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
354 | 405 | | |
355 | 406 | | |
356 | 407 | | |
| |||
0 commit comments