Skip to content

feat(validator): warn when the local clock disagrees with a beacon node's - #886

Merged
MegaRedHand merged 31 commits into
mainfrom
feat/validator-clock-skew
Nov 27, 2026
Merged

MegaRedHand merged 31 commits into
mainfrom
feat/validator-clock-skew

Conversation

@MegaRedHand

@MegaRedHand MegaRedHand commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #834.

Problem

The validator client times every duty off its own wall clock (SlotClock) and never checked that clock against anything. Against an ethlambda node, a clock ahead by more than 500 ms gets proposals refused (refuse_future_slot), one ahead by a few seconds votes for the parent, and one behind sends every duty late while every series this client exports looks healthy. The log never pointed at the clock. A wall-clock step was absorbed silently too: next_slot_to_serve jumps to the slot the clock reads after a forward step, and waits for it to come back after a backward one.

What this does

A clock check on every sync probe (crates/validator/src/clock_check.rs, new). #876's probe asks every node /eth/v1/node/syncing a sixth of a slot before each boundary. It now also records when each answer came back and its Date header (health::Probe::reply, a new health::Reply), and health::run hands each round to a ClockWatch. Two comparisons are made per node:

  • By slot (compare_slots). The client's wall slot is taken at send (Probe::at) and at receive (Reply::received), so a boundary crossed while the request was out lands between the two and counts as neither.
    • A head_slot more than one slot past the client's wall slot at receive means the client's clock is behind (Lighthouse's TimeDiscrepancy). One slot past is tolerated.
    • With a nonzero sync_distance from a node that is not syncing, head_slot + sync_distance is the node's wall slot. A wall slot before the client's at send means the client is ahead; one past the client's at receive means it is behind.
  • By Date (date_offset). The header, taken at the middle of the second it names, less the midpoint of send and receive. A sample from a round trip longer than a second is dropped. A node is flagged once the median of its last three kept samples is 2 s or more from zero. A sample is read for six slots, so a node that stops sending a usable Date loses its estimate rather than keeping an old skew warned about and on its gauge. A node that sends no Date, or one that is not an IMF-fixdate, gets the slot comparison alone.

Steps (clock_check::StepWatch, one check call at the top of the duty loop in lib.rs). Each pass compares how far the wall clock moved with how far Instant moved. A difference of half a second or more is a step: logged at warn with its size and direction, and counted. The message says slots were lost only for a forward step past the next slot, and that duties wait only for a backward step before the slot served; a step within those only moves the next boundary. If no step was found but the wall clock reads more than a slot past the slot served, a stall is logged, not counted.

Surfacing.

  • A warning names the node by its position in --beacon-nodes and gives the signed offset, plus the node's and client's slots when the slot comparison fired. It is worded by direction: behind means late duties nothing refuses, ahead means refused block requests and votes for the parent. It recurs at most once an epoch per node while the disagreement lasts, and one info line follows when the clocks agree again (NodeClock::report).
  • ethlambda_validator_beacon_node_clock_offset_seconds{node="<position>"}: node clock minus client clock, so positive means this client is behind.
  • ethlambda_validator_clock_steps_total.
  • ethlambda-metrics now re-exports GaugeVec and register_gauge_vec for the gauge.

Plumbing. BeaconNodeApi::sync_status_with_date is a new trait method. Its default answers no Date, so the mock and the fallback need nothing. HttpBeaconNode implements it through a new get_dated, which get now delegates to. FallbackBeaconNode::probe keeps its signature and calls the new method.

Decisions

  • Date is read on the probe's request only, not in every get/post. One sample per node per slot is plenty, and the probe is the one request already timed per node and tied to a position.
  • Three samples, by median. They are not there for averaging. The probe goes out at the same point of every slot, so on whole-second slots the header's truncation error is the same on every sample, and more samples would not shrink it. Centring the header on its second removes that bias instead. With the one-second round-trip cap, a kept sample is within about a second of the truth: a synced node never reaches 2 s and a node 3 s off always does. The median of three ignores one bad sample, such as one taken while either clock stepped, and still reports within three slots.
  • sync_distance is read only when nonzero and the node is not syncing. That goes beyond the issue's sketch. The Beacon API defines the distance as how many slots the node must process to reach the head. Teku (GetSyncing.calculateSlotsBehind) reports 0 whenever it is in sync, and its peers' best slot less its head while it syncs. Read unconditionally, a Teku node would put the client ahead on every missed slot and during any chain stall. Lighthouse, Prysm, Nimbus and ethlambda compute the distance from their own clock, so the rule reads them whenever their head lags. The head rule needs no distance. The cost is real: a synced node's head is at its wall slot, so its distance is 0, and in the ordinary case the slot comparison cannot see a client that is ahead. Only Date sees that direction then, and it is the direction that costs proposals.
  • The slots bound the Date estimate when they disagree (ClockWatch::read). When the slot comparison fires, the reported offset is the Date estimate held to at least the offset the slots allow, and the warning takes its direction from the slots. A reverse proxy in front of the node writes its own Date (nginx does by default), which is the proxy's clock, and would otherwise report a node 10 s behind as agreeing.
  • Steps are measured against the monotonic clock, not by slot alone. refresh_epoch is not bounded by its slot, so an epoch refresh against slow nodes can return more than a slot later (feat(validator): rank beacon nodes by health and broadcast signed messages #885 shortens the hung-node case to one request timeout, but does not bound the refresh). A slot-only rule would count that as a forward step, and an NTP slew that puts the wall clock a few milliseconds behind a boundary would count as a backward one. The monotonic comparison catches every step of 0.5 s or more, including ones that cross no boundary. It also catches a suspended host, since Instant stops while the host sleeps. A paused process or VM whose monotonic clock runs on shows up as a stall. 0.5 s is MAXIMUM_GOSSIP_CLOCK_DISPARITY, the smallest error that already costs a proposal against an ethlambda node.
  • What the gauge shows for a node without a Date estimate. That covers a node that sends no Date, and any node before three samples are kept. When the slot comparison fires, the gauge shows the offset nearest zero that the comparison allows, from the slot start and the send or receive time. Otherwise it shows 0. So every node that answers has a series. A warning from the slots alone shows only the offset they prove, about 1.9 s on 12 s slots when this client is behind (a sixth of a slot less the round trip), so docs/metrics.md puts an alert meant to match every warning at 1.5 on 12 s slots, lower on shorter ones. A slot comparison that proves less than half a second (SLOT_SKEW_MIN_SECS), a boundary crossed inside a long round trip by a node a few milliseconds ahead, does not count. A labelled gauge has no series before a node's first answer, which docs/metrics.md says. A node that does not answer a probe has its series removed until it answers again, so an alert does not keep firing on its last value.
  • Labelled by position, not URL. A --beacon-nodes URL can carry credentials, and feat(validator): check each beacon node's sync status before every slot's duties #876's logs already name nodes by position.
  • On the issue's "To decide" questions.
    • Resolution: about 1–2 s from Date, nothing finer. No timesync endpoint, no NTP query.
    • Which side is wrong: not judged. The warning says what each direction costs if the client's clock is the one off.
    • Warn only: the checks touch neither slot_signs, nor the ranking (NodeHealth::ranked, Tier), nor Standing, nor what /health reports.
    • Shared clock: not covered. The docs say only a split setup is caught.
    • Node-side check: out of scope.

Docs.

  • docs/cli.md: a "Clock checks" section after "Ranking and broadcast", and the sync check's "no clock-based rule for signing" bullet now says the clock checks read sync_distance and head_slot too.
  • docs/metrics.md: both new series.
  • The health.rs module doc is updated to match.

On #884 and #885. Probe has a new field, reply, and this PR adds reply: None to the one literal #884 and #885 build by hand, #884's client_health::tests::probe. #885's at_distance and el_offline build through health.rs's test probe helper, which this PR already changes. No existing public item was renamed or removed.

Tests

clock_check.rs:

  • Date parsing. The RFC example, the epoch and a leap day parse to their instants. The two obsolete forms, a non-GMT zone, impossible dates (31 February, 29 February 2023), out-of-range fields, a leading +, a pre-1970 year, non-ASCII and the empty string are refused.
  • Date offset.
    • A sample is the middle of its second less the midpoint of the round trip. A round trip over a second, or one that ends before it starts, gives no sample.
    • A 3 s skew, ahead or behind, is flagged from the third sample and not before; a 1 s skew never is. Both hold at five sub-second phases of the probe.
    • One wild sample among three does not move the median.
    • A node that stops sending Date keeps its estimate for six slots after its oldest sample, then loses it and is no longer flagged.
    • A node without Date reads 0 while the slots agree.
  • Slot verdicts.
    • A head two slots past the client's wall slot means the client is behind; one slot past is tolerated.
    • A node wall slot past the client's at receive means the client is behind; one before it at send means the client is ahead. Both check the offset bound.
    • A boundary inside the round trip is not flagged, nor is a round trip ending 9 ms short of the client's boundary from a node that already crossed it.
    • A distance of 0, a syncing node's distance and a missing head are not read.
    • A slot disagreement flags a node before any Date estimate, and sets the offset to its bound.
    • A Date estimate near zero, as from a proxy, does not hide a node whose wall slot is behind the client's: the offset is held to the slots' bound of about -10 s.
  • Through the probe. With MockBeaconNode reporting a head three slots past the client's clock, the node is flagged; one slot past, it is not, whichever side of a boundary the probe lands on. A probe records the receive time for an answering node and no reply for a failing one. Only the probe taken for the slot, and only an answer, is read.
  • Rate limit. One warning an epoch, one line when the clocks agree again, and no repeat on a flicker within the epoch.
  • Steps.
    • A ten-minute backward step and a 36 s forward step are reported as steps.
    • A three-slot overrun with both clocks moving together is a stall, not a step.
    • An ordinary pass is nothing, and a few-millisecond slew across a boundary is nothing.

beacon_node/http.rs: sync_status_with_date reads an IMF-fixdate Date from the answer and reads an RFC 850 one as none.

The global gauge is not asserted on, since tests in one binary share it. The tests assert on the Reading it is set from.

Tests not run locally (CI runs them); make fmt and make lint clean.

…ot's duties

The client asked whether its beacon node was syncing or optimistic once
an epoch, at the top of refresh_epoch, and between refreshes left every
duty to the node's 503. The Beacon API has none for a syncing node's
head root or an optimistic node's payload attestation data, and with
several nodes every request still started at the first one listed.

beacon_node::health probes every node's /eth/v1/node/syncing once a
slot, all at once, a sixth of a slot before the boundary (2 s on 12 s
slots), on its own task. NodeHealth keeps each node's last probe (the
full SyncStatus, head_slot and sync_distance included, or the error),
shared through FallbackBeaconNode::health() with a cheap snapshot().

- The duty loop reads the probe at the boundary: a slot signs nothing
  when some node answered and every node that answered is syncing or
  optimistic. A node that did not answer does not count, so the 503
  stays the backstop. Logged, and counted on
  ethlambda_validator_slots_skipped_syncing_total. Only the fee
  recipient re-send, which signs nothing, still runs in such a slot.
- refresh_epoch drops its own check and runs only in a slot that
  passed, so the epoch refresh and the duties read one probe.
- The fallback tries the nodes that passed first, then the rest, each
  in command-line order; Producer positions are unchanged.
- The head root and the PTC data are never asked of a node whose last
  probe said syncing or optimistic, so no sync committee message is
  signed over a syncing node's head and no PTC vote over an optimistic
  one.
- el_offline and each node's change of state are logged on change.
@MegaRedHand
MegaRedHand changed the base branch from feat/validator-per-slot-sync-check to feat/validator-health-endpoint November 25, 2026 02:17
@MegaRedHand
MegaRedHand force-pushed the feat/validator-clock-skew branch from 87613c4 to 82ff394 Compare November 25, 2026 02:17
…s probe

A synced node whose sync probe had not come back by the boundary counted
as not answering, so one fast syncing answer withheld the slot while
routing still ranked that node synced. A node still on the slot before's
synced answer now holds the gate open.

The probe task's end is logged: it loops for the client's life, so it
ends only by panicking, and the duties then go on unchecked.

The el_offline change logs compare against the last probe that
answered, so a failed probe in between neither hides the execution
client coming back nor reports it going offline twice.
@MegaRedHand
MegaRedHand force-pushed the feat/validator-clock-skew branch from 82ff394 to 2987f41 Compare November 25, 2026 14:23
@MegaRedHand

Copy link
Copy Markdown
Collaborator Author

/review

…ered synced

The head root and the payload attestation data have no 503 behind them,
yet a node whose sync probe failed was still asked for them: a syncing
node with a slow or broken /node/syncing could hand out its stale head,
or an optimistic one its unvalidated payload data, for this client to
sign.

For those two calls a node must have answered its last probe synced, or
have no probe to read (a fallback no probe task runs for). With no node
left to ask the answer stays BeaconNodeSyncing, which the sync
committee and PTC services read as "do not sign".
…sages

Requests walk the beacon nodes by tier, best first: synced and validated;
optimistic or with the execution client offline; syncing or more than 8
slots behind by sync_distance; not probed yet; failing. Command-line order
breaks ties, so one healthy node, or several, are asked as listed. A
request that times out or cannot connect ranks its node failing until a
later probe answers, so a hung node costs one request timeout per probe
rather than one per request. `nodes` stays in command-line order, so a
Producer still names the node that built a blinded block.

`--broadcast attestations,blocks,sync-committee` sends those signed
messages to every node at once, succeeding when any accepts. Nodes ranked
failing are sent a broadcast only when no other node took it. A block
reports the best answer (200 over 202 over refused). An envelope goes to
its block's producer first, then the rest, or to the producer alone when
sent without its blobs. A blinded block stays on its producer. None is
broadcast by default.
…less envelope to its producer

In a stall every node is past the sync tolerance and ranks Behind, so a
syncing node listed first was asked ahead of a synced one. Inside a
tier, a node reporting syncing now goes last, and an optimistic or
el_offline one after the rest.

An envelope without its blobs goes to its producer alone with or
without --broadcast blocks: only the producer cached them, and a
producer ranked failing for a timed-out block publish was otherwise
asked last.

Also: --broadcast accepts Lighthouse's `none` as a no-op, the request
failures are recorded with inspect_err, and the dto.rs table says
el_offline and sync_distance rank a node.
@github-actions

Copy link
Copy Markdown

AI security review: 2 finding(s) to check

Reviewed by Opus, GPT, Kimi, GLM, DeepSeek. A judge model checked every one of the findings against the code.

# Finding Severity Status Found by Where
M1 Slot comparison warns on arbitrarily small clock offsets near a boundary low Bug DeepSeek, GLM (2/5) crates/validator/src/clock_check.rs:304
M2 Documented alert at |offset| >= 2 misses 'client behind' skews detected only by slots, since the gauge then reads below low Bug Opus (1/5) docs/metrics.md:947
Details

M1. Slot comparison warns on arbitrarily small clock offsets near a boundary (low, logic)

  • Trigger: An honest beacon node whose clock is only milliseconds ahead of the validator's, with a sync-probe response that arrives in the short interval after the node crosses the next slot boundary but before the validator does. The node controls the timing and reports head_slot and sync_distance through /eth/v1/node/syncing in FallbackBeaconNode::probe.
  • Mechanism: compare_slots treats node_slot > received_slot as a disagreement whenever the node's computed wall slot is one slot ahead. For example, with 12-second slots, a probe is sent 2 seconds before the boundary; if the node is 10 ms ahead and responds 9 ms before the validator's boundary, sent_slot and received_slot are both the old slot while node_slot is the next slot. The resulting offset_bound is only about 9 ms, but Reading::is_skewed returns true solely because slots is Some, without applying the 2-second threshold used for Date samples. A Date estimate of zero is also clamped to only about 9 ms, so the warning and the documented absolute-value-2 metric alert disagree.
  • Impact: Clocks that agree to milliseconds can be reported every epoch as a meaningful beacon-node clock disagreement, causing unnecessary operator investigation and a warning that is not reflected by the documented metric threshold.
  • Judge: A non-syncing node just milliseconds ahead can report the next wall slot while both client timestamps remain in the preceding slot. This produces a millisecond-scale offset_bound, yet any slot disagreement triggers a warning regardless of the Date estimate. The send/receive comparison only tolerates boundaries crossed by the client's clock; warnings are limited to once per epoch.

M2. Documented alert at |offset| >= 2 misses 'client behind' skews detected only by slots, since the gauge then reads below 2 s (low, docs)

  • Trigger: Ordinary operation. A beacon node's slots put it in the next slot (the distance rule with node_slot = received_slot+1, or the head rule with head = received_slot+2), and the node has no Date estimate yet. That covers a node that sends no Date, a node whose round trips exceed 1 s, and the first two probes after startup. It also happens when the Date estimate is under 2 s.
  • Mechanism: The probe goes out slot/6 before the boundary (probe_time), so received is about start_of(S) - slot/6 + RTT. In compare_slots, the client-behind bound is start_of(node_slot) - received (distance rule) or start_of(head - 1) - received (head rule). With node_slot = S, or head - 1 = S, that is slot/6 - RTT: about 1.95 s on mainnet and about 0.8–0.95 s on 5–6 s slots. ClockWatch::read then sets offset to this bound ((None, Some(skew)) =› skew.offset_bound) or date.max(bound). Reading::is_skewed is true because slots.is_some(), so the client logs a warning, but the gauge shows a value below 2. For example, a node whose own clock is 10 s ahead of the network (head S-1, wall S, distance 1) and that sends no Date reads 1.95 for as long as the skew lasts.
  • Impact: An operator who follows the documented alert (and the PR's claim that one alert at an absolute value of 2 covers every node) never sees these client-behind detections in alerting, only in the logs. On networks with slots shorter than 12 s the gauge can never reach 2 from a slot detection alone. No duty is affected, because the check only warns.
  • Judge: The documented alert misses reachable slot-only warnings: a probe sent two seconds before the boundary and answered 50 ms later can produce a +1.95-second bound even for a substantially larger actual skew. Without a Date estimate, that bound is published unchanged while the client warns. The broader claim that shorter-slot networks can never reach two seconds from slot detection is overstated: lar

Cost of this review: ~$3.47 of a $30 budget (estimated from token counts).

…e envelope's failover

A broadcast waited for every node not ranked failing. A node hanging on
publish_block for the first time held it past the proposal's deadline,
which cut the whole publish: the proposal read as failed, the
self-built envelope was skipped, and the hung node's timeout was never
recorded, so the next proposal waited on it again. Once a node accepts,
a broadcast now waits at most half a second more; a node still sending
is cut off and ranked failing.

An envelope without its blobs went to its producer alone. A block with
no blobs can be revealed through any node, so a producer that does not
take it is now followed by the walk, with or without --broadcast.

A request failure is cleared only by a probe sent after it, not by one
already on its way when the request failed.
…ties

The validator client's /health always answered 200 with a constant
body, so a client whose beacon nodes were all down or syncing, or whose
slashing-protection writes kept failing, looked healthy to every probe.

client_health::ClientHealth holds what the endpoint reads, all of it
state the client already keeps, and makes no beacon node request of its
own. /health now answers 200 when the client can do its duties and 503
when it cannot, with status, service and four checks:

- beacon_nodes {usable, configured}: usable counts the nodes whose
  latest sync probe (beacon_node::health) answered neither syncing nor
  optimistic and is at most two slots old. One is enough.
- validators {loaded, resolved}: reported, never failing. loaded is
  read from the key store with try_read, falling back to the last count.
- slashing_protection {last_write_ok}: SharedProtection::last_write_ok,
  two atomics beside the record's mutex. commit() sets the write flag
  from file::write's outcome; blocking() sets the wait flag on a
  RECORD_WAIT timeout and clears it when it reaches the record. A failed
  write fails the check until a later write succeeds.
- started: the duty loop marks the first successful refresh_epoch.

status is healthy (200), starting (503: not started, nothing else
failed; a node not probed yet does not count against a client that has
not started) or unhealthy (503).

beacon_node_available is now set on every /metrics scrape from the same
report, as is the new ethlambda_validator_healthy gauge and
validators_loaded, so a gauge and the endpoint read one answer. Its old
writers in the duty loop and the sync gate are gone.

docs/cli.md documents the endpoint and docs/metrics.md the metric
changes.
A node can answer its sync probe synced and still fail every duty
refresh. /health then stayed 200 for good after the first refresh, with
no duties left to do once the held schedule ran out, and the failure
paths that used to drop beacon_node_available are gone.

/health gains a schedule_current check: the last successful refresh is
at most two epochs old, so the schedule it fetched (its own epoch and
the next) still covers now. healthy now also requires it.
…y held

schedule_current allowed two epochs from the refresh's completion. A
refresh late in its epoch then read current for most of an epoch past
the schedule's end, and one whose lookahead fetch failed (which
refresh_around shrugs off) read current through an epoch it held no
attester duties for.

The duty loop now passes the last epoch the attester schedule holds
after a successful refresh: the lookahead epoch when its fetch went
through, else the refresh's own (DutiesService::holds_attesters).
ClientHealth compares it with the clock's epoch, so attach takes the
SlotClock.
@MegaRedHand
MegaRedHand force-pushed the feat/validator-clock-skew branch from 3c3b63b to 015d62a Compare November 25, 2026 15:04
…rent across boundaries

A refresh that resolved no validator (no keys, or keys waiting for
activation) fetches no attester schedule, so the schedule check counted
it through its own epoch only, and /health read unhealthy at every epoch
boundary until that slot's refresh returned. Such a refresh now counts
through the next epoch: there is no schedule to run out.
…de's

Every duty is timed off the client's own wall clock, and nothing checked
it. The per-slot sync probe now compares it with each beacon node's clock,
and the duty loop watches it for steps. Both only warn.

- crate::clock_check, new: the slot comparison (a head more than a slot
  past the client's wall slot; head_slot + sync_distance against the
  client's wall slots at send and receive, read only for a nonzero
  distance from a node that is not syncing), the Date estimate (header at
  the middle of its second less the round trip's midpoint, round trips
  over a second dropped, median of three samples, warned at 2 s, held to
  the slot comparison's bound when the two disagree), the IMF-fixdate
  parser, the per-node warning rate limit (once an epoch),
  and StepWatch (wall clock against the monotonic one per pass of the
  duty loop, 0.5 s threshold, plus a stall warning).
- health::Probe gains `reply` (receive time and Date); the probe calls
  the new BeaconNodeApi::sync_status_with_date, which HttpBeaconNode
  answers from get_dated, and health::run reads each round.
- Metrics: ethlambda_validator_beacon_node_clock_offset_seconds{node}
  and ethlambda_validator_clock_steps_total; ethlambda-metrics re-exports
  GaugeVec and register_gauge_vec.
- Docs: docs/cli.md "Clock checks", docs/metrics.md.
… series

A node's Date estimate was the median of its last three samples however
old they were, so a node that stopped sending a usable Date kept an old
skew warned about and on its gauge for good. A sample is now read for
six slots.

A node that does not answer a probe has its clock offset series
removed, rather than keeping the last value an alert would keep firing
on.

A clock step that stays within the slot served or the next is logged as
such, instead of as one that lost slots or holds duties back.
…ect the alert guidance

A round trip that ends just short of this client's slot boundary, from
a node a few milliseconds ahead that already crossed it, flagged clocks
that agree: any slot disagreement warned, whatever it proved. A slot
comparison now counts only when it proves half a second or more
(MAXIMUM_GOSSIP_CLOCK_DISPARITY).

The docs said an alert on an absolute offset of 2 matches the warnings.
A warning from the slots alone shows only the offset they prove, about
1.9 s on 12 s slots when this client is behind, so the guidance now
says where such an alert has to fire.
@MegaRedHand
MegaRedHand force-pushed the feat/validator-clock-skew branch from 015d62a to 5325408 Compare November 25, 2026 15:31
…ot-sync-check

Conflicts with the chain check from main (#854), resolved to keep both:

- FallbackBeaconNode holds the probe records and the chain check's
  per-node states side by side. The walk follows the probe ranking and
  skips a node whose usable flag is down; try_each_synced answers
  BeaconNodeSyncing only when some node is on this client's chain, and
  the no-usable-node failure otherwise.
- The per-slot probe and is_optimistic_or_syncing ask only the nodes on
  this client's chain, so a synced node on another chain cannot open the
  slot's gate.
- The duty loop reads the gate before the readmission count, so a node let
  back in during a withheld slot is still sent what it missed at the next
  slot that passes. Both the probe task and the chain check are stopped
  when run returns.
- docs/cli.md: the --beacon-nodes row and the per-slot section name the
  chain check.
…-node-ranking

Brings in main through the base branch: the chain check (#854) and the
keymanager token file (#867).

Conflicts in fallback.rs, resolved to keep both: the broadcast topics and
flag sit beside the chain check's per-node states, and the module doc keeps
both sections. Beyond the conflicts, a node whose usable flag is down is
now left out of a broadcast (`broadcast_to_all`), and an envelope whose
producer left the chain is not sent to it but to the walk or the broadcast,
as no other call goes to such a node. A broadcast with no node to send to
names the chain check's no-usable-node reason. docs/cli.md says so.
…-endpoint

Brings in main through the base branches: the chain check (#854) and the
keymanager token file (#867). One conflict, the module list in lib.rs,
which keeps both chain_check and client_health.
…ck-skew

Brings in main through the base branches: the chain check (#854) and the
keymanager token file (#867).

Conflicts:
- fallback.rs: the probe keeps this branch's dated request and reply
  (`sync_status_with_date`, `Reply`) over the base's usable nodes only, so
  a node on another chain feeds neither the gate nor the clock check;
  check_nodes stays as main has it.
- lib.rs: the duty loop keeps the clock-step watch beside the readmission
  and schedule-generation counters.
@MegaRedHand
MegaRedHand added this pull request to stack #897 November 25, 2026 19:45
With an empty ValidatorStore the sync committee and PTC services sign
nothing whichever node answers, so both tests still passed with
head_block_root routed back through the plain try_each walk. Loading one
key makes a stale or optimistic node's root produce a submitted message,
which the existing asserts catch.
…ot-sync-check

Brings in #869, #870 and #879. One conflict, in the duty loop's refresh
block (lib.rs): main's ahead_of_block/settle_refresh restructure is kept,
with this branch's comment fix (refresh_epoch no longer runs a sync check)
carried over.

Semantic fix: #869's a_refresh_that_finds_the_node_syncing_stops_the_proposals
drove the node_syncing gate through refresh_epoch's is_optimistic_or_syncing
check, which this branch removes in favour of the per-slot probe. The gate is
still reachable through a duties fetch every node refuses with a 503 (read as
BeaconNodeSyncing), so the test now feeds settle_refresh that outcome. The
proposal gate's comment now names the per-slot check as the primary guard.
pablodeymo and others added 5 commits November 25, 2026 17:43
…-endpoint

Brings in #876's and #885's latest, and through them main's #869, #870 and
#879, which restructured the duty loop's refresh (ahead_of_block,
settle_refresh, a refresh deferred past the block).

Conflicts in lib.rs, resolved onto main's structure with this branch's
intent ported:
- health.epoch_refreshed now runs wherever settle_refresh reports a refresh
  that got through, both ahead of the block and deferred past it, through a
  new report_refreshed helper that keeps the covered_through rule.
- The set_beacon_node_available writes #869 and #870 added (settle_refresh's
  two failure arms, the proposer-only fetch, spawn_subscriptions) are
  dropped, as this branch dropped the older ones: the gauge is set from the
  /health report on every scrape.

duties.rs: #869 and this branch each added an identical holds_attesters;
one is kept.
…ck-skew

Brings in the rest of the stack's latest, and through it main's #869, #870
and #879. One conflict, in the duty loop's state (lib.rs): this branch's
StepWatch and #869's node_syncing flag were declared at the same spot; both
are kept.
…anking

main is #876's squash (2a67cdb), whose tree is identical to #876's last
head (db433ad), already merged here. Recorded with -s ours so GitHub sees
main as merged; this branch's tree is unchanged.
…-endpoint

Brings in the base branch's merge of main, which carries #876 as one
squashed commit.
…ck-skew

Brings in the base branches' merge of main, which carries #876 as one
squashed commit.
MegaRedHand added a commit that referenced this pull request Nov 26, 2026
…de's (#886)

The validator client timed every duty off its own wall clock and never
checked it against anything, so a skewed clock got proposals refused or
sent duties late while every series looked healthy. Each sync probe now
also reads the node's Date header and answer time, and the client warns
when its clock is off from the nodes' by half a second or more
(ethlambda_validator_beacon_node_clock_offset_seconds). A step of the wall
clock against the monotonic one is logged and counted too.

Applied as this PR's own change on top of #884, which it is stacked on.
Resolved against #874 and #880: the module list and the metrics keep
#874's and #880's entries next to this PR's clock series.

@pablodeymo pablodeymo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It only warns and updates metrics, I found no panic paths, and CI is green. Measuring the Date header at the round trip's midpoint, and checking the slots at both send and receive, keeps a slow answer from being read as skew.

One concern from my first pass is gone: now that #854 is merged in, probe asks only usable nodes, and ClockWatch::read takes only a probe from the current slot. A node the chain check marks as on another chain therefore gets no reading: its gauge is cleared and it can't raise a false clock warning.

One docs fix I'd like before merging, and one nit, inline.

Comment thread docs/metrics.md
| `ethlambda_validator_slots_skipped_syncing_total` | Counter | Slots in which nothing was signed because every beacon node that answered the slot's sync probe (`/eth/v1/node/syncing`, a sixth of a slot before the boundary) reported syncing or optimistic. Should read zero once the nodes are synced; a steady climb is a node that stays syncing or on an optimistic head, usually because its execution client is behind. Nodes that did not answer are not counted against the slot, so this stays flat while every node is down. See [The per-slot sync check](./cli.md#the-per-slot-sync-check) |
| `ethlambda_validator_beacon_node_available` | Gauge | 1 when at least one configured beacon node answered its latest sync probe neither syncing nor optimistic, and that probe is at most two slots old. 0 before the first probe answers, and while every node is down, syncing or optimistic, which includes every slot the sync check withholds. Set on every scrape from the per-node probe records `/health` reads, so it follows the nodes rather than the last duty: a failed attestation no longer sets it to 0, and a node that comes back sets it to 1 within a slot, without waiting for the next epoch's refresh |
| `ethlambda_validator_healthy` | Gauge | 1 when `/health` answers `200`, 0 when it answers `503`: the client has run a duty refresh whose attester schedule reaches the current epoch, at least one beacon node is usable, and the last slashing-protection write went through. Set on every scrape from the same report `/health` answers with, so an alert on it and a probe of the endpoint cannot disagree. 0 while the client is starting. See [Metrics](./cli.md#metrics) for the checks |
| `ethlambda_validator_beacon_node_clock_offset_seconds` | Gauge | Each beacon node's clock minus this client's, labelled `node` by its position in `--beacon-nodes` (from 0), so positive means this client's clock is behind. Set from every answer to the sync probe: the median of the node's last three `Date` header samples once three are kept from the last six slots, good to about a second. When the node's `head_slot` and `sync_distance` put it in another slot than this client, the value is held to at least the offset that allows, so a `Date` written by something else (a reverse proxy) cannot hide it; that offset is also the value until three samples are kept, or for a node that sends no `Date`. Otherwise 0. Every node the client warns about reads at least 1.5 in absolute value on 12 s slots, so alert there: a `Date` warning needs 2, and a warning from the slots alone shows the least offset they prove, which for this client being behind is about the probe's lead before the boundary less the round trip (about 1.9 s; a sixth of a slot in general, so lower the threshold on shorter slots). A synced node's `Date` estimate stays within about a second. Unlike the other series, a node's is absent until its first answer, and again from a probe it does not answer until one it does. See [Clock checks](./cli.md#clock-checks) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix: "Every node the client warns about reads at least 1.5 in absolute value on 12 s slots" holds only for a short round trip. A warning from the slots alone counts once the proven offset reaches SLOT_SKEW_MIN_SECS (0.5), and the bound is about the probe's lead minus the round trip. The probe's budget runs nearly to the next probe, so a slow answer can give a bound well under 1.5. For example, a node 3 s ahead that sends no Date and answers in 1.2 s reads about 0.8: the client warns, but an alert at 1.5 never fires. Could this say "at least 0.5", or point alerting at a separate "skewed" signal (e.g. a 0/1 gauge set when the client warns) rather than a threshold on the offset?

Report::Quiet
};
}
let due = self

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: warned_at isn't reset when the clocks agree again. Sequence: warn at slot k, agree at k+1 (logs "agrees again" and clears unresolved), skewed again at k+2. That third reading is held back until k+32, so for up to an epoch the last log line says the clocks agree while they don't. The gauge does show it. Clearing warned_at on Report::Agree, or allowing a warning right after an agree, would fix it; the epoch limit could still apply between warnings that have no agree in between.

… it off, and give the envelope's producer a head start

- A node a broadcast stops waiting for 500 ms after the first acceptance is
  no longer ranked Failing. One that is only slower (to import a block, or to
  take a large envelope) was cut out of every broadcast until its next probe,
  slot after slot. A hung node still costs a broadcast at most the grace, and
  its probe ranks it failing. `NodeHealth::record_no_answer` is removed.
- Under `--broadcast blocks` the envelope's producer gets a 500 ms head start
  (`PRODUCER_HEAD_START`) rather than an unbounded wait. A producer that holds
  the request open (one that answered the block 202 waits for a block it never
  imported) no longer keeps the envelope from every node until the proposal's
  deadline cuts the reveal; past the head start its answer is awaited with the
  others' (`Sent::Pending`).
- An envelope without its blobs that the producer refused is not sent to it a
  second time by the walk (`Reach::EveryBut`).
- `register_validators_in_batches` records failed batches against node health.
…anking

# Conflicts:
#	bin/ethlambda/src/validator.rs
…anking

# Conflicts:
#	bin/ethlambda/src/validator.rs
#	crates/validator/src/lib.rs
MegaRedHand added a commit that referenced this pull request Nov 26, 2026
…de's (#886)

The validator client timed every duty off its own wall clock and never
checked it against anything, so a skewed clock got proposals refused or
sent duties late while every series looked healthy. Each sync probe now
also reads the node's Date header and answer time, and the client warns
when its clock is off from the nodes' by half a second or more
(ethlambda_validator_beacon_node_clock_offset_seconds). A step of the wall
clock against the monotonic one is logged and counted too.

Applied as this PR's own change on top of #884, which it is stacked on.
Resolved against #874 and #880: the module list and the metrics keep
#874's and #880's entries next to this PR's clock series.
…-endpoint

Brings in #885's latest, with main's #872 and #880.

One conflict, in the sync committee message step: it keeps #880's
head-event trigger and drops the direct beacon_node_available write, as
this branch does everywhere. The metric is set from the health report
alone.
…ck-skew

Brings in #884's latest, with #885's and main's #872 and #880.

One conflict, in the validator metrics: they keep #880's duty-trigger and
event-stream series next to this branch's clock offset and clock step
series, and init registers all four.
@MegaRedHand
MegaRedHand added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 26, 2026
Base automatically changed from feat/validator-health-endpoint to main November 26, 2026 23:19
Brings in main now that #885 and #884 have merged, with #868, #900, #901
and #911.

#885 and #884 reached main as squash commits, so a plain merge saw both
sides add the same files and conflicted throughout. The tree is main plus
this branch's own diff against #884's merged head (42dcaa3), which
applies to main without conflicts.
@MegaRedHand
MegaRedHand added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 4989419 Nov 27, 2026
12 of 13 checks passed
@MegaRedHand
MegaRedHand deleted the feat/validator-clock-skew branch November 27, 2026 00:03
MegaRedHand added a commit that referenced this pull request Nov 27, 2026
Brings in #868, #872, #880, #884, #885 and #886, among others.

Each side added a flag next to --beacon-nodes, a ValidatorConfig field
and a row in the README and docs/cli.md flag tables. --network and
main's --broadcast both stay, --network first, and the --beacon-nodes
rows take main's text, which describes #885's ranking. The config is
built before run (#872), so network joins main's broadcast and
event_stream fields there.
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.

validator: warn when the local clock disagrees with the beacon node

2 participants