Skip to content

Support dual discovery protocols (discv4 + discv5) with shared PeerTable #5884

@ElFantasma

Description

@ElFantasma

Summary

Add support for running both discv4 and discv5 discovery protocols simultaneously, sharing a single unified PeerTable.

Motivation

  • discv5 is the newer discovery protocol with better security and features
  • Transitioning requires supporting both protocols during the migration period
  • A unified PeerTable allows peers discovered via either protocol to be used interchangeably

Proposed Changes

Architecture

  • Two separate discovery servers sharing one unified PeerTable
  • Separate UDP ports: discv4 on 30303 (default), discv5 on 30304 (default)
  • Runtime control via CLI flags (not just compile-time feature flags)

New CLI Options

--discovery.discv4       Enable discv4 (default: true)
--discovery.discv5       Enable discv5 (default: false)
--discovery.discv5-port  UDP port for discv5 (default: 30304)

Unified PeerTable

  • Merge discv4/peer_table.rs and discv5/peer_table.rs into a single peer_table.rs
  • Use generic pending_ping_id: Option<Bytes> instead of protocol-specific fields
  • Keep session: Option<Session> for discv5 encryption sessions

Files to Modify

  • crates/networking/p2p/peer_table.rs - CREATE unified module
  • crates/networking/p2p/network.rs - spawn servers based on config
  • crates/networking/p2p/discv4/server.rs - use unified peer_table
  • crates/networking/p2p/discv5/server.rs - use unified peer_table
  • cmd/ethrex/cli.rs - add discovery CLI flags

Testing

  • cargo build -p ethrex-p2p - builds with discv4 only
  • cargo build -p ethrex-p2p --features experimental-discv5 - builds with both
  • cargo test -p ethrex-p2p - run existing tests
  • Manual: start node with both protocols, verify peer discovery works

Related

  • Builds on discv5 handshake handling work (current branch: discv5-server-handshake-handling)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions