Skip to content

fix(p2p): park votes for a block still importing, and check them again once it lands - #899

Open
MegaRedHand wants to merge 4 commits into
mainfrom
fix/park-votes-for-unimported-blocks
Open

MegaRedHand wants to merge 4 commits into
mainfrom
fix/park-votes-for-unimported-blocks

Conversation

@MegaRedHand

@MegaRedHand MegaRedHand commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Validators vote as soon as the slot's block reaches them, so the first votes for every block reach this node while it is still importing that block: waiting for its custody columns, or running its state transition. The beacon_attestation_{subnet_id} and beacon_aggregate_and_proof stateful checks read the voted block's own cached post-state, so in that window they answer Ignore(StateUnavailable), or Ignore(UnknownBlock) if the block is not stored at all. The vote was reported at once and was then lost for good:

  • gossipsub did not relay it;
  • it never reached the attestation pool an aggregator on this node reads;
  • no other copy came later, since every peer sends the same message id.

Measured on an 8-participant kurtosis devnet (lighthouse, prysm, teku and ethlambda BNs; fulu; 12 s slots; imports of ~130 ms) by recording single_attestation events from all eight BNs for 63 slots:

BN votes that arrived before its own import of the block lost
ethlambda ×3 134–200 each 61–78%
lighthouse ×2, prysm ×2, teku 31–416 each 0

That is 5 to 8% of every subnet vote each ethlambda node received, and lean_beacon_gossip_validation_total{reason="state_unavailable"} matched the count. No participation was lost there, only because other aggregators covered each committee.

What lighthouse and prysm do

  • Lighthouse (stable 57c2abc1): an UnknownHeadBlock attestation or aggregate goes into the reprocess queue with no verdict sent to gossipsub. It stays there up to 12 s, with at most 16,384 queued, and is released on that root's BlockImported to run the checks again, so an accepted vote propagates as the original message. It also asks sync to fetch the block. A block counts as known once it is in fork choice or in early_attester_cache, which holds a block that has its data and its post-state but is not yet written to the database.
  • Prysm (develop e625ddd1): returns ValidationIgnore and parks the vote: at most 32,768, dropped after an epoch. After importing the block it checks the parked votes in a batch, pools them and publishes them itself. It also asks the votes' senders for the block by root.

This change: lighthouse's shape

  • Park on the verdict path. When the first verdict for a subnet attestation or an aggregate is Ignore(UnknownBlock | StateUnavailable), verdict::receive_verdict parks it under the voted block's root (beacon/parked_votes.rs) and reports nothing yet. A StateUnavailable for a block that has a stored state (imported earlier, its state since evicted from the cache, or landed during the check) is checked once more at once and not parked, since no release would come for it. The rules crate is unchanged.
  • Release on import. In the Imported arm, next to drain_sidecars_awaiting_parent, the chain actor sends the new BlockChainToP2P::block_state_ready(root) (beacon only). p2p runs the stateful checks of the root's parked votes again, in blocking batches of 64 votes of one kind. The batches run on a permit pool of their own (RECHECK_PERMITS, 32, pool="recheck"), so a released burst takes no permit from the votes arriving meanwhile, and a batch waits for a permit rather than coming back Ignore(Overloaded). Each vote's deadline is checked again right before its turn. Each vote then goes through the usual settle_message, report and forward.
  • Bounds:
    • A vote is parked once; its second check reports whatever it answers.
    • A vote still parked 2.5 s after it arrived gets its first verdict from a sweep that runs every 250 ms while anything is parked, and a released vote reached past 2.5 s gets it from its batch. Gossipsub drops a message awaiting its verdict 3.5 to 4.2 s after arrival (6 heartbeats of 700 ms of history), and a test pins the deadline plus one sweep interval under that.
    • At most 16,384 votes are parked, since nothing about a parked vote has been verified, and at most 2,048 of them aggregates, since an electra aggregate's bits can reach 16 KiB before its signature is checked (about 32 MiB at most, against about 256 MiB under the shared cap alone). Past either, a vote gets its first verdict at once.
  • Race. The import's signal can reach p2p before the verdict it would release: the check reads the store on a blocking thread, then the import caches the state and signals, and only then does the verdict arrive. p2p remembers the last 64 announced roots, and a vote for one of them is checked again at once.
  • Metrics:
    • lean_beacon_gossip_parked_votes_total{kind,result}, with result one of parked, full, rechecked or expired.
    • lean_beacon_gossip_parked_votes, a gauge of how many are parked now.
    • lean_beacon_gossip_validation_seconds for these two kinds now includes the wait.
  • Docs: docs/beacon_wire.md, docs/metrics.md and CLAUDE.md.

Left out

  • No block lookup. A vote for a block this node has never seen does not start a by-root fetch, which lighthouse and prysm do; it waits for gossip or sync to bring the block. On the devnet nearly every drop was state_unavailable (the block was already stored), against 3 unknown_block an hour. A lookup per unverified vote is also a fetch amplifier, so it is worth its own change.
  • No gloas payload requeue. Lighthouse also requeues a gloas vote whose payload envelope is unseen; payload_envelope_unseen is still reported at once here.

Overlap

#771 (batched gossip checks) rewrites the same stateful-check dispatch and keeps both Ignores, so whichever merges second has to bring parking across.

Testing

  • Unit tests for the queue (release by root, the race window, the cap, the aggregate cap, expiry, sweep scheduling, the deadline against gossipsub's window), for receive_verdict (what parks and what is reported at once, the immediate recheck, the sweep reporting expired votes), and for recheck (a recheck never parks again, and keeps its first outcome once past its deadline).
  • A chain-actor test that the signal is beacon-only, plus a fixture test (beacon-spec-tests) that importing a gloas block sends it for that root.
  • The test suite was not run locally; CI runs it. Not yet run on a live node either: the next step is redeploying the devnet's ethlambda BNs and checking that state_unavailable drops to near zero and that lean_beacon_gossip_verdict_expired_total stays at zero.

…n once it lands

A subnet attestation or aggregate whose vote block is not stored yet, or has
no cached post-state yet, was reported Ignore(UnknownBlock/StateUnavailable)
at once. Validators vote as soon as the block reaches them, so the first votes
for every block arrive while this node is still waiting for its columns or
running its state transition, and all of them were dropped: not relayed, not
pooled for an aggregator here, and never received again, since every peer
sends the same message id.

Such a vote is now parked under the voted block's root with its verdict
withheld, so gossipsub keeps holding the message. The chain actor's import
sends BlockChainToP2P::block_state_ready once the post-state is cached, and
p2p runs the parked votes' stateful checks again, in blocking batches of 64
on one permit each, reporting whatever they answer. This is lighthouse's
reprocess queue; the specification allows it.

Bounds: one retry per vote; 16,384 parked at most (lighthouse's cap); a vote
still parked 2.5 s after arriving gets its first verdict, inside gossipsub's
3.5 to 4.2 s window. A root announced just before its vote's verdict reaches
the actor is remembered (last 64 roots), so that vote is checked again at
once rather than waiting out its deadline.

New metrics: lean_beacon_gossip_parked_votes_total{kind,result} and
lean_beacon_gossip_parked_votes.
…rked aggregates

Review round 1 on #899:

- A released root started every batch at once, each taking a permit from
  the attestation pool with try_acquire. At the cap that is 256 batches
  against 128 permits: the batches past the last permit were ignored as
  overloaded, and the votes arriving meanwhile found no permit either,
  the loss parking is there to prevent. Rechecks now run on a pool of
  their own (RECHECK_PERMITS, 32, pool="recheck"), and a batch waits for
  a permit rather than failing without one.
- A vote's deadline was checked once, when its batch was spawned. It is
  now checked again right before each vote's turn, so one reached too
  late (after a long wait for a permit, or a slow batch) gets its first
  verdict, which can still reach gossipsub, instead of a second that
  cannot. "rechecked" now counts only votes whose checks ran again.
- The cap counted votes alone, and an electra aggregate parked before its
  signature check can carry 16 KiB of bits, so junk aggregates naming
  roots that never import could keep about 256 MiB resident. Aggregates
  now have a cap of their own, MAX_PARKED_AGGREGATES (2,048, two slots of
  an honest network's), about 32 MiB at most.
- A missing post-state was read as "still importing", but it also means a
  block imported earlier whose state has left the cache, for which no
  release ever comes. When the block has a stored state, the first check
  runs once more at once and the vote is not parked. That also covers a
  state that landed while the check ran.
- Tests: the aggregate cap, and a recheck that never parks again and
  keeps its first outcome once past its deadline.
Review round 2 on #899:

- Round 1's has_state probe ran outside guarded. has_state panics on a
  storage error (its reads expect rather than return one), so a failing
  read would have unwound the blocking task with no verdict sent, and
  gossipsub would have held the message until its cache evicted it. The
  probe and the second check now run inside the same guarded closure as
  the first, so a panic there is Ignore(Internal) like any other.
- A batch of rechecked votes was timed under its votes' own kind, mixing
  64-check batches with single first checks in the blocking-task
  histograms. Batches are timed under beacon_attestation_recheck and
  beacon_aggregate_and_proof_recheck.
- The deadline test compared against a literal 5 * 700 ms. Gossipsub's
  heartbeat and history length are now named constants (GOSSIPSUB_HEARTBEAT,
  GOSSIPSUB_HISTORY_LENGTH) that build_swarm and the test both read.
- Docs: docs/metrics.md says which votes the two ignore reasons count, that
  rechecked/expired include votes checked again at once, and the recheck
  timing labels; docs/beacon_wire.md and CLAUDE.md give the aggregate cap,
  the recheck pool and the evicted-state rule.

Not changed: a smaller cap for UnknownBlock votes. Those include votes
for a block held in memory while its columns arrive, the case this PR is
for, and the shared cap matches lighthouse's with no regression against
main.
MegaRedHand added a commit that referenced this pull request Nov 27, 2026
…n once it lands (#899)

Port of #899 (main) onto pq-devnet-0: a subnet attestation or aggregate
whose first stateful check answers Ignore(UnknownBlock | StateUnavailable)
is parked under the voted block's root with its verdict withheld, and
checked again once the chain actor's import announces that root's
post-state (BlockChainToP2P::block_state_ready). Bounded by a 2.5 s
deadline, one retry, 16,384 parked votes and 2,048 parked aggregates.

PQ: subnet attestations park too (parkable_root matches
PqValidated::Attestation). On pq-devnet-0 geth-1 ignored 1.3% of all votes
as unknown_block, about three a slot, and 28 of 46 of our aggregates left
votes out (2.3 on average) while Dora saw almost none of them arrive late.
PQ aggregates do not park: each carries a ~180 KiB proof, and they go out
more than half a slot after their block.
MegaRedHand added a commit that referenced this pull request Nov 27, 2026
…n once it lands (#899)

Validators vote as soon as the slot's block reaches them, so the first
subnet attestations and aggregates for a block reached this node while it
was still importing that block. Their stateful checks read the voted
block's cached post-state and answered Ignore(StateUnavailable) or
Ignore(UnknownBlock), and the vote was lost for good: not relayed, not
pooled, and no later copy, since every peer sends the same message id. On
an 8-participant devnet that was 5 to 8% of the subnet votes each
ethlambda node received; lighthouse, prysm and teku lost none.

Such a vote is now parked under the voted block's root with its verdict
withheld (beacon/parked_votes.rs, lighthouse's reprocess queue), and the
chain actor's import sends block_state_ready(root), on which p2p checks
the root's parked votes once more and settles, reports and forwards each
as usual. Rechecks run in 64-vote batches on a permit pool of their own
(32, pool="recheck"), so a big release takes no permit from the votes
arriving meanwhile. A vote is parked once, for at most 2.5 s (inside
gossipsub's ~4.2 s cache window), with at most 16,384 parked and 2,048 of
them aggregates; past either it gets its first verdict at once. A vote
whose block was imported but whose state has left the cache is checked
again at once and not parked, since no release would come for it. New
metrics count parked, full, rechecked and expired votes, and recheck
batches are timed under their own labels.

Applied as the PR's own diff against its merge base with main
(4989419), since its branch carries main merges. It applied without
conflicts.
MegaRedHand added a commit that referenced this pull request Nov 27, 2026
…ork (#902)

The validator client had no network config of its own: it ran on whatever
chain the first beacon node to answer was on, created its slashing
protection record on that chain, and followed an outdated fork schedule
without a word when every node served one. ethlambda validator now takes
an optional --network (mainnet, sepolia, hoodi, plataberget, or a
directory of published network files), resolved by the same network
module ethlambda beacon uses. With no flag nothing changes.

The network holds the chain's identity: a node whose preset, genesis time,
genesis validators root, slot duration or genesis fork version differs
from it is never the reference and is skipped like any incompatible node,
and startup fails once every configured node has answered and none is on
the network (it waits while one has not answered). The fork schedule only
warns, once an epoch, naming both values, since either side can be the
stale one: the beacon nodes, or --network's config (this binary's for a
built-in network, the directory's config.yaml otherwise). The named
network is only compared against; the client still runs on the reference
node's config, and list order still picks the reference among the nodes
on the network.

Applied as the PR's own diff against its merge base with main
(4989419), since its branch carries main merges, on top of #899.

Resolved against #871, #873, #874 and #877: ValidatorConfig and its
construction keep #874's distributed and #877's shut_down_when_slashed
next to this PR's network, with --broadcast where nightly has it; the
imports keep #871's GraffitiFile, and drop DEFAULT_GAS_LIMIT as #873 did;
chain_check::run takes #873's settings and this PR's network, and each
round hands over the gas limit schedule before the schedule warning.

This branch has not been deployed

No deployments
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