Skip to content

perf(pq): publish each attestation as soon as it is signed - #906

Merged
MegaRedHand merged 1 commit into
pq-devnet-0from
pq/stream-attestations
Nov 26, 2026
Merged

MegaRedHand merged 1 commit into
pq-devnet-0from
pq/stream-attestations

Conversation

@MegaRedHand

@MegaRedHand MegaRedHand commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

🗒️ Description / Motivation

ethlambda's attestations are still the last to arrive on pq-devnet-0 after #891. In Dora's epoch 710, ethlambda's median vote lands at 2.6–3.1 s; the other clients land at 1.4–2.1 s.

Profiling both ethlambda boxes found the reason: signing is CPU-bound.

  • A leanXMSS signature costs about 0.3 s of a core. leanVM grinds the one-time signature's randomizer until the message digest is a codeword. That takes about a million Keccak permutations on average: a digest is a codeword with probability 2⁻¹² × P(58 two-bit digits sum to 106) ≈ 9.5·10⁻⁷. The Merkle path, which the code comment called "roughly 10 ms", is about 5% of it.
  • The cost varies a lot. The trial count is geometric, so one signature in ten takes more than 2.3× the mean and one in a hundred more than 4.6×.
  • The validator client saturates the host. Each node has ~20 attestations and ~15 PTC votes per slot. The client uses 6–8 of the 8 vCPUs for 1–2.5 s after every block, about 10 core-seconds per slot. The ~0.85-core average over a day hid this.
  • The batch waits for its slowest signature. ethlambda_validator_signing_duration_seconds (attestation batch) averages 1.75 s on geth-1 and 1.36 s on geth-2. publication_delay_seconds averages 2.68 s and 2.28 s.
  • Other clients publish each vote as it is signed. Every client has the same 19.5 votes per node per slot. In Dora's 100 ms buckets, the others' first votes appear at 1.05–1.3 s and the rest spread over 0.6–2 s. Each ethlambda node's votes all land in one bucket, around 2.55 s.

This PR publishes each PQ attestation as soon as its signature exists, so the median vote goes out about halfway through the signing rather than after the slowest one.

What Changed

  • crates/validator/src/pq.rs
    • sign_each(requests, signed) hands each signature to a callback as soon as it exists, with its position in the batch.
    • sign_streamed(requests) runs sign_each on tokio's blocking pool, starts at once, and returns a channel of answers.
    • Leaves are recorded exactly as before: all of the batch's leaves with one write and one flush, before any signature exists (claim_batch, split out of sign_batch).
    • The sign_batch doc now says what a signature really costs, and why.
  • crates/validator/src/attestation.rs
    • The PQ branch of attest_with moves to publish_pq_as_signed.
    • Each submission carries whatever was signed by the time the previous one answered: the first vote alone, then whatever came in meanwhile. A slow node therefore costs fewer, larger requests, not a queue of small ones.
    • Each submission logs Published attestations with its count and how many are still pending.
    • Pre-PQ forks keep the single batch.
    • AttestationService::with_clock gives the service the slot clock for the new metric.
  • crates/validator/src/metrics.rs, docs/metrics.md
    • New histogram ethlambda_validator_attestation_vote_delay_seconds, one observation per accepted vote. Its median is the median vote's, the number Dora compares clients by. It is observed on every fork.
    • publication_delay_seconds stays once per slot: from PQ it is the slot's last vote.
    • signing_duration_seconds stays the time until the last signature exists, so before and after stay comparable.
  • crates/validator/src/lib.rs: the duty loop passes the clock.

Correctness / Behavior Guarantees

  • Slashing protection is unchanged. The whole batch is recorded before any signature exists. The leanXMSS leaf record still claims every leaf with one flush before signing.
  • One validator's failure costs only its own vote. A failed signature is logged and counted, as before.
  • A failed submission costs its own votes, and the rest go on. attest_with returns the error only when no vote was accepted at all, so the duty loop's failure accounting still fires for a node that refuses everything.
  • A signing task that dies mid-batch closes the channel. The votes that never answered are logged and counted as signing failures.
  • An abandoned duty (the slot-end timeout) drops the receiver. Signatures still in flight are discarded, and their leaf is spent either way, as before.
  • Leaf order is not a promise. Votes go out in the order their signatures finish, not duty order. The node checks and publishes each submission in its own order.

Tests Added / Run

  • pq::tests::signing_one_by_one_answers_each_request_once_in_its_place: refusals stay refusals, every position is answered once, and the bytes match sign_batch's (signing is deterministic).
  • pq::tests::a_streamed_batch_answers_every_request_and_then_closes, including the empty batch.
  • make fmt, make lint clean.
  • Local A/B devnet: see below.

Related Issues / PRs

Local devnet (all four PRs together, A/B)

Run with ethereum-package pq (7a29d69e), PQ at genesis, on an arm64 Mac:

Five epochs ran, and the three nodes justified and finalized together (just=3 fin=2 at slot 132, one head). Justification needs more than 107 of the 160 votes, so the new client's streamed votes counted. There were no warnings on any node beyond startup notices, and zero signing, attestation, PTC or envelope failures on either client.

new baseline
vote delay (per vote) p50 / p90 0.49 s / 0.88 s 0.70 s / 1.05 s
submissions per slot (median) 2 1
first PTC publish minus last attestation, p50 (min) +0.29 s (+0.03 s) +0.01 s (−0.61 s)
envelope after its block, p50 / mean / max 0.05 / 0.11 / 0.41 s (44 proposals) 0.15 / 0.21 / 0.69 s (55)
next epoch's PTC duties fetched after the slot's duties, +6.2–6.5 s at the refresh, +0.14–0.18 s

On this small network each client signs only about two votes per slot, so the streaming gain is smaller than on pq-devnet-0's twenty. The node there answers the early PTC request in 0.15 s, so the 2 s state advance only shows at pq-devnet-0's 10,000 validators. Both effects are expected to be larger on the real devnet.

A leanXMSS signature costs about 0.3 s of a core on the devnet's hosts
(leanVM grinds the one-time signature's randomizer through about a million
Keccak permutations), and the time varies several fold from one signature to
the next. With twenty votes per node per slot, the batch kept the host busy
for a second or more, and every vote waited for the slowest. Other clients
publish each vote as it is signed.

pq::sign_each / sign_streamed hand each signature on as soon as it exists,
after the batch's leaves are recorded with one flush as before. The PQ
attestation path submits whatever has been signed by the time the previous
submission answered. A failed submission costs its own votes; the slot's
error is returned only when none was accepted.

New histogram ethlambda_validator_attestation_vote_delay_seconds, one
observation per accepted vote; publication_delay_seconds stays the slot's
last vote and signing_duration_seconds the time until the last signature.
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