Skip to content

feat(p2p/discover,cmd/devp2p): export Ping and add discv4 ping tools#2421

Draft
anunay-xin wants to merge 2 commits into
dev-upgradefrom
feat/discv4-ping-export
Draft

feat(p2p/discover,cmd/devp2p): export Ping and add discv4 ping tools#2421
anunay-xin wants to merge 2 commits into
dev-upgradefrom
feat/discv4-ping-export

Conversation

@anunay-xin

Copy link
Copy Markdown
Collaborator

Expose Table.Ping and ErrTimeout for external UDP health checks, and add a devp2p discv4 ping/check CLI for bootnode reachability testing.

Proposed changes

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

Expose Table.Ping and ErrTimeout for external UDP health checks, and add
a devp2p discv4 ping/check CLI for bootnode reachability testing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

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: 8ffc0021-a99f-40a1-b615-c0e6331daf63

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
  • Commit unit tests in branch feat/discv4-ping-export

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.

@anunay-xin anunay-xin closed this Jun 26, 2026
@anunay-xin anunay-xin deleted the feat/discv4-ping-export branch June 26, 2026 12:29
@anunay-xin anunay-xin restored the feat/discv4-ping-export branch June 26, 2026 13:16
@anunay-xin anunay-xin reopened this Jun 26, 2026
Comment thread p2p/discover/udp.go
errUnknownNode = errors.New("unknown node")
errTimeout = errors.New("RPC timeout")
ErrTimeout = errors.New("RPC timeout")
errTimeout = ErrTimeout

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you reorder this variable to either top or bottom of it, beautify this var structure

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 exposes discovery v4 ping primitives from p2p/discover (exported Table.Ping and ErrTimeout) and introduces a new cmd/devp2p CLI with discv4 ping / discv4 check subcommands for UDP reachability testing of bootnodes/enodes.

Changes:

  • Export discover.ErrTimeout for external callers to reliably detect ping timeouts.
  • Add (*discover.Table).Ping(*enode.Node) as a public wrapper around the underlying UDP ping implementation.
  • Add a new devp2p binary with discv4 ping (single node) and discv4 check (batch file) commands.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
p2p/discover/udp.go Exports the discovery RPC timeout sentinel error for external timeout detection.
p2p/discover/table.go Adds an exported Table.Ping helper to perform discv4 ping/pong.
cmd/devp2p/main.go Adds a new devp2p CLI entrypoint wiring in discv4 commands.
cmd/devp2p/discv4cmd.go Implements discv4 ping and discv4 check, including discovery startup and retry logic.

Comment thread p2p/discover/udp.go
Comment on lines 42 to +44
errUnknownNode = errors.New("unknown node")
errTimeout = errors.New("RPC timeout")
ErrTimeout = errors.New("RPC timeout")
errTimeout = ErrTimeout
Comment thread cmd/devp2p/main.go
Comment on lines +5 to +19
import (
"fmt"
"os"

"github.com/urfave/cli/v2"
)

var app = &cli.App{
Name: "devp2p",
Usage: "XDC devp2p tools",
Commands: []*cli.Command{
discv4Command,
},
}

Comment thread cmd/devp2p/discv4cmd.go
Comment on lines +113 to +117
timeout := ctx.Duration(timeoutFlag.Name)
parallel := ctx.Int(checkParallelFlag.Name)
if parallel < 1 {
return errors.New("parallel must be at least 1")
}
Comment thread cmd/devp2p/discv4cmd.go
var ok, fail int
for _, r := range results {
fmt.Fprintln(out, r.line)
if strings.Contains(r.line, "UDP_PONG") {
Comment thread cmd/devp2p/discv4cmd.go
Comment on lines +206 to +217
conn, err := net.ListenPacket("udp4", ctx.String(listenAddrFlag.Name))
if err != nil {
return nil, nil, err
}
udpConn := conn.(*net.UDPConn)
db, err := enode.OpenDB("")
if err != nil {
conn.Close()
return nil, nil, err
}
ln := enode.NewLocalNode(db, key)
tab, err := discover.ListenUDP(udpConn, ln, discover.Config{PrivateKey: key})
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