Skip to content

refactor(p2p,eth): replace pair-peer with BFT write priority, close #2359#2360

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

refactor(p2p,eth): replace pair-peer with BFT write priority, close #2359#2360
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:drop-peer-dual-connection

Conversation

@gzliudan

@gzliudan gzliudan commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

This PR close #2359.

Drop the per-peer dual TCP (pair-peer) mechanism and restore the upstream devp2p semantics of one connection per NodeID. To preserve the original goal of low BFT write latency, introduce a two-level write priority in the per-peer write scheduler so XDPoS v2 consensus messages (VoteMsg, TimeoutMsg, SyncInfoMsg) preempt block/tx traffic at the next write boundary.

p2p: remove Peer.pairPeer/PairPeer/SetPairPeer/ClearPairPeer, ErrAddPairPeer, and the pair branches in Server.encHandshakeChecks/addpeer/removePeerTracking and dialstate.checkDial. Keep the DiscPairPeerStop enum slot for wire compatibility with peers that still send it.

p2p: add PriorityMsgWriter interface and SendPriority helper. Rework Peer.run write arbitration: replace the single writeStart token with buffered hi/lo writeSlot request queues; non-blocking hi-bias when idle, blocking select on both otherwise, and a starvation guard that forces one lo through after writePriorityStarveLimit (16) consecutive hi writes.

eth: drop pairRw from peer and the ErrAddPairPeer fast-path in ProtocolManager.handle; collapse the pair fallback in peerSet.Register. Route SendVote/SendTimeout/SendSyncInfo through p2p.SendPriority.

Tests: revert p2p/dial_test.go and p2p/server_test.go to upstream geth expectations, drop pair-only cases, and add p2p/peer_priority_test.go covering hi/lo preemption, the starvation guard, and the non-priority fallback path.

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 May 28, 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: e776f062-018c-48ce-8c41-deb5994efc52

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 and usage tips.

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 the XDPoS pair-peer dual-connection mechanism and replaces its BFT-latency goal with per-peer high/low priority write scheduling in the p2p message path.

Changes:

  • Removes pair-peer state, duplicate-connection allowances, and eth pair writer fallback paths.
  • Adds PriorityMsgWriter / SendPriority and routes Vote, Timeout, and SyncInfo messages through the high-priority lane.
  • Updates dial/server tests and adds priority scheduler tests for preemption, starvation guard, and fallback behavior.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
p2p/server.go Rejects duplicate NodeID connections and removes pair-peer tracking.
p2p/server_test.go Updates server peer tracking tests for single-peer semantics.
p2p/peer.go Adds high/low write request queues and priority arbitration.
p2p/peer_test.go Removes pair-peer disconnect behavior test.
p2p/peer_priority_test.go Adds tests for priority write scheduling behavior.
p2p/peer_error.go Removes ErrAddPairPeer.
p2p/message.go Adds SendPriority helper with fallback to normal writes.
p2p/dial.go Restores duplicate peer dial rejection.
p2p/dial_test.go Updates dial state expectations for one connection per NodeID.
eth/peer.go Removes pairRw and uses priority sends for BFT messages.
eth/handler.go Simplifies peer registration now that pair peers are removed.

Comment thread p2p/message.go
Comment thread p2p/peer.go Outdated
@gzliudan gzliudan force-pushed the drop-peer-dual-connection branch 2 times, most recently from 4d8709c to 3771f6b Compare May 28, 2026 06:26
@gzliudan gzliudan changed the title refactor(p2p,eth): replace pair-peer with BFT write priority refactor(p2p,eth): replace pair-peer with BFT write priority, close #2359 May 28, 2026
@gzliudan gzliudan force-pushed the drop-peer-dual-connection branch 3 times, most recently from bb807f4 to a37847c Compare May 28, 2026 07:01
@gzliudan gzliudan requested a review from Copilot May 28, 2026 07:02

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 13 out of 13 changed files in this pull request and generated no new comments.

@gzliudan gzliudan force-pushed the drop-peer-dual-connection branch 8 times, most recently from 43397e7 to 8e66ebd Compare May 29, 2026 07:18
@gzliudan gzliudan force-pushed the drop-peer-dual-connection branch from 8e66ebd to 4f92775 Compare June 2, 2026 02:47
@gzliudan gzliudan force-pushed the drop-peer-dual-connection branch from 4f92775 to 77c08ce Compare June 8, 2026 03:34
@gzliudan gzliudan force-pushed the drop-peer-dual-connection branch from 77c08ce to 4548fb3 Compare June 11, 2026 06:43
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