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)
Summary
Add support for running both discv4 and discv5 discovery protocols simultaneously, sharing a single unified PeerTable.
Motivation
Proposed Changes
Architecture
New CLI Options
Unified PeerTable
discv4/peer_table.rsanddiscv5/peer_table.rsinto a singlepeer_table.rspending_ping_id: Option<Bytes>instead of protocol-specific fieldssession: Option<Session>for discv5 encryption sessionsFiles to Modify
crates/networking/p2p/peer_table.rs- CREATE unified modulecrates/networking/p2p/network.rs- spawn servers based on configcrates/networking/p2p/discv4/server.rs- use unified peer_tablecrates/networking/p2p/discv5/server.rs- use unified peer_tablecmd/ethrex/cli.rs- add discovery CLI flagsTesting
cargo build -p ethrex-p2p- builds with discv4 onlycargo build -p ethrex-p2p --features experimental-discv5- builds with bothcargo test -p ethrex-p2p- run existing testsRelated
discv5-server-handshake-handling)