Repository navigation
perf(pq): publish each attestation as soon as it is signed - #906
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🗒️ 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.
ethlambda_validator_signing_duration_seconds(attestation batch) averages 1.75 s on geth-1 and 1.36 s on geth-2.publication_delay_secondsaverages 2.68 s and 2.28 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.rssign_each(requests, signed)hands each signature to a callback as soon as it exists, with its position in the batch.sign_streamed(requests)runssign_eachon tokio's blocking pool, starts at once, and returns a channel of answers.claim_batch, split out ofsign_batch).sign_batchdoc now says what a signature really costs, and why.crates/validator/src/attestation.rsattest_withmoves topublish_pq_as_signed.Published attestationswith itscountand how many are stillpending.AttestationService::with_clockgives the service the slot clock for the new metric.crates/validator/src/metrics.rs,docs/metrics.mdethlambda_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_secondsstays once per slot: from PQ it is the slot's last vote.signing_duration_secondsstays 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
attest_withreturns 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.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 matchsign_batch's (signing is deterministic).pq::tests::a_streamed_batch_answers_every_request_and_then_closes, including the empty batch.make fmt,make lintclean.Related Issues / PRs
pq-devnet-0; each stands alone:pq-devnet-0merged back in.Local devnet (all four PRs together, A/B)
Run with ethereum-package
pq(7a29d69e), PQ at genesis, on an arm64 Mac:pq-devnet-0(ba522d44c, 64 validators).ethpandaops/teku:pq-devnet-0, 32 validators).Five epochs ran, and the three nodes justified and finalized together (
just=3 fin=2at 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.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.