Skip to content

perf(pq): merge a block's attestation proofs ahead of its slot - #914

Merged
MegaRedHand merged 4 commits into
pq-devnet-0from
pq/merge-proofs-ahead
Nov 27, 2026
Merged

MegaRedHand merged 4 commits into
pq-devnet-0from
pq/merge-proofs-ahead

Conversation

@MegaRedHand

@MegaRedHand MegaRedHand commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

🗒️ 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:

proposer first seen (median) arrival p50
lighthouse 214 ms 358 ms
prysm 162 ms 388 ms
teku 280 ms 422 ms
silver 168 ms 422 ms
grandine 196 ms 470 ms
lodestar 771 ms 905 ms
ethlambda 1102 ms 1235 ms
nimbus 1387 ms 1601 ms

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):

  • ~0.17 s: before production collects the payload build started ahead of the slot.
  • 575 ms (533–656): merging the packed aggregates' proofs into the block's one proof on the sidecar.
  • ~0.08 s: assembling the block, which is then produced at +0.84 s.
  • 0.18 s, with a tail of 0.6–0.8 s: the validator client signing and publishing, so the block is on gossip at +1.02 s.

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 when ba522d44c starts S's payload build.

What Changed

  • New crates/blockchain/src/pq_attestation_packing.rs
    • pack_attestations, merge_budget and the one-merge-at-a-time MERGE_PERMIT move here from rpc/src/beacon/pq_proposal.rs. Three things change:
      • The result (PackedAttestations) says whether it is complete, i.e. everything the selection picked rather than the one-committee fallback. It also records the pool aggregates it was packed from.
      • It takes a PermitWait. Production still tries the permit once. A packing ahead of the slot waits for it, unless that packing is abandoned meanwhile.
      • An abandoned packing gives up quietly, at debug level.
    • PreparedPqAttestations is shared by the chain actor and block production, like PreparedPayloads. 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.

        • Starting the same slot and head again is a no-op.
        • Another slot or head replaces the packing and abandons the old one. An abandoned packing does not start its merge; one already merging finishes, unheard.
        • A packing whose state cannot be read or advanced is released, so a later start can retry.
      • take(store, slot, head_root, budget) removes the packing and waits up to budget for one still running. It returns the result only when all of these hold:

        • it is for that slot and head;
        • it is complete;
        • the pool's candidates for the slot are still the aggregates it was packed from, compared by identity.

        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_build also 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-payload alone does not pack: it would merge every slot for blocks this node does not propose.
  • crates/net/rpc/src/beacon/pq_proposal.rs: produce takes the attestations prepared for its own slot and head, waiting up to the whole merge budget. Otherwise it packs them itself, exactly as before.
  • Wiring: PayloadPreparation::prepared_pq_attestations, the RPC handles and an Extension, created in main.rs next to PreparedPayloads.
  • docs/beacon_pq.md: the Proposing section describes the packing ahead of the slot. It is removed from the known gaps.

Correctness / Behavior Guarantees

  • Same block, earlier. Both paths run the same selection and merge on the same inputs: the same head state advanced to the same slot, and the same pool. take checks the pool's candidates have not changed since the packing, so an aggregate that arrived late is not left out. Production packs again instead.
  • Every mismatch falls back to today's path. That covers:
    • another head at production (the parent came late, or a reorg);
    • aggregates that arrived or changed since the packing;
    • a packing that fell back to one committee (its merge failed or missed its budget);
    • a packing whose state would not advance;
    • no packing at all (not our proposer, no engine).
  • A merged proof the block rejects is still caught. assemble_pq_block runs process_stark on whatever proof is packed and rebuilds the block without attestations if it fails, as before.
  • One merge at a time on the sidecar, as before: both paths share the permit. A packing nobody will use releases it or never takes it.
  • No double merge at production. A packing still running is waited for, up to the merge budget, rather than run a second time. Production could not merge sooner anyway, since the running packing holds the permit. A packing that never started closes its channel and is skipped at once.
  • The packing runs only when this node's proposer holds the next slot. On pq-devnet-0 that is about one slot in sixteen per node, at ~0.6 s of sidecar time each. It runs after the node's own aggregation proving for the previous slot is done.

Tests Added / Run

  • pq_attestation_packing::tests covers:
    • candidates are compared by identity, in any order;
    • a complete packing is taken once, for its own slot and head;
    • a packing production does not use is abandoned;
    • a partial packing is not taken;
    • a packing from other candidates is not taken;
    • a packing under way is waited for up to the budget;
    • a packing that never started gives nothing at once;
    • a packing is claimed once per slot and head;
    • an abandoned packing does not take the merge permit.
  • make fmt and make lint are clean. CI is green.
  • Local devnet (ethereum-package 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.
    • All three justified on one head. The PR node logged no warnings beyond the two config ones at startup.
    • 46 of 46 of its blocks took the packing made ahead, every one complete. Each block was produced 0.084 s into the slot (p50; max 0.091 s).
    • This does not show the gain. 160 validators make one committee per slot, so a local block carries one aggregate and there is nothing to merge: the packing took 1 ms. Here the baseline node also produces at 0.084 s. The ~575 ms merge only exists with pq-devnet-0's two committees, so the gain will show there after deploy.

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:

  • What it costs today. If packing and aggregating a mainnet block's attestations takes tens of milliseconds, there is nothing to win. If it is hundreds, the same pack-ahead-and-take shape applies. It needs measuring on a mainnet follower's proposals, e.g. from the produceBlockV3/V4 timing, before porting anything.
  • The inclusion delay is one slot, not two. A block at S on main packs 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

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.
@MegaRedHand
MegaRedHand merged commit 8a12777 into pq-devnet-0 Nov 27, 2026
14 checks passed
@MegaRedHand
MegaRedHand deleted the pq/merge-proofs-ahead branch November 27, 2026 01:36
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