feat(p2p/discover,cmd/devp2p): export Ping and add discv4 ping tools#2421
feat(p2p/discover,cmd/devp2p): export Ping and add discv4 ping tools#2421anunay-xin wants to merge 2 commits into
Conversation
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>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
| errUnknownNode = errors.New("unknown node") | ||
| errTimeout = errors.New("RPC timeout") | ||
| ErrTimeout = errors.New("RPC timeout") | ||
| errTimeout = ErrTimeout |
There was a problem hiding this comment.
can you reorder this variable to either top or bottom of it, beautify this var structure
There was a problem hiding this comment.
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.ErrTimeoutfor 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
devp2pbinary withdiscv4 ping(single node) anddiscv4 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. |
| errUnknownNode = errors.New("unknown node") | ||
| errTimeout = errors.New("RPC timeout") | ||
| ErrTimeout = errors.New("RPC timeout") | ||
| errTimeout = ErrTimeout |
| import ( | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/urfave/cli/v2" | ||
| ) | ||
|
|
||
| var app = &cli.App{ | ||
| Name: "devp2p", | ||
| Usage: "XDC devp2p tools", | ||
| Commands: []*cli.Command{ | ||
| discv4Command, | ||
| }, | ||
| } | ||
|
|
| timeout := ctx.Duration(timeoutFlag.Name) | ||
| parallel := ctx.Int(checkParallelFlag.Name) | ||
| if parallel < 1 { | ||
| return errors.New("parallel must be at least 1") | ||
| } |
| var ok, fail int | ||
| for _, r := range results { | ||
| fmt.Fprintln(out, r.line) | ||
| if strings.Contains(r.line, "UDP_PONG") { |
| 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}) |
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 applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that