Skip to content

feat/add discv5#1555

Closed
darrenkel wants to merge 21 commits intomasterfrom
darren/feat/add-discv5-2
Closed

feat/add discv5#1555
darrenkel wants to merge 21 commits intomasterfrom
darren/feat/add-discv5-2

Conversation

@darrenkel
Copy link
Copy Markdown
Contributor

@darrenkel darrenkel commented Jan 19, 2026

Summary

Motivation

VeChainThor currently uses an older discv5 implementation from an earlier go-ethereum version. The modern discv5 protocol offers:

  • Better NAT traversal
  • Improved security (encrypted handshakes)
  • ENR (Ethereum Node Records) support for richer node metadata
  • Network isolation via the eth ENR entry for filtering nodes by topic

Changes

New Packages

  • p2p/discv5/ - Modern discv5 protocol from go-ethereum with subpackages:
    • discover/ - v4 and v5 UDP discovery implementations
    • enode/ - Node representation and local node management
    • v5wire/ - Protocol wire encoding and session handling
    • nat/, netutil/, rlpx/ - Supporting network utilities
  • common/ - Common utilities (hexutil, mclock, lru, math, prque, bitutil, etc.)
  • rlp/ - RLP encoding/decoding library

Renamed Package

  • p2p/discv5/ → p2p/tempdiscv5/ - Legacy discv5 renamed to avoid conflicts

P2P Server Updates (p2psrv/server.go)

  • Runs both discv5 versions simultaneously using a shared UDP connection
  • New discv5 writes to the socket; unhandled packets forwarded to tempdiscv5
  • Node filtering via callback to accept only nodes with matching eth ENR record
  • New options: DiscV5 (enable new), TempDiscV5 (enable legacy)

Node Filtering

  • Nodes are filtered based on the eth ENR record matching the genesis-based topic
  • Ensures nodes only connect to peers on the same VeChain network

New Flags

  • --disable-temp-discv5 (hidden) - Disable legacy discv5 for testing

Architecture

                  ┌─────────────────────────┐
                  │     Shared UDP Port     │
                  └───────────┬─────────────┘
                              │
            ┌─────────────────┼─────────────────┐
            │                 │                 │
            ▼                 │                 ▼
  ┌─────────────────┐         │       ┌─────────────────┐
  │  Modern discv5  │         │       │  Temp discv5    │
  │  (v5 protocol)  │ ────────┘       │  (legacy)       │
  │                 │  unhandled      │                 │
  └─────────────────┘  packets        └─────────────────┘
            │                                   │
            └─────────────┬─────────────────────┘
                          │
                          ▼
                ┌─────────────────┐
                │ Discovered Nodes│
                │  (with filter)  │
                └─────────────────┘

Test Plan

  • Run thor node with both discovery protocols enabled (default)
  • Verify nodes are discovered via both protocols
  • Test --disable-temp-discv5 flag disables legacy discovery
  • Verify node filtering correctly rejects nodes from different networks
  • Run disco bootnode with both protocols
  • Test NAT traversal functionality

Breaking Changes

None - existing behavior preserved by default with both protocols running.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing E2E tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

@darrenkel darrenkel requested a review from a team as a code owner January 19, 2026 09:56
@darrenkel darrenkel marked this pull request as draft January 19, 2026 09:56
@darrenkel darrenkel marked this pull request as ready for review January 19, 2026 10:12
@darrenkel darrenkel marked this pull request as draft January 19, 2026 10:12
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 19, 2026

@darrenkel darrenkel force-pushed the darren/feat/add-discv5-2 branch from 37b9a5f to 7f40e7c Compare January 19, 2026 10:32
@darrenkel darrenkel marked this pull request as ready for review January 22, 2026 12:08
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale PR/ Issue has been marked as stale label Mar 28, 2026
@github-actions github-actions Bot closed this Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR/ Issue has been marked as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants