fix(p2p/enode): fix endpoint determination for IPv6 #29801#2461
fix(p2p/enode): fix endpoint determination for IPv6 #29801#2461gzliudan wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 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 |
There was a problem hiding this comment.
Pull request overview
This PR updates p2p/enode.Node endpoint selection to correctly determine and prefer the “most global” announced address across IPv4/IPv6 (not always preferring IPv4), and switches endpoint handling to netip for clearer address semantics.
Changes:
- Add
enr.IPv4Addr/enr.IPv6Addrentries backed bynetip.Addrfor ENR"ip"/"ip6"keys. - Cache the selected endpoint (
ip,udp,tcp) insideenode.Nodeat construction time, using a locality-based preference between IPv4 and IPv6. - Update URL/CLI endpoint formatting and add a table-driven test for endpoint selection behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| p2p/enr/entries.go | Adds netip-based ENR IP entry types for "ip" and "ip6". |
| p2p/enode/node.go | Introduces cached endpoint fields and locality-based IPv4/IPv6 endpoint selection. |
| p2p/enode/nodedb.go | Updates DB node decoding to reconstruct nodes via the new constructor logic. |
| p2p/enode/urlv4.go | Switches URL formatting “missing IP” check to use cached netip validity. |
| p2p/enode/idscheme.go | Ensures SignNull returns a node with endpoint cache initialized. |
| p2p/enode/node_test.go | Adds endpoint-selection tests for mixed IPv4/IPv6 records. |
| cmd/devp2p/discv4cmd.go | Updates endpoint formatting to use IPAddr().IsValid() instead of Incomplete(). |
| func (n *Node) setIPv4Ports() { | ||
| if err := n.Load((*enr.UDP)(&n.udp)); err != nil { | ||
| n.Load((*enr.UDP6)(&n.udp)) | ||
| } | ||
| if err := n.Load((*enr.TCP)(&n.tcp)); err != nil { | ||
| n.Load((*enr.TCP6)(&n.tcp)) | ||
| } | ||
| } |
Proposed changes
Ref: ethereum#29801
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