Skip to content

feat(p2p): ENR updates for discovery v4 compatibility #16679#2010

Merged
AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:enr-v4compat
Feb 6, 2026
Merged

feat(p2p): ENR updates for discovery v4 compatibility #16679#2010
AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:enr-v4compat

Conversation

@gzliudan
Copy link
Copy Markdown
Collaborator

Proposed changes

Ref: ethereum#16679

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

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
  • 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

Copilot AI review requested due to automatic review settings January 28, 2026 07:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 28, 2026

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.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Copy Markdown

Copilot AI left a comment

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 refactors the ENR implementation to support the discovery v4 identity scheme, including pluggable identity schemes and updated ENR fields for IP/ports, while updating tests for interoperability and size limits.

Changes:

  • Introduces a pluggable identity scheme registry with a concrete v4 scheme (signing, verification, and node address derivation) and a dedicated SignV4 helper.
  • Simplifies ENR entry types by unifying IP handling into a single IP entry, introducing UDP/TCP keys, and wiring records to use identity schemes for signature verification and NodeAddr.
  • Updates ENR tests to use the new API (SignV4, IP, UDP), adjusts Python-interoperability fixtures, and adds a regression test ensuring failed signing does not mutate records.

Reviewed changes

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

Show a summary per file
File Description
p2p/enr/idscheme.go Adds the identity scheme registry, implements the v4 identity scheme (signing, verification, NodeAddr), and integrates with existing ENR types.
p2p/enr/idscheme_test.go Adds a regression test ensuring SignV4 errors leave the original Record unmodified.
p2p/enr/entries.go Replaces IP4/IP6 and DiscPort with unified IP, TCP, and UDP entry types and defines the IDv4 identity-scheme constant.
p2p/enr/enr.go Refactors Record to delegate signature verification and node address derivation to identity schemes, introduces SetSig/AppendElements/idScheme, and updates sequence/invalidations.
p2p/enr/enr_test.go Updates tests to use the new IP/UDP entries and SignV4, refreshes expected node addresses and Python interop fixtures, and validates record size and random-entries encoding under the new scheme.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread p2p/enr/enr.go
Comment on lines +103 to +104
// encoded. If the record is signed, Set increments the sequence number and invalidates
// the sequence number.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The comment for Set states that, "If the record is signed, Set increments the sequence number and invalidates the sequence number", but the actual behavior in invalidate is to increment seq only when r.signature is nil (i.e. when the record is not signed) and to clear the signature/raw fields. This is confusing for users of Record and makes it unclear whether seq is meant to advance on updates to already-signed records or only while building an unsigned record. Please either adjust the invalidate logic so that seq is incremented when the record previously had a signature, or update the comment to accurately describe the current semantics (and clarify that Set invalidates the signature/encoded form, not the sequence number).

Suggested change
// encoded. If the record is signed, Set increments the sequence number and invalidates
// the sequence number.
// encoded. Calling Set invalidates any existing signature and encoded form of the record;
// the record must be re-signed before it can be encoded again.

Copilot uses AI. Check for mistakes.
Comment thread p2p/enr/enr.go
// than the size limit or if the signature is invalid according to the passed scheme.
func (r *Record) SetSig(idscheme string, sig []byte) error {
// Check that "id" is set and matches the given scheme. This panics because
// inconsitencies here are always implementation bugs in the signing function calling
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

There is a typo in this comment: "inconsitencies" should be spelled "inconsistencies". Since this comment documents a panic condition for SetSig, it would be good to fix the spelling to keep the public API docs polished.

Suggested change
// inconsitencies here are always implementation bugs in the signing function calling
// inconsistencies here are always implementation bugs in the signing function calling

Copilot uses AI. Check for mistakes.
Comment thread p2p/enr/enr_test.go
// TestGetSetDiscPort tests encoding/decoding and setting/getting of the DiscPort key.
func TestGetSetDiscPort(t *testing.T) {
port := DiscPort(30309)
// TestGetSetUDP tests encoding/decoding and setting/getting of the DiscPort key.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

This test comment still refers to the "DiscPort" key, but the code and types now use UDP as the ENR key for the discovery port. To avoid confusion for future readers, consider updating the comment to say that TestGetSetUDP tests encoding/decoding and setting/getting of the UDP key (or discovery UDP port key).

Suggested change
// TestGetSetUDP tests encoding/decoding and setting/getting of the DiscPort key.
// TestGetSetUDP tests encoding/decoding and setting/getting of the UDP key.

Copilot uses AI. Check for mistakes.
@gzliudan gzliudan changed the title p2p/enr: ENR updates for discovery v4 compatibility #16679 feat(p2p): ENR updates for discovery v4 compatibility #16679 Feb 5, 2026
@AnilChinchawale AnilChinchawale merged commit a46e6a9 into XinFinOrg:dev-upgrade Feb 6, 2026
13 checks passed
@gzliudan gzliudan deleted the enr-v4compat branch February 6, 2026 08:23
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.

5 participants