Skip to content

feat(eth): implement EIP-2364 - xdc/164 handshake with fork ID #20140#2470

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:xdc164
Open

feat(eth): implement EIP-2364 - xdc/164 handshake with fork ID #20140#2470
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:xdc164

Conversation

@gzliudan

@gzliudan gzliudan commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

Adapt go-ethereum PR ethereum#20140 (EIP-2364) to extend the Status handshake
for xdc/164 with ForkID-based compatibility checks.

  • Keep runtime protocol negotiation as [xdc164, xdc100, eth63].
  • Use statusData (with ForkID) for xdc164 and statusData63 (legacy, no ForkID)
    for xdc100/eth63.
  • Split status decoding into readStatus/readStatusLegacy and validate ForkID
    through the ProtocolManager fork filter.
  • Align status error naming with upstream and include ErrForkIDRejected.

Tests:

  • Move the newly added 64-path coverage to 164-path coverage to match runtime
    protocol support.
  • Add status error coverage for protocol 63/100/164.
  • Validate fork split behavior with protocol 164.
  • Add 164 variants for header/body/node-data/receipt and tx send/receive tests.

Compatibility note: xdc100 keeps the legacy statusData63 layout for peers that
still run older xdpos2/100 implementations without ForkID.

Refs:

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6f6d0ea4-fafd-4fb5-8ad8-6ef2c05ed0a5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

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 ports go-ethereum’s EIP-2364 handshake extension to add ForkID negotiation for eth/64 and xdc/164, enabling early rejection of incompatible peers during the status handshake while preserving legacy compatibility for eth/63 and xdc/100.

Changes:

  • Add protocol versions eth64 and xdc164, updating the supported-version negotiation order.
  • Introduce a ForkID-carrying status packet for eth/64+ (and xdc/164) alongside a legacy status packet for eth/63 and xdc/100, plus corresponding handshake read helpers.
  • Add/adjust tests for status-handshake error cases and ForkID-based chain splitting behavior; expand existing handler tests to cover eth/64.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
eth/protocol.go Adds new protocol versions and defines legacy vs ForkID status packet types and new error codes.
eth/peer.go Extends handshake to send/validate ForkID for eth/64 & xdc/164 while keeping legacy status for older versions.
eth/handler.go Stores a long-lived forkid.Filter on ProtocolManager and wires ForkID + filter into peer handshakes.
eth/protocol_test.go Adds/updates status handshake error tests for 63/64/100 and introduces ForkID split tests.
eth/helper_test.go Updates test handshake helpers to emit the correct status packet per protocol version.
eth/handler_test.go Adds eth/64 variants of existing protocol handler tests.
core/forkid/forkid.go Introduces a forkid.Filter type alias and tweaks filter head/fork boundary logic.
Comments suppressed due to low confidence (1)

eth/helper_test.go:268

  • testPeer.handshake is called with t == nil from newTestPeer (when shake==true), but the function unconditionally calls t.Fatalf, which will panic with a nil pointer dereference and break any tests that use implicit handshakes. Handle the nil case explicitly (or refactor handshake to return an error).
	if err := p2p.ExpectMsg(p.app, StatusMsg, msg); err != nil {
		t.Fatalf("status recv: %v", err)
	}
	if err := p2p.Send(p.app, StatusMsg, msg); err != nil {
		t.Fatalf("status send: %v", err)

Comment thread eth/protocol_test.go
@gzliudan
gzliudan force-pushed the xdc164 branch 2 times, most recently from 5c467df to 963c40a Compare July 16, 2026 15:37
@gzliudan gzliudan changed the title feat(eth): implement EIP-2364 — eth/64 handshake with fork ID #20140 feat(eth): implement EIP-2364 - eth/64 handshake with fork ID #20140 Jul 16, 2026
@gzliudan gzliudan changed the title feat(eth): implement EIP-2364 - eth/64 handshake with fork ID #20140 feat(eth): implement EIP-2364 - xdc/164 handshake with fork ID #20140 Jul 16, 2026
@gzliudan
gzliudan requested a review from Copilot July 17, 2026 00:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

eth/helper_test.go:266

  • testPeer.handshake is called with a nil *testing.T (see newTestPeer), but this method calls t.Fatalf on send/receive errors. If the handshake ever fails, this will panic with a nil pointer dereference and hide the real failure cause. Handle the nil case explicitly (panic with a helpful message) so failures remain diagnosable.
		panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version))
	}
	if err := p2p.ExpectMsg(p.app, StatusMsg, msg); err != nil {
		t.Fatalf("status recv: %v", err)
	}

Comment thread eth/protocol_test.go
Comment on lines +235 to +236
chainNoFork, _ = core.NewBlockChain(dbNoFork, nil, gspecNoFork, engine, vm.Config{})
chainProFork, _ = core.NewBlockChain(dbProFork, nil, gspecProFork, engine, vm.Config{})
Comment thread eth/protocol_test.go
Comment on lines +274 to +275
chainNoFork.InsertChain(blocksNoFork[:1])
chainProFork.InsertChain(blocksProFork[:1])
Comment thread eth/protocol_test.go
Comment on lines +298 to +299
chainNoFork.InsertChain(blocksNoFork[1:2])
chainProFork.InsertChain(blocksProFork[1:2])
@gzliudan
gzliudan force-pushed the xdc164 branch 2 times, most recently from 7325260 to 49b0324 Compare July 17, 2026 03:09
…um#20140

Adapt go-ethereum PR ethereum#20140 (EIP-2364) to extend the Status handshake
for xdc/164 with ForkID-based compatibility checks.

- Keep runtime protocol negotiation as [xdc164, xdc100, eth63].
- Use statusData (with ForkID) for xdc164 and statusData63 (legacy, no ForkID)
  for xdc100/eth63.
- Split status decoding into readStatus/readStatusLegacy and validate ForkID
  through the ProtocolManager fork filter.
- Align status error naming with upstream and include ErrForkIDRejected.

Tests:
- Move the newly added 64-path coverage to 164-path coverage to match runtime
  protocol support.
- Add status error coverage for protocol 63/100/164.
- Validate fork split behavior with protocol 164.
- Add 164 variants for header/body/node-data/receipt and tx send/receive tests.

Compatibility note: xdc100 keeps the legacy statusData63 layout for peers that
still run older xdpos2/100 implementations without ForkID.

Refs: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2364.md
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.

3 participants