Repository navigation
fix(discovery): start the ENR's seq at the clock so a restart replaces the record peers hold - #954
Conversation
|
/review |
…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
…erved The clock-based seq makes a restart's first record newer than the one peers hold. On a node started without --discovery.advertise-ip that record is at the bind address, 0.0.0.0, so peers would replace a record they can dial with one they cannot, until IP voting settled again. With the constant seq the old record stayed in place. The node now saves the record it serves (Metadata "local_enr", on the dial tick, whenever its seq moves), and a start reads it back: - A start that names no address takes the last record's, within the family the discovery socket is bound on. Voting stays on and replaces it if it has changed. - Every start signs above the last record's seq, so a clock that reads earlier than it did no longer puts the new record behind. A record under another node key carries nothing over. Also: starting_seq reads the clock through unix_now_ms, its test checks what a restart needs in place of a bracket between two clock reads, the doc comment no longer says geth starts its record at the clock (it does so only for a node it has no stored counter for), and docs/cli.md no longer says the ENR stays the same across restarts. The same fix is on #735, which the AI security review flagged for this (its M1). The code here differs only where #735 has an editable record: this branch, cut from release/v2.0.0, has neither that nor #732's LocalEnr, and reads the served seq through a small ServedEnr over the mirror ethrex writes.
3843558 to
19f9116
Compare
|
/review |
|
Verified with Antigravity: PR #954 (19f9116) is an accurate, self-contained port of the exact subset of PR #735 that release/v2.0.0 needs, with no ethrex
• Clock + persisted seq floor (enr::starting_seq, enr::build_local_enr_after): ────── Just like #962, gh pr checks 954 reports no checks on the current head (19f9116) (the last CI run on that branch was on 8919274 |
…they are sent (#968) ## 🗒️ Description / Motivation Backport of #956 to `release/v2.0.0`, for `v2.0.0-rc.2`. #956 is approved and not merged on `main` yet, so this is taken from its head (`36232dcf`) and not from a squash commit on `main`. If #956 changes before it merges, this branch has to be refreshed from the new head. ## What Changed The ten commits of #956 as one commit on top of `release/v2.0.0` (`3ed99c86`): the diff from its branch point on `main` (`e48246f8`) to its head (`36232dcf`), applied with `git apply --3way`. It applied without conflicts and nothing was edited by hand. That includes #958, the by-root counterpart, which was merged into #956's branch. What it does, from #956: - An `execution_payload_envelopes_by_range` answer stops once 16 MiB of SSZ has gone out, always carrying the first envelope its window has. Before, one request could make the node load and send about 1 GiB. - Envelopes are read as they are sent: the codec reads each row just before writing its chunk, and a row that fails to read or decode ends the answer where it is. - The requester asks the same peer again after an answer that stops short, for up to 30 s. - `execution_payload_envelopes_by_root` answers are bounded and read the same way (#958). ## Tests Added / Run On this branch: - `cargo fmt --all -- --check` and `make lint`: clean. - `cargo test -p ethlambda-p2p --profile release-fast --lib`: 587 passed, 0 failed, 1 ignored. - `cargo test -p ethlambda-storage --profile release-fast --features rocksdb`: 256 passed, 0 failed, 2 ignored. Not run locally: the rest of `make test`. ## Related Issues / PRs - Original: #956 (closes #895 on `main`), with #958. - The other PRs open against the release branch: #954, #962 (backport of #950) and #965 (backport of #952). This one merges with each of them without conflicts (checked with `git merge-tree`), though it shares `crates/net/p2p/src/lib.rs`, `CLAUDE.md` and `docs/beacon_wire.md` with some of them. - Release checklist: #943.
🗒️ Description / Motivation
Targets
release/v2.0.0directly: it is the part of the "Decide on #735" item on #943's checklist that can ship in v2.0.0.maingets the same fix through #735.The ENR this node serves over discv5 keeps the fork digest it started with across a fork boundary (#932): ethrex's
DiscoveryServercannot replace its record at runtime. #735 fixes that, but it depends on ethrex work that is not in a release (lambdaclass/ethrex#7488), 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 higherseq. 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.mdlisted this as a known limitation for upgrades ("An upgrade's new ENR entries are invisible to peers that stayed up").This PR takes two parts of #735: the starting
seq, and the record kept across restarts. Neither needs an ethrex change or a lockfile change.The second part is there because of the first. A record that starts at the clock is newer than the one peers hold, and on a node started without
--discovery.advertise-ipit is at the bind address,0.0.0.0. Peers would swap a record they can dial for one they cannot, until IP voting settled again. The AI security review raised this on #735 (its M1), and the fix here is the one made there.What Changed
crates/net/p2p/src/discovery/enr.rs:build_local_enr_aftersigns the record atstarting_seq(previous_seq): the current time in milliseconds, or one past theseqof the record this node last served where the clock has not got that far.carried_overreads what a start may take from that last record, its address and itsseq, and takes nothing from a record under another node key or with a bad signature.crates/net/p2p/src/discovery/mod.rs:spawn_discoverytakes the last record. A start that names no address takes the last record's, within the address family the discovery socket is bound on (resumes_address), and logs that it did. IP voting stays on in that case.ServedEnrreads the served record through the mirror ethrex writes each re-signed record into, which this branch used to hand over and drop.update_served_enr) ends with "Restart the node to publish the new fork digest".crates/net/p2p/src/discovery/dial.rs:save_served_enr, called on every dial tick, saves the served record when itsseqhas moved. IP voting re-signs the record inside ethrex, so there is no event to save it on.crates/net/p2p/src/lib.rs:P2P::spawnreads the saved record and hands it tospawn_discovery.crates/storage/src/store.rs:Store::local_enr/set_local_enr, a newMetadatarow (local_enr). An older directory has no row;DB_VERSIONdoes not change.docs/discovery.md,docs/beacon_wire.md,docs/data_storage.md,docs/cli.md(the--node-keyrow said the ENR stays the same across restarts) andCLAUDE.md.Correctness / Behavior Guarantees
seqthe previous run reached: above the clock in every ordinary case, and above the saved record'sseqwhen the clock reads earlier than it did.--discovery.advertise-ipstarts at the address its last record carried. If the address has changed, peers dial a stale one until IP voting replaces it, which is what they did with their cached record before this PR.seq = 1record peers hold from an earlier version.ethlambda nodewith--discovery.enabletoo: same code.Tests Added / Run
enr:the_record_starts_at_the_clock_not_at_a_fixed_seq,a_start_takes_over_the_address_and_seq_of_this_nodes_last_record,a_last_record_that_never_found_its_address_carries_only_its_seq,a_record_under_another_key_carries_nothing_over,a_record_starts_above_the_last_one_whatever_the_clock_says.discovery:a_restart_serves_the_address_its_last_record_carried,an_address_the_operator_names_is_not_replaced_by_the_last_records,the_last_address_is_taken_only_within_the_bound_family.dial:the_served_record_is_saved_once_and_again_when_it_moves.store:the_served_enr_survives_a_reopen.cargo test -p ethlambda-p2p --profile release-fast --lib(575 passed, 1 ignored),cargo test -p ethlambda-storage --profile release-fast --lib(247 passed, 2 ignored),make lintandcargo fmt --all -- --checkclean.make test.pong_message.enr_seq > cached_seq; the handshake sends the record only whenseqdiffers from the requester's); for other clients it is the ENR spec's rule.Related Issues / PRs
nfdremain)main. The two differ in how the served record is read: feat(discovery): republish the ENR's eth2 entry at fork boundaries #735 has an editable record (LocalEnrWriter), andmainhasLocalEnrfrom feat(discovery): hunt attestation subnet peers with discv5 predicate queries #732; this branch has neither, henceServedEnr. When the release branch is merged back intomain, the discovery module will conflict there, andmain's version is the one to keep.main. It was rebuilt onrelease/v2.0.0and retargeted, sincemaingets the fix through feat(discovery): republish the ENR's eth2 entry at fork boundaries #735.✅ Verification Checklist
make fmt— cleanmake lint(clippy with-D warnings) — cleanmake test(test-consensus,test-nodeandtest-ethrex, atrelease-fast) — all passing (onlyethlambda-p2p --libandethlambda-storage --lib)