Skip to content

fix(p2p,eth): remove per-peer dual-connection mechanism, close #2351 #2359#2433

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:drop-peer-dual-tcp
Open

fix(p2p,eth): remove per-peer dual-connection mechanism, close #2351 #2359#2433
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:drop-peer-dual-tcp

Conversation

@gzliudan

@gzliudan gzliudan commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

XDPoSChain kept two independent RLPx/TCP connections per remote peer (a "primary" and a "pair"), a private divergence from upstream go-ethereum which allows only one connection per NodeID. This adds state-machine complexity (isPair, pairRw, PairPeer, ErrAddPairPeer, DiscPairPeerStop) without measured benefit, and the pair connection already carried both block-sync and BFT traffic, so it never isolated Vote/Timeout/SyncInfo from large BlockBodies/NodeData frames.

Revert to a single connection per NodeID (upstream semantics) and route all eth messages, including the XDPoS v2 BFT messages, over that single connection using the existing upstream FIFO write scheduling. No write-priority lane is added; RLPx framing, message ids, capability strings and the handshake are unchanged, so the change is rolling-upgrade safe against legacy pair-capable nodes.

Changes:

  • p2p/server.go: postHandshakeChecks rejects any duplicate NodeID with DiscAlreadyConnected; addPeer no longer stores a second connection.
  • p2p/peer.go: drop pairPeer field/methods and the DiscPairPeerStop cascade on Peer.run exit.
  • p2p/peer_error.go: remove ErrAddPairPeer; keep the DiscPairPeerStop enum slot (deprecated) to preserve on-the-wire numbering.
  • eth/peer.go: remove pairRw; all Send/Request helpers use p.rw; peerSet.Register reverts to one peer per id.
  • eth/handler.go: drop ErrAddPairPeer special-casing so every peer registers with the downloader and syncs transactions.

fix #2351 and #2359

replace #2360

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

@gzliudan gzliudan changed the title refactor(p2p,eth): remove per-peer dual-connection mechanism, close #2351 #2359 refactor(p2p,eth): remove per-peer dual-connection mechanism, fix #2351 #2359 Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 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: 80aa029e-e36b-4796-be3e-59d19345ed26

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 removes XDPoSChain’s per-peer “dual connection” (primary + pair) RLPx mechanism and returns to upstream-style semantics of a single active connection per remote NodeID, routing all ETH/BFT traffic over the single negotiated session.

Changes:

  • Enforce single-connection-per-NodeID in the p2p server by rejecting duplicates with DiscAlreadyConnected.
  • Remove pair-peer lifecycle/state from p2p.Peer and delete the associated test.
  • Simplify the ETH peer implementation to use only p.rw, and make peerSet.Register strictly reject duplicate IDs; handler always registers peers with the downloader.

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
p2p/server.go Rejects duplicate NodeID connections and stores only one peer per ID.
p2p/peer.go Removes pair-peer state and the pair-disconnect cascade on shutdown.
p2p/peer_test.go Deletes the pair-peer shutdown test (no longer applicable).
p2p/peer_error.go Removes ErrAddPairPeer; keeps DiscPairPeerStop enum slot as deprecated for wire-number stability.
eth/peer.go Removes pairRw routing and makes peer registration strictly one-per-id.
eth/peer_test.go Adds a regression test that duplicate IDs are rejected by peerSet.Register.
eth/handler.go Removes ErrAddPairPeer special-casing so every peer is registered with the downloader and tx sync.

Comment thread p2p/server.go
@gzliudan gzliudan force-pushed the drop-peer-dual-tcp branch 2 times, most recently from a2a4be7 to 4aab775 Compare July 2, 2026 07:17
@gzliudan gzliudan changed the title refactor(p2p,eth): remove per-peer dual-connection mechanism, fix #2351 #2359 fix(p2p,eth): remove per-peer dual-connection mechanism, close #2351 #2359 Jul 2, 2026
…Org#2351 XinFinOrg#2359

XDPoSChain kept two independent RLPx/TCP connections per remote peer
(a "primary" and a "pair"), a private divergence from upstream
go-ethereum which allows only one connection per NodeID. This adds
state-machine complexity (isPair, pairRw, PairPeer, ErrAddPairPeer,
DiscPairPeerStop) without measured benefit, and the pair connection
already carried both block-sync and BFT traffic, so it never isolated
Vote/Timeout/SyncInfo from large BlockBodies/NodeData frames.

Revert to a single connection per NodeID (upstream semantics) and route
all eth messages, including the XDPoS v2 BFT messages, over that single
connection using the existing upstream FIFO write scheduling. No
write-priority lane is added; RLPx framing, message ids, capability
strings and the handshake are unchanged, so the change is rolling-upgrade
safe against legacy pair-capable nodes.

Changes:
- p2p/server.go: postHandshakeChecks rejects any duplicate NodeID with
  DiscAlreadyConnected; addPeer no longer stores a second connection.
- p2p/peer.go: drop pairPeer field/methods and the DiscPairPeerStop
  cascade on Peer.run exit.
- p2p/peer_error.go: remove ErrAddPairPeer; keep the DiscPairPeerStop
  enum slot (deprecated) to preserve on-the-wire numbering.
- eth/peer.go: remove pairRw; all Send/Request helpers use p.rw;
  peerSet.Register reverts to one peer per id.
- eth/handler.go: drop ErrAddPairPeer special-casing so every peer
  registers with the downloader and syncs transactions.

Refs: XinFinOrg#2359
@gzliudan gzliudan force-pushed the drop-peer-dual-tcp branch from 4aab775 to aee570b Compare July 2, 2026 07:26
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.

2 participants