Skip to content

fix(discovery): start the ENR's seq at the clock so a restart replaces the record peers hold - #954

Open
pablodeymo wants to merge 1 commit into
mainfrom
fix/enr-seq-starts-at-the-clock
Open

pablodeymo wants to merge 1 commit into
mainfrom
fix/enr-seq-starts-at-the-clock

Conversation

@pablodeymo

Copy link
Copy Markdown
Collaborator

🗒️ Description / Motivation

Intended for release/v2.0.0 by cherry-pick once merged here. It is the part of the "Decide on #735" item on #943's checklist that can ship in v2.0.0.

The ENR this node serves over discv5 keeps the fork digest it started with across a fork boundary (#932): ethrex's DiscoveryServer cannot replace its record at runtime. #735 fixes that, but it depends on three unmerged ethrex PRs (lambdaclass/ethrex#7488, on #7574, on #7217), so it cannot be in v2.0.0, which pins ethrex to a release tag. The plan for v2.0.0 is to state the gap in the release notes and tell operators to restart after Hoodi's Glamsterdam boundary (epoch 143616, 2026-12-15 19:12:24 UTC).

That restart does not reliably work today. The record is signed at ethrex's INITIAL_ENR_SEQ (1) on every boot, and a discv5 peer takes a replacement record only at a strictly higher seq. So after a restart, peers that already hold the node's record keep their copy, previous fork digest included, and hand it on in their NODES answers. docs/discovery.md listed this as a known limitation for upgrades ("An upgrade's new ENR entries are invisible to peers that stayed up").

This PR takes the seq part of #735 on its own: it needs no ethrex change and no lockfile change.

What Changed

  • crates/net/p2p/src/discovery/enr.rs: build_local_enr signs the record at starting_seq(), the current time in milliseconds (never below INITIAL_ENR_SEQ), as geth does. Code and test are feat(discovery): republish the ENR's eth2 entry at fork boundaries #735's.
  • crates/net/p2p/src/discovery/mod.rs: the warning logged at a boundary (update_served_enr) now ends with "Restart the node to publish the new fork digest".
  • docs/discovery.md, docs/beacon_wire.md, CLAUDE.md: describe the starting seq and what a restart does; the closed known limitation is removed.

Correctness / Behavior Guarantees

  • The served record still cannot change at a boundary. A node running across one keeps following the chain, keeps its peers and still dials out; peers that discover it afterwards reject its record until it restarts.
  • A restart now serves a record above any seq the previous run reached. Nothing is persisted: the only edits to a running record are discv5 IP voting's, one seq each, so the previous run would have had to edit more than once per millisecond of uptime to pass the clock. A clock stepped back past the previous run's last edit is the one case not covered.
  • The first start on this build also replaces the seq = 1 record peers hold from an earlier version.
  • Applies to ethlambda node with --discovery.enable too: same function.

Tests Added / Run

  • New: the_record_starts_at_the_clock_not_at_a_fixed_seq (the seq is inside the clock readings taken around the build, and the signature verifies).
  • cargo test -p ethlambda-p2p --profile release-fast --lib: 567 passed, 1 ignored.
  • cargo clippy -p ethlambda-p2p --all-targets -- -D warnings and cargo fmt --all -- --check: clean.
  • Not run: the workspace-wide make lint and make test.
  • Not tested: a live peer of another client fetching the restarted node's record. The strictly-higher rule was read in ethrex v33.0.0's discv5 handlers (pong_message.enr_seq > cached_seq; the handshake sends the record only when seq differs from the requester's); for other clients it is the ENR spec's rule.

Related Issues / PRs

✅ Verification Checklist

  • Ran make fmt — clean
  • Ran make lint (clippy with -D warnings) — clean (only ethlambda-p2p)
  • Ran make test (test-consensus, test-node and test-ethrex, at release-fast) — all passing (only ethlambda-p2p --lib)

…s the record peers hold

The record was signed at ethrex's INITIAL_ENR_SEQ (1) on every boot. A discv5
peer takes a replacement record only at a strictly higher seq, so after a
restart peers kept the copy they had cached from the previous run. That copy
carries the previous run's `eth2` entry, and the served record cannot be
edited at runtime (#932), so a restart is the only way a node publishes its
fork digest after a boundary: at a fixed seq even that did not reach peers
that already knew the node.

The record now starts at the current time in milliseconds, as geth's does.
This is the seq part of #735, which needs no ethrex change.

The boundary warning now tells the operator to restart.

Related to #932

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