Repository navigation
perf(pq): merge a block's attestation proofs ahead of its slot - #914
Merged
Merged
Conversation
Block production merged the packed aggregates' proofs into the block's one proof when the validator client asked for the block, at the slot's start: about 0.58 s on the sidecar (533-656 ms over geth-2's 19 proposals), on the path of every block this node proposed. ethlambda's blocks reached Dora's nodes at a 1.24 s median against 0.36-0.47 s for Lighthouse, Prysm, Teku, Silver and Grandine, whose blocks carry the same merged proof (one attestation over both committees, ~185 KB). Nothing the merge reads is new at the slot: a block at S packs aggregates from S-2 and earlier, against the head's state advanced to S. So when the chain actor starts S's payload build a third of a slot ahead, it now also starts packing S's attestations (PreparedPqAttestations::start), and production collects the result when it is for the head it builds on, waiting for one still running up to the merge budget. Anything else (another head, a packing that fell back to one committee, none at all) packs at production as before. pack_attestations, merge_budget and the one-merge-at-a-time permit move from rpc's pq_proposal to the new ethlambda_blockchain::pq_attestation_packing, unchanged except that the result says whether it is complete.
…and keep the permit for the packing that counts Review round 1 on the ahead-of-slot packing: - Production takes the prepared result only when the pool's candidates are the ones it was packed from (held Arcs compared by identity), so an aggregate that arrived or was replaced since, or a pool that was empty then, is packed at production instead of being dropped. - A packing replaced by another (the head moved) is abandoned and does not start its merge; one ahead of the slot waits for the merge permit within its budget instead of falling back at once. Production still tries the permit once, as before. - Production waits for a packing under way for half its merge budget at most, leaving it time to pack itself. - Only for a proposer with a registered fee recipient, not every slot --always-prepare-payload builds for. - A packing that could not start releases its claim, so it can be tried again; production takes the result instead of cloning it; the head state is read in the packing's task, not on the chain actor.
…tching one for the whole merge budget Review round 2 on the ahead-of-slot packing: - take() abandons every packing it does not hand over (this slot on another head, an earlier slot, one it gave up waiting for), so it does not take the merge permit from production's own merge. - Production waits for a packing under way for this slot and head up to the whole merge budget: it computes what production would and holds the merge permit production would need, so giving up early could only leave the block with one committee's attestation. - An abandoned packing returns quietly (debug), without the one-attestation fallback warning or the 'packed ahead' line. - docs/beacon_pq.md describes packing ahead and drops it from the known gaps.
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 blocks reach the network last but one on pq-devnet-0. Dora's median block arrival by proposer over slots 24420–24535:
Propagation is not the cause: Dora first sees our blocks within milliseconds of the node publishing them. The time is spent building them. geth-2's node log over its 19 proposals since #906–#909 deployed (medians):
proofon the sidecar.The merge is the biggest piece, and it runs when the validator client asks for the block at the slot's start. Our competitors' blocks carry the same thing. Prysm's and Teku's have one attestation over both committees (
committee_bits=0x0300, ~312 voters) with a ~185 KB merged proof, and still go out ~150–290 ms into the slot, so they merge earlier. Lodestar, whose blocks carry two attestations, lands near us at ~0.9 s.Nothing the merge reads is new at the slot. A block at slot S packs aggregates from S −
MIN_ATTESTATION_INCLUSION_DELAY_PQ(2) and earlier. This node holds those from about half way through S − 2 (aggregates go out ~6.5 s into their slot). They are selected against the head's state advanced to S, and that head is normally settled a third of a slot before S. That is also whenba522d44cstarts S's payload build.What Changed
crates/blockchain/src/pq_attestation_packing.rspack_attestations,merge_budgetand the one-merge-at-a-timeMERGE_PERMITmove here fromrpc/src/beacon/pq_proposal.rs. Three things change:PackedAttestations) says whether it iscomplete, i.e. everything the selection picked rather than the one-committee fallback. It also records the pool aggregates it was packed from.PermitWait. Production still tries the permit once. A packing ahead of the slot waits for it, unless that packing is abandoned meanwhile.PreparedPqAttestationsis shared by the chain actor and block production, likePreparedPayloads. It holds one packing, the latest started.start(store, head_root, slot)registers the packing for(slot, head_root)and spawns it. The spawned task reads the head state and advances it to the slot (advance_for_proposal, so an epoch-start slot reuses the epoch precompute's state) on the blocking pool, then packs and merges.take(store, slot, head_root, budget)removes the packing and waits up tobudgetfor one still running. It returns the result only when all of these hold:Whatever production does not use is abandoned, so it does not take the merge permit production may need next. That covers another head, an earlier slot, a timeout, or a packing that never started. A packing for a later slot is the next proposal's and is left alone.
crates/blockchain/src/payload_attributes.rs:start_payload_buildalso starts the packing when the proposal slot is PQ and the slot's proposer registered a fee recipient here. That is a third of a slot ahead, and again whenever the head changes.--always-prepare-payloadalone does not pack: it would merge every slot for blocks this node does not propose.crates/net/rpc/src/beacon/pq_proposal.rs:producetakes the attestations prepared for its own slot and head, waiting up to the whole merge budget. Otherwise it packs them itself, exactly as before.PayloadPreparation::prepared_pq_attestations, the RPC handles and anExtension, created inmain.rsnext toPreparedPayloads.docs/beacon_pq.md: the Proposing section describes the packing ahead of the slot. It is removed from the known gaps.Correctness / Behavior Guarantees
takechecks the pool's candidates have not changed since the packing, so an aggregate that arrived late is not left out. Production packs again instead.assemble_pq_blockrunsprocess_starkon whatever proof is packed and rebuilds the block without attestations if it fails, as before.Tests Added / Run
pq_attestation_packing::testscovers:make fmtandmake lintare clean. CI is green.pq): this branch together with the fix(p2p): park votes for a block still importing, and check them again once it lands #899 port, next to a pq-devnet-0 node (perf(pq): publish each attestation as soon as it is signed #906–perf(pq): sign a proposal's envelope alongside its block #909) and Teku.Open question: the same for
main, for BLS aggregation?main's beacon block production also packs the block's attestations at request time (block_production's packing, with BLS aggregation of the pool's attestations into the block's aggregates), after #894 moved only the payload build ahead. Should it get the same treatment? Two things decide it:mainpacks S − 1's attestations, and S − 1's aggregates arrive two thirds of the way into S − 1, which is after the payload build starts (a third of a slot ahead of S). So a packing started there would miss the last slot's aggregates. It would have to be topped up at S rather than taken as is, unlike PQ's, which has a whole slot of margin.Related Issues / PRs
ba522d44c(the payload build a third of a slot ahead), which this extends to the attestation merge.pq_proposal.rs's prover to in-process leanVM (pq_aggregation.rs) and will need this merged back in. The move into the blockchain crate keeps the packing code itself as it was.