Skip to content

feat(pq): expose aggregation timings as Prometheus metrics - #973

Merged
pablodeymo merged 4 commits into
pq-devnet-2from
feat/pq-devnet-2-aggregation-metrics
Dec 4, 2026
Merged

pablodeymo merged 4 commits into
pq-devnet-2from
feat/pq-devnet-2-aggregation-metrics

Conversation

@pablodeymo

Copy link
Copy Markdown
Collaborator

Summary

Ports #941 (step 1 of #938) onto pq-devnet-2, exposing the eleven PQ aggregation, merge, verification, and vote-arrival Prometheus series on /metrics alongside pq-devnet-2's OTLP PQ telemetry hooks:

Metric Labels Measures
lean_beacon_pq_committee_proof_seconds position leanVM time to prove one committee's aggregate
lean_beacon_pq_committee_proof_ready_offset_seconds position how far into its slot the proof was ready
lean_beacon_pq_committee_proof_signatures signatures the proof proves
lean_beacon_pq_committee_proof_size_bytes proof size
lean_beacon_pq_committee_proofs_total position, outcome committees a seat was due to prove: proved, late, failed, already_proven, unproved
lean_beacon_pq_merge_seconds phase leanVM time to merge a block's attestation proofs
lean_beacon_pq_merge_children child proofs the merge folded
lean_beacon_pq_merged_proof_size_bytes merged proof size
lean_beacon_pq_merges_total phase, outcome packings with several proofs to merge: merged, failed, late, skipped
lean_beacon_pq_proof_verification_seconds kind verifying one aggregate's proof or one block's merged proof
lean_beacon_pq_gossip_arrival_offset_seconds kind how far into its vote's slot an attestation or aggregate arrived

Conflict resolutions on pq-devnet-2

  • crates/net/rpc/src/beacon/pq_aggregation.rs: prove_committee returns (Arc<PooledPqAggregate>, Duration, Option<proof::Plan>), feeding both metrics::observe_pq_committee_proof / inc_pq_committee_proofs and pq_events duty/operation hooks.
  • crates/blockchain/src/pq_attestation_packing.rs: pack_attestations records both metrics::observe_pq_merge / inc_pq_merges and the pq_events::proof::Plan / duty::remember_result lifecycle.
  • crates/blockchain/state_transition/src/beacon/gossip/pq.rs: Uses a single Instant::now() timer around verify_aggregates for both observe_pq_proof_verification("aggregate", elapsed) and pq_events::gossip::record_current_proof_verify_ns.
  • docs/metrics.md: Appends ### PQ Aggregation Timing cleanly alongside ### PQ Measurement Exporter Health without overlapping feat(telemetry): emit PQ events at wire 0.5 (pq-measurement-spec, registry 0.10.0) #972.

Related Issues / PRs

Verification

  • cargo fmt --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • Unit tests across ethlambda-metrics, ethlambda-state-transition, ethlambda-p2p, ethlambda-rpc, and ethlambda-blockchain

Ports #941 (step 1 of #938) onto pq-devnet-2, exposing the 11 PQ
aggregation, merge, verification, and arrival series on `/metrics`, all
lazily registered so a network without PQ shows none:

- Committee proofs, by aggregator seat (`rpc`'s seat prover): leanVM's
  proving time, how far into the slot the proof was ready, its
  signatures and size, and `lean_beacon_pq_committee_proofs_total` by
  outcome (`proved`, `late`, `failed`, `already_proven`, `unproved`).
- Block-proof merges, by phase (`ahead` of the slot, at `production`):
  duration, children and merged size when the merge ends, in time or
  not, and `lean_beacon_pq_merges_total` by outcome (`merged`, `failed`,
  `late`, `skipped`).
- `lean_beacon_pq_proof_verification_seconds`, by kind: an `aggregate`'s
  proof in the gossip rules, a `block`'s merged proof in `process_stark`.
- `lean_beacon_pq_gossip_arrival_offset_seconds`, by topic kind: every
  attestation and aggregate that decodes, from the start of its own
  slot.

Preserves pq-devnet-2's OTLP PQ telemetry hooks (`ethlambda_telemetry::pq_events`)
across `pq_aggregation`, `pq_attestation_packing`, and `gossip::pq`,
sharing the proof-verification timer between Prometheus and OTLP.
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

AI security review: 1 finding(s) to check

Reviewed by Opus, GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
GLM (error, see the run log) did not finish; Opus, GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

# Finding Severity Status Found by Where
M1 PQ committee-proof counter skips committees when a seat wakes after its deadline (also M2) low Bug GPT, Kimi, DeepSeek (3/4) crates/net/rpc/src/beacon/pq_aggregation.rs:151
Details

M1. PQ committee-proof counter skips committees when a seat wakes after its deadline (low, logic)

  • Trigger: The PQ aggregation scheduler reaches a seat after that seat's broadcast deadline, for example after the previous seat's blocking proof overruns, while pq_signature_pool().aggregators(slot) is non-empty and the seat has committees due to prove.
  • Mechanism: This branch returns at line 165 before the accounting loop at lines 379-389, which is the only place metrics::inc_pq_committee_proofs is called. The telemetry branch can enumerate committees_at_seat and mark their duties missed, but the new Prometheus counter never records their unproved outcome.
  • Impact: lean_beacon_pq_committee_proofs_total underreports missed aggregator duties, so operators and dashboards cannot see committees that were due to be proved when a seat was skipped after its deadline.
  • Judge: A seat reached after its deadline returns before the sole committee-counter update. With subscribed duties and unproved collected inputs, those committees contribute no unproved outcomes. The scheduler awaits seats sequentially and does not time out an in-progress proof, so an earlier overrun can trigger this. The omission affects the newly added metric.
Duplicates folded into another finding: 1
# Same as Finding Found by Where
M2 M1 Count unproved committees when a seat starts after its deadline GPT, Kimi crates/net/rpc/src/beacon/pq_aggregation.rs:387

Cost of this review: ~$1.67 of a $30 budget (estimated from token counts).

…kes past deadline

Addresses security review finding M1 on PR #973:

When an earlier aggregator seat's blocking proof overran past a later
seat's broadcast deadline (`budget == 0`), `prove_seat` returned early
before updating `lean_beacon_pq_committee_proofs_total`. Unify the
zero-budget case into `prove_seat`'s `spawn_blocking` pass (`budget =
deadline_ms.saturating_sub(now_ms())`) so:

- `head(&store)` always runs on the blocking pool rather than the async
  runtime thread, and seats this node does not hold return quietly.
- Committees an earlier seat already proved in full are still counted as
  `already_proven` (`suppressed`/`already_covered`), zero-input
  committees close as `no_inputs`, and committees with unproved
  collected signatures stop at the deadline check without invoking
  leanVM and are counted as `unproved` on `/metrics` (with
  `available_signers` attached to every abandoned telemetry duty).
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

AI security review: 2 finding(s) to check

Reviewed by Opus, GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
GLM (error, see the run log) did not finish; Opus, GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

# Finding Severity Status Found by Where
M1 Peers can inject arbitrary samples into lean_beacon_pq_gossip_arrival_offset_seconds before any validation low Bug Opus (1/4) crates/net/p2p/src/beacon/pq.rs:423
M2 PQ committee-proof total counts collected proof groups rather than every seated committee low Bug DeepSeek (1/4) crates/net/rpc/src/beacon/pq_aggregation.rs:214
Details

M1. Peers can inject arbitrary samples into lean_beacon_pq_gossip_arrival_offset_seconds before any validation (low, logic)

  • Trigger: Any directly connected gossip peer sends PQ beacon_attestation_{subnet} or beacon_aggregate_and_proof messages that decode but carry a chosen data.slot (for example slot 0 or a long-past slot) and junk signatures. They arrive through triage in crates/net/p2p/src/beacon/pq.rs.
  • Mechanism: The arrival offset is observed right after SSZ decode, before aggregate_cheap_checks / attestation_cheap_checks look at the slot window, the seen caches or any signature. The offset is computed from the message's own claimed data.slot. A slot far in the past gives an offset of roughly (now - genesis), which can be months of seconds; a future slot gives 0. These messages then fail the cheap checks with mostly Ignore verdicts, which do not penalize the peer, so it can keep sending distinct ones (each has its own gossipsub message id) without being scored down.
  • Impact: The histogram's _sum and upper buckets can be skewed at will. Any dashboard showing mean or quantile vote-arrival timing (the purpose of pq-devnet-1: expose aggregation timings (committee proof, recursive merge, aggregate arrival) #938 step 1) becomes unreliable on a node exposed to a misbehaving peer. Consensus and fork choice are not affected.
  • Judge: The histogram records the peer-supplied slot before any cheap or signature checks. Old slots produce offsets approaching time since genesis, while future slots produce zero. Suitable stale/future messages receive Ignore, and changing payload bytes changes their message IDs, bypassing deduplication. Although counting all decoded traffic is explicitly documented, the claimed histogram contamination

M2. PQ committee-proof total counts collected proof groups rather than every seated committee (low, logic)

  • Trigger: A validator client subscribes this node's aggregator to a committee whose slot collects no signature before the seat deadline, or a reorg/competing attestation-data root causes two collected groups for one committee.
  • Mechanism: all_groups is PqSignaturePool::collected, which only returns raw entries created by insert; a subscribed committee with no received attestation has no raw entry and is absent from all_groups. The new counter derives every outcome from committees = all_groups.len() and unproved = committees - already_proven - proved - failed - late, so no metric is emitted for no-input committees, while multiple data-root groups for the same committee are each counted as another committee.
  • Impact: lean_beacon_pq_committee_proofs_total will understate the number of aggregator duties scheduled when committees are quiet and can overstate them for multi-data-root cases, misleading operators about aggregation health.
  • Judge: Both counting errors hold. Subscribing creates no raw signature group, so a seated committee receiving no signatures contributes zero to every counter outcome. Conversely, raw groups are keyed by attestation-data root as well as committee, so competing roots for one committee contribute multiple outcomes. The new counter therefore measures collected proof groups, not the due committees advertised

Cost of this review: ~$1.63 of a $30 budget (estimated from token counts).

…mittees

Addresses the two findings of the second security review on PR #973.

M1: `lean_beacon_pq_gossip_arrival_offset_seconds` was observed right
after SSZ decode, from the slot the message itself names. A peer could
send votes naming any slot with junk signatures, have them ignored at no
cost to its score, and write the samples it liked (a slot long past
reads as the time since genesis). The offset is now observed in
`PqValidated::forward` on `Accept` only, still measured from when the
message came off the wire: an accepted vote is in the current or the
previous epoch, signed by its validator and the first for its key.

M2: `lean_beacon_pq_committee_proofs_total` derived every outcome from
the collected signature groups, so a seated committee that collected no
signature left no trace. It is now counted once as `no_inputs`. The
counter's unit is stated as what it counts, the aggregate (one
committee's signatures on one vote, which is what one proof covers): a
committee whose attesters split over two votes is due one per vote, and
`proved` plus `late` stays equal to the sample count of
`lean_beacon_pq_committee_proof_seconds`. The seat's summary log reports
`committees` as the seated committees, with `aggregates` and `no_inputs`
beside it.
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

AI security review: 1 finding(s) to check

Reviewed by Opus, GPT, Kimi, DeepSeek. A judge model checked every one of the findings against the code.
GLM (error, see the run log) did not finish; Opus, GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

# Finding Severity Status Found by Where
M1 New rpc test can fail at random: it makes absolute assertions on an unlabelled global histogram that a parallel test als low Bug Opus, GPT, Kimi (3/4) crates/net/rpc/src/beacon/pq_aggregation.rs:642
Details

M1. New rpc test can fail at random: it makes absolute assertions on an unlabelled global histogram that a parallel test also writes to (low, other)

  • Trigger: Running the rpc crate's unit tests with plain cargo test (the Makefile's cargo test --locked --profile release-fast and CI's cargo test --locked). libtest runs a_seats_proving_pass_is_timed_and_counted and a_split_committee_counts_per_vote_and_a_quiet_one_as_no_inputs on parallel threads in one process. This only affects test code.
  • Mechanism: series_value reads Prometheus' process-wide default registry. lean_beacon_pq_committee_proof_size_bytes and lean_beacon_pq_committee_proof_signatures have no labels, so every prove_seat call that makes a proof observes them, whatever the seat. a_split_committee_counts_per_vote_and_a_quiet_one_as_no_inputs calls prove_seat at position 3 and makes two proofs, so the size histogram's count goes up by 2. a_seats_proving_pass_is_timed_and_counted asserts the absolute count is Some(1.0). If the split test's proofs land first, the count reads 3 and the assertion fails. The same test's delta check signatures - signatures_before == members.len() breaks too if the other test's proofs land between its two reads.
  • Impact: Whether the unit tests pass depends on thread scheduling, so CI can fail on unrelated changes. Node behaviour is not affected.
  • Judge: Both reported mechanisms hold. The tests share process-global, unlabeled proof histograms without isolation or serialization. If the split-committee test records its two proofs before the absolute size-count assertion, that assertion sees 3 instead of 1; observations between the signature-sum reads also corrupt the delta. This is a newly introduced test-reliability bug, not a node-runtime issue. C

Cost of this review: ~$2.71 of a $30 budget (estimated from token counts).

Addresses the third security review's finding M1 on PR #973.

`lean_beacon_pq_committee_proof_size_bytes` and
`lean_beacon_pq_committee_proof_signatures` carry no `position` label,
and the metrics are the process's, so every test that makes a proof
through `prove_seat` writes the same two series.
`a_seats_proving_pass_is_timed_and_counted` asserted the size
histogram's absolute count and a signature sum delta, and
`a_split_committee_counts_per_vote_and_a_quiet_one_as_no_inputs`, added
with the previous fix, makes two proofs on another libtest thread:
whether the first passed depended on which ran when.

Every test that drives `prove_seat` now holds one lock, and the
unlabelled series are read as what the pass adds instead of as absolute
values. Test code only.
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

AI security review: 0 finding(s) to check

Reviewed by Opus, GPT, Kimi, DeepSeek.
GLM (error, see the run log) did not finish; Opus, GPT, Kimi, DeepSeek reviewed the whole PR. Comment /review continue to retry, with a new budget; reviewers that finished are reused.

No findings to check.

Cost of this review: ~$2.18 of a $30 budget (estimated from token counts).

@pablodeymo
pablodeymo merged commit 05e43ba into pq-devnet-2 Dec 4, 2026
14 checks passed
@pablodeymo
pablodeymo deleted the feat/pq-devnet-2-aggregation-metrics branch December 4, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant