validator: re-fetch duties when their dependent root changes between epoch refreshes

Aperta
#827 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
api, backend

Direzione di ricerca

Start with crates/validator/src/lib.rs:400-452 and the duty fetch logic in crates/validator/src/duties.rs; the issue also points to preferences.rs:30-37 and slot_clock.rs:1-6. Compare the event driven and per-slot polling options, including reconnect handling and the fork-epoch PTC root decision, before choosing an approach. Done means changed dependent roots refresh affected duties and subscriptions in time, with the listed mock-node, head-event, reconnect, and lookahead tests passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The validator client fetches its duties at the first slot of each epoch and compares each schedule's dependent_root only then. Between two refreshes, nothing notices a reorg that changes a held schedule. The client reads no beacon node events, neither head nor chain_reorg.

Code references are at main @ 5d8628e9.

What happens today

  • refresh_epoch runs at an epoch's first slot (crates/validator/src/lib.rs:400-452). Each of its fetches compares the dependent root it gets with the one held, and replaces the schedule when it moved:
    • attester duties for this epoch and the next (duties.rs:124-136);
    • proposer duties for this epoch (duties.rs:174-180);
    • PTC duties for this epoch and the next (duties.rs:235-244).
  • The next comparison happens at the next epoch's first slot, or at the next slot when the refresh failed.
  • Sync committee duties carry no dependent root (duties.rs:64-67): the endpoint sends none, and the committee is fixed a period ahead. They are out of scope here.
  • PreferencesService already polls v2 proposer duties every slot, from the epoch before gloas. It follows a changed dependent root within a slot for the preferences it signs (preferences.rs:30-37). The duty loop's own proposer schedule does not, so the two can disagree until the next refresh.

Which reorgs this misses

beacon-APIs defines the dependent roots (ethereum/beacon-APIs master @ 6bc8c7bd, apis/validator/duties/{attester,ptc,proposer,proposer.v2}.yaml). ethlambda's node follows the same definitions (docs/rpc.md:304-308).

Schedule When the client fetches it Depends on What changes it after the fetch
Attester and PTC duties for the current epoch E Slot 0 of E-1, as lookahead, and again at slot 0 of E The last block of epoch E-2 A reorg that replaces a block at least 33 slots back
Proposer duties for E (v1) Slot 0 of E The v1 root is the last block of E-1. Since fulu, the proposers themselves come from the lookahead fixed by the end of E-2 Since fulu, the same deep reorg. Before fulu, a reorg of the boundary block
Attester and PTC duties for E+1, the lookahead Slot 0 of E The last block of E-1 A one-slot reorg at the boundary. Examples: a late block in E-1's last slot that the next proposer re-orgs, or one that arrives after the refresh

beacon-APIs says this of the current epoch's duties: "Duties should only need to be checked once per epoch, however a chain reorganization (of > MIN_SEED_LOOKAHEAD epochs) could occur, resulting in a change of duties. For full safety, you should monitor head_v2 events and confirm the dependent root in this response matches" (attester.yaml, ptc.yaml, proposer.v2.yaml).

So:

  • This epoch's schedules go stale only on a reorg deeper than an epoch. That is rare on a finalizing chain. It is expected during long non-finality, when competing forks more than an epoch long switch places.
  • The next epoch's attester and PTC schedules go stale on a one-slot reorg at the boundary, which is ordinary. The next refresh replaces them before any vote uses them. Two things act on them before that:
    • The subnet subscriptions the refresh leaves owing are computed from them (lib.rs:488-500). The corrected ones go out only after the next epoch's first proposal, so an aggregator in the first slots of E+1 may have joined the wrong subnet.
    • If the refresh at slot 0 of E+1 fails, the loop keeps the previous schedule (lib.rs:436-439) and attests from the stale lookahead.
  • The PTC of the gloas fork epoch. Per ptc.yaml, that PTC "is computed at the fork from effective balances that are updated at the end of the previous epoch, so its duties can change until the last slot before the fork". For that epoch alone, beacon-APIs moves the dependent root to the last block before the fork epoch, and adds: "Duties for this epoch are not available before the fork."
    • ethlambda's node answers the fork epoch's PTC before the fork by advancing a copy of its pre-gloas head to the fork epoch (crates/net/rpc/src/beacon/ptc.rs:194-204). It reports the root of the last block before the previous epoch, as for every other epoch (ptc.rs:115-118, :170-176). The duties can move during the last pre-gloas epoch while the root stays put.
    • The client fetches the fork epoch's PTC at the start of the last pre-gloas epoch (lib.rs:1258-1269). At the fork's first slot it keeps that schedule, because the root did not move (duties.rs:235-238).
    • It can hold a stale PTC schedule through the first gloas epoch, and per-slot re-polling would not catch it either. Hoodi and mainnet have not forked yet. The node half belongs in an issue of its own.

Why it matters

  • A stale attester schedule costs the epoch's vote. The client attests in the wrong slot or committee. Gossip rejects an attester who is not in the committee, so the vote is lost. Slashing protection has already recorded the target epoch, so the validator's real duty later in the epoch is refused too.
  • A stale proposer schedule costs a block. The client asks for a block in a slot that is not its own, which the node or gossip rejects for its proposer index, and misses the slot that is.
  • A stale PTC schedule votes in the wrong slot and misses the right one.
  • Stale subscriptions leave an aggregator without its committee's votes.

What other clients do

Client How held duties follow a reorg Read at
Lighthouse Polls attester and proposer duties every slot, each in its own loop (duties_service.rs:727, :759). For attesters it asks for a few validators first, and fetches everything only for validators whose stored dependent_root differs (duties_service.rs:1240-1266). It fetches proposers for the current and the next epoch every slot, with v2 by default (duties_service.rs:1882, :1940-1946). Head events are not used for duties unstable @ 11813cfb
Teku Loads each epoch's duties once. On every head event (head_v2 from gloas) it compares the event's dependent roots with the held ones, and recalculates on a mismatch (AbstractDutyScheduler.java:72-84, PendingDuties.java:166-171). previous_duty_dependent_root is checked against the head's epoch and current_duty_dependent_root against the next (AttestationDutyScheduler.java:76-83). A missed-events signal, such as a reconnect, recalculates everything (AbstractDutyScheduler.java:96-100) master @ 62a54b96
Prysm Runs checkDependentRoots on every head_v2 (or head) event, and calls UpdateDuties when a root differs (duties.go:765-812). --disable-duties-polling turns it off develop @ 0c1e3d24
Nimbus With the default --block-monitor-type=event, each duty loop polls once an epoch, and again when a head event's dependent root differs from the stored one (common.nim:1623-1625, duties_service.nim:834-840). A stream (re)connect invalidates everything (block_service.nim:864-868) unstable @ 9bed158a
Lodestar Polls attester duties every epoch. On each head event it checks previousDutyDependentRoot against the current epoch and currentDutyDependentRoot against the next, and refetches on a mismatch (attestationDuties.ts:351-367). Proposers get the same check (blockDuties.ts:216-218) unstable @ 77088eb7
Vouch On each head event for the current slot, compares its dependent roots with the previous head event's (events.go:80). A changed previous root refreshes this epoch's attester and PTC duties. A changed current root refreshes this epoch's proposers and the next epoch's attester and PTC duties (events.go:226-249) master @ 691f3652
Vero Subscribes to head_v2 and chain_reorg on every node (event_consumer.py:238-244). A head_v2 whose dependent roots differ from the held duties' triggers a refetch (attestation.py:155-165, block_proposal.py:205-215, ptc.py:116-126). A chain_reorg refetches attester, proposer and sync duties (validator_duty_service.py:106-110) master @ 9d110c1d

File names are relative to each client's validator client directory.

All seven follow a changed dependent root within a slot or a head event. Lighthouse polls. The other six compare the dependent roots in head events. Only Vero also listens to chain_reorg.

Proposal

Two ways, not exclusive:

  • Head events. Subscribe to head (head_v2 once nodes serve it).
    • On each event, compare previous_duty_dependent_root with the held current-epoch attester and PTC roots, and current_duty_dependent_root with the next epoch's. Refetch what differs, and resubscribe when the attester schedule moved.
    • On a stream (re)connect, refetch everything, as Teku and Nimbus do, since events can be lost.
    • The epoch refresh and the slot clock stay. slot_clock.rs:1-6 explains why a dropped event must never cost a duty.
    • ethlambda's node emits head with both dependent roots (docs/rpc.md:1023). It accepts head_v2 but never emits it (crates/blockchain/src/events.rs:296-311). It sends no head while more than 32 slots behind the wall clock (docs/rpc.md:1023).
  • Per-slot polling, as Lighthouse does. Re-request the current and next epoch's attester and PTC duties every slot, and compare roots. Lighthouse keeps the cost down by asking for a few validators first and fetching the rest only when the root moved (duties_service.rs:1240-1266).

To decide

  • Events, polling or both. Events cost nothing per slot, but they need an SSE client, reconnect handling and a choice of node. Polling needs nothing new. On an ethlambda node, though, each attester duties request "walk[s] every committee of the epoch, a full shuffle per request on mainnet" (docs/rpc.md:308-309), so polling two epochs every slot costs the node two shuffles a slot per client.
  • Which node's events, with several configured. The first node, every node as Vero does, or the node that serves the duties.
  • Which proposer root to track. The loop keeps v1 proposer duties. Their root moves on a boundary reorg that, since fulu, cannot change the proposers. Tracking the v2 root (previous_duty_dependent_root for the head's epoch) avoids refetching for nothing. This ties in with #826, which proposes prefetching the next epoch's proposers.
  • chain_reorg. Vero refetches on it. Once head events are compared it adds little, since every reorg that changes duties moves a dependent root.
  • The fork-epoch PTC root. Fix the node's dependent root for GLOAS_FORK_EPOCH first; nothing on the client side can see the change without it.

Tests

  • A mock node whose attester duties' dependent root changes between two slots of one epoch: assert the second slot attests from the new schedule.
  • A head event carrying a new previous_duty_dependent_root: assert this epoch's attester and PTC duties are fetched again, and that matching roots fetch nothing.
  • A stream that drops and reconnects: assert a full refetch.
  • A changed lookahead schedule: assert the subnet subscriptions are sent again within the slot.
Lingua principale
Rust
Stelle
86
Fork
34
Merge medio
9g 20h
PR unite (30g)
77

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lambdaclass/ethlambda

Tutte le issue di lambdaclass/ethlambda

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.