Skip to content

p2p/protocols/eth, p2p/sentry/libsentry, node/direct: derive msgid tables instead of triple-maintaining them#22175

Draft
yperbasis wants to merge 2 commits into
mainfrom
yperbasis/eth-msgid-tables
Draft

p2p/protocols/eth, p2p/sentry/libsentry, node/direct: derive msgid tables instead of triple-maintaining them#22175
yperbasis wants to merge 2 commits into
mainfrom
yperbasis/eth-msgid-tables

Conversation

@yperbasis

Copy link
Copy Markdown
Member

Every new eth protocol version copied ~14-entry message-id map blocks into three hand-maintained tables: eth.ToProto, eth.FromProto (its inverse), and libsentry.ProtoIds. eth/68→71 accumulated four copies in each.

Now: ToProto is a literal eth/68 base plus per-version deltas (3/2/2 entries for 69/70/71); FromProto is derived by inversion with a collision panic; ProtoIds is derived in libsentry from the FromProto keysets. The one deliberate asymmetry is preserved and pinned: FromProto/ProtoIds omit STATUS_69 for eth/69+ (status is handshake-only; SendMessageById must not emit a status frame) — TestFromProtoOmitsStatus derives the omitted set from goldens and asserts it exactly. wit's single-version tables get the same inversion treatment.

Golden tests were committed and verified green before the refactor: three external-package test files pin the exact pre-refactor content of all three tables with literal version keys (+325 test lines).

Structural note: the import graph pointed the wrong way for a single-copy derivation (eth imported node/direct for the version constants). The version constants ETH68..ETH71 move into package eth (where the protocol lives), direct re-exports everything as aliases so its ~109 external usage sites are untouched, and the version↔sentryproto.Protocol bridge maps live once in libsentry. The alias direction makes a future eth → direct re-import a compile error.

Net −72 production lines, and the next eth version becomes a one-delta change. Verified: goldens pre/post, go test ./p2p/... ./node/direct/..., scoped golangci-lint clean (×2), make erigon.

Part of a dedup series; siblings #22165#22174.

yperbasis added 2 commits July 2, 2026 22:00
…sts for message-id tables

Pin the exact content of eth.ToProto/eth.FromProto, wit.ToProto/wit.FromProto
and libsentry.ProtoIds ahead of deriving them from a single source per
protocol version. TestFromProtoOmitsStatus additionally pins the deliberate
asymmetry: FromProto for eth/69+ omits the status ids (status is
handshake-only and must stay unreachable via SendMessageById).
…ct: single source per version for message-id tables

Previously every new eth version required copying a ~14-entry message-id
map into three files: eth.ToProto, eth.FromProto (hand-written inverse)
and libsentry.ProtoIds (hand-written value-set). Now each eth version's
ToProto map is built as a clone of the previous version plus a delta, and
the other two tables are derived from it:

- eth.FromProto = inversion of ToProto, skipping StatusMsg so that
  SendMessageById can never emit a status frame (the pre-existing,
  deliberate asymmetry, pinned by TestFromProtoOmitsStatus);
- libsentry.ProtoIds = key sets of eth.FromProto and wit.FromProto,
  which is exactly what the hand-written table contained (including the
  status omission for eth/69+);
- wit.FromProto = inversion of wit.ToProto.

Deriving ProtoIds requires libsentry to import the protocol packages, so
the dependency direction is flipped: the ETH68..ETH71 version constants
move from node/direct into p2p/protocols/eth (wit already had WIT1), and
the version<->Protocol bridge maps move from node/direct into libsentry.
node/direct keeps its former API as aliases, so no call sites change.
Inversions and bridge lookups panic on collisions/missing versions so a
future version bump cannot silently drop or misroute an entry.

Golden tests pin all three tables to their exact pre-refactor content.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes triple-maintained ETH/WIT message-id tables by deriving FromProto (and libsentry.ProtoIds) from a single ToProto source-of-truth, while preserving the deliberate “status is handshake-only” asymmetry.

Changes:

  • Refactors eth and wit protocol msg-id mappings to derive FromProto via inversion (with collision panics) and constructs ETH version tables via “base + deltas”.
  • Derives libsentry.ProtoIds from eth.FromProto / wit.FromProto, and centralizes protocol-version ↔ sentryproto.Protocol bridge maps in libsentry.
  • Moves ETH version constants into p2p/protocols/eth and re-exports them from node/direct to avoid import cycles without changing external call sites; adds golden tests pinning pre-refactor table contents.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
p2p/sentry/libsentry/protocol.go Centralizes protocol-version bridge maps and derives ProtoIds from protocol FromProto tables.
p2p/sentry/libsentry/protocol_msgid_golden_test.go Golden test pinning libsentry.ProtoIds content.
p2p/protocols/wit/protocol.go Derives wit.FromProto by inverting ToProto (collision-checked).
p2p/protocols/wit/protocol_msgid_golden_test.go Golden tests pinning wit.ToProto / wit.FromProto.
p2p/protocols/eth/protocol.go Introduces ETH version constants in-package; builds ToProto via base+delta and derives FromProto via inversion omitting status.
p2p/protocols/eth/protocol_test.go Updates tests to use eth.ETH71 constant directly (no direct import).
p2p/protocols/eth/protocol_msgid_golden_test.go Golden tests pinning eth.ToProto / eth.FromProto and asserting status omission contract.
p2p/protocols/eth/handlers.go Updates documentation comment examples to use eth.ETH* constants.
p2p/protocols/eth/handlers_receipts_query_test.go Updates receipt query test to use eth.ETH68 constant (no direct import).
node/direct/sentry_client.go Re-exports ETH/WIT version constants and protocol maps via eth/wit/libsentry to keep external usages unchanged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants