Commit 85115d7
authored
Add lean_block_proposal_* metrics for block-proposal attestation selection (#414)
## 🗒️ Description / Motivation
Ports the five `lean_block_proposal_*` observability metrics from
[leanSpec PR #753](leanEthereum/leanSpec#753)
into the ethlambda block builder.
These metrics give cross-client visibility into the block-proposal
attestation-selection path (`build_block`): how long each phase takes,
how many proposal builds run, how many child payloads are greedily
consumed, and how many distinct `AttestationData` / aggregated proofs
end up in the proposed block. They align with [zeam
#914](blockblaz/zeam#914
`getProposalAttestations` instrumentation and the leanSpec naming so the
[leanMetrics](https://github.com/leanEthereum/leanMetrics) dashboards
work across clients.
## What Changed
**`crates/blockchain/src/metrics.rs`** — five new metrics registered
with the existing `LazyLock` + `register_*!` pattern, a
`BLOCK_PROPOSAL_ATTESTATION_BUILD_PHASES` label constant, registration
in `init()`, public API functions, and a unit test:
| Metric | Type | Buckets / Labels |
|--------|------|------------------|
| `lean_block_proposal_attestation_build_phase_seconds` | HistogramVec |
`phase` = `select_payloads`, `compact`, `stf_simulate`; buckets
`0.001…8` |
| `lean_block_proposal_attestation_builds_total` | Counter | one per
proposal attempt |
| `lean_block_proposal_child_payloads_consumed_total` | Counter |
greedily-picked proofs before compaction |
| `lean_block_proposal_attestation_data_selected` | Histogram | buckets
`0, 1, 2, 4, 8, 16, 32` |
| `lean_block_proposal_aggregates_selected` | Histogram | buckets `0, 1,
2, 4, 8, 16, 32, 64, 128` |
**`crates/blockchain/src/block_builder.rs`** — instruments
`build_block`: times the `select_attestations`, `compact_attestations`,
and STF (`process_slots` + `process_block`) phases, and emits the
counters/histograms after a successful build.
**`docs/metrics.md`** — documents all five in the Block Production
Metrics table.
## Correctness / Behavior Guarantees
- **No behavior change.** Only metric observations were added around
existing logic; block contents, selection order, and the
state-transition path are untouched.
- **Architectural divergence from leanSpec, documented.** leanSpec
re-runs the STF inside a fixed-point loop and observes `stf_simulate`
per round. ethlambda projects justification/finalization incrementally
during selection and runs the STF exactly **once** at the end, so its
`stf_simulate` is a single observation per build. This is noted on the
`BLOCK_PROPOSAL_ATTESTATION_BUILD_PHASES` doc comment, consistent with
the upstream PR's own caveat that phase timings are not directly
comparable across clients.
- `attestation_data_selected` and `aggregates_selected` are observed
from the post-compaction body (one merged proof per distinct
`AttestationData`), matching the spec's intent.
- Metrics are only emitted on a **successful** build; a build that
errors out in the STF is already counted by the existing
`lean_block_building_failures_total`.
## Tests Added / Run
- New unit test
`metrics::tests::block_proposal_attestation_build_metrics_are_usable` —
verifies the phase metric registers and accepts every label in
`BLOCK_PROPOSAL_ATTESTATION_BUILD_PHASES`, and that the companion
counters/histograms are callable. Guards against drift between the label
constant and the strings passed at the `build_block` call sites.
- Existing `block_builder` tests (`build_block_*`,
`compact_attestations_*`, `extend_proofs_greedily_*`) now exercise the
new metric paths and pass unchanged.
Commands run:
- `make fmt` — clean
- `cargo clippy -p ethlambda-blockchain --all-targets -- -D warnings` —
clean
- `cargo test -p ethlambda-blockchain --lib` — 23 passing
## Related Issues / PRs
- Ports
[leanEthereum/leanSpec#753](leanEthereum/leanSpec#753)
- Related to
[blockblaz/zeam#914](blockblaz/zeam#914)
- Follows the metrics pattern from #406 (per-subnet attestation
aggregate coverage)
## ✅ Verification Checklist
- [x] Ran `make fmt` — clean
- [x] Ran `make lint` (clippy with `-D warnings`) — clean
- [ ] Ran `cargo test --workspace --release` — only
`ethlambda-blockchain` lib suite run (23 passing); full workspace
release run not yet executed1 parent 161245f commit 85115d7
3 files changed
Lines changed: 127 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
| 74 | + | |
67 | 75 | | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
80 | 89 | | |
81 | 90 | | |
82 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
83 | 96 | | |
84 | 97 | | |
| 98 | + | |
85 | 99 | | |
86 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
87 | 105 | | |
88 | 106 | | |
89 | 107 | | |
| |||
156 | 174 | | |
157 | 175 | | |
158 | 176 | | |
| 177 | + | |
159 | 178 | | |
160 | 179 | | |
161 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
26 | 38 | | |
27 | 39 | | |
28 | 40 | | |
| |||
420 | 432 | | |
421 | 433 | | |
422 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
423 | 491 | | |
424 | 492 | | |
425 | 493 | | |
| |||
512 | 580 | | |
513 | 581 | | |
514 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
515 | 589 | | |
516 | 590 | | |
517 | 591 | | |
| |||
739 | 813 | | |
740 | 814 | | |
741 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
742 | 844 | | |
743 | 845 | | |
744 | 846 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| |||
0 commit comments