Skip to content

feat(sensor): derive fork IDs from a fork schedule - #1058

Open
minhd-vu wants to merge 2 commits into
mainfrom
feat/sensor-next-fork
Open

minhd-vu wants to merge 2 commits into
mainfrom
feat/sensor-next-fork

Conversation

@minhd-vu

@minhd-vu minhd-vu commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

p2p sensor only accepted peers whose fork ID hash equalled --fork-id, and advertised that hash with Next: 0. A hard fork changes the fork ID at its activation block, and under EIP-2124 an upgraded node then rejects a peer that still advertises the old hash with no next fork. Connections opened before the fork survive it, because the fork ID is only checked in the handshake. But once a sensor restarts after a fork, it can only reach nodes that never upgraded, which are stuck on the block before the fork and announce no new blocks.

This happened on Amoy after the Salvador fork at block 54483500: a sensor restarted on the pre-fork ID received no block announcements until its configuration was changed.

  • --fork-blocks and --fork-times take every fork since genesis that changes the fork ID, including scheduled ones; --fork-times covers forks activated by timestamp. With --genesis-hash, the sensor computes each fork ID the way a node does from its chain config: it sorts the forks, drops duplicates and drops forks at block 0. No hash is entered by hand.
  • The advertised fork ID is computed for the sensor's head at each handshake, including the next scheduled fork. The sensor moves to the new fork ID when its head passes a fork, with no restart or config change.
  • Peers on any fork ID in the schedule are accepted, including nodes that never upgraded past a fork. They still relay transactions, and a sensor has room for many peers.
  • Guards against a wrong schedule:
    • An explicitly set --fork-id must be one of the schedule's fork IDs, so a wrong genesis hash or fork list fails at startup.
    • A peer on the sensor's own fork ID that expects a different next fork is logged as a warning. That catches a wrong scheduled fork before it activates.
  • A rejected peer's error lists the accepted fork IDs, and the sensor logs them at startup.
  • --fork-id is checked to be 4 bytes. A wrong length used to panic on the array conversion.
  • With neither new flag set, the sensor behaves as before: it advertises --fork-id with no next fork and accepts only that hash.
  • Docs: the sensor usage doc has a new "Fork IDs" section. The examples include each network's fork list, and the Amoy example uses the post-Salvador fork ID, dbfe071c.

go-ethereum's forkid.NewFilter isn't used for validation because it needs a params.ChainConfig, which can't describe the Bor-specific forks. It would also reject the not-upgraded peers that the sensor deliberately keeps.

Testing

  • p2p/forkid_test.go:
    • The Polygon mainnet and Amoy fork lists give the fork IDs Bor publishes, on both sides of Salvador: 22d523b2 → a19b27ae at 98803800, and 8b7e4175 → dbfe071c at 54483500.
    • Unsorted lists with duplicates and 0 give the same schedule. Time forks follow block forks.
    • With --fork-id alone, the sensor knows exactly that one hash.
    • On a chain with one fork, the schedule matches forkid.NewIDWithChain. forkid.NewFilter accepts the sensor's advertised ID from a node on either side of the fork, with the sensor's head on either side. A post-fork node rejects the pre-fork hash with Next: 0, which was the old behaviour.
  • cmd/p2p/sensor/forks_test.go: covers --fork-id alone, a short fork ID, a schedule with and without an explicit --fork-id, a wrong fork block caught by the --fork-id check, and a malformed genesis hash.
  • go test ./p2p/... ./cmd/p2p/... passes, and golangci-lint reports 0 issues.
  • make gen-doc regenerated doc/polycli_p2p_sensor.md.
  • Live runs, 80 s each, with a fresh node list and the fork lists from the docs:
    • Amoy: the head is past Salvador, so the sensor advertised dbfe071c. It accepted 16 upgraded peers on dbfe071c and 10 on 8b7e4175.
    • Polygon mainnet: 33 peers accepted, with no "different next fork" warnings, so the Salvador block that upgraded peers advertise matches the schedule.

🤖 Generated with Claude Code

minhd-vu and others added 2 commits December 4, 2026 12:48
…ork-block

The sensor only accepted peers whose fork ID hash equalled --fork-id and
advertised that hash with no next fork. After a hard fork, upgraded nodes
reject that ID, so a sensor restarted after the fork only reached nodes
that never upgraded.

--next-fork-block advertises the fork's block as the fork ID's next field,
which EIP-2124 nodes accept on both sides of the fork, and --next-fork-id
accepts peers on the post-fork hash too. --fork-id is now checked to be 4
bytes instead of panicking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace --next-fork-id and --next-fork-block with --fork-blocks and
--fork-times. With --genesis-hash the sensor computes every fork ID in the
schedule as a node does, advertises the one for its current head with the
next scheduled fork, and accepts peers on any of them. It moves to a new
fork ID at a fork on its own, and no hash is entered by hand.

An explicitly set --fork-id must be in the schedule, so a wrong genesis hash
or fork list fails at startup, and a peer on the sensor's fork ID that
expects a different next fork is logged. A rejected peer's error lists the
accepted fork IDs, and only the schedule is passed through the handshake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@minhd-vu minhd-vu changed the title feat(sensor): cross a scheduled fork with --next-fork-id and --next-fork-block feat(sensor): derive fork IDs from a fork schedule Dec 4, 2026
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