Discv4 (Discovery v4) is Ethereum's peer-to-peer node discovery protocol, implementing the devp2p discv4 specification. Its primary purpose is to enable Ethereum nodes to find and connect to each other in a decentralized fashion — without any central directory — by maintaining a distributed hash table (DHT) of known peers.
In reth, the entire implementation lives under crates/net/discv4/.
Discv4 (Discovery v4) is Ethereum's peer-to-peer node discovery protocol, implementing the devp2p discv4 specification. Its primary purpose is to enable Ethereum nodes to find and connect to each other in a decentralized fashion — without any central directory — by maintaining a distributed hash table (DHT) of known peers.
In reth, the entire implementation lives under crates/net/discv4/.
Discv4 uses a Kademlia-like routing table (KBucketsTable) to store and manage discovered peers and topics. Each node is identified by a 64-byte secp256k1 public key (the PeerId), and nodes are organized in k-buckets based on XOR distance from the local node. 2 3
Discv4 operates entirely over UDP (default port 30303). It does NOT use TCP for discovery — TCP is only referenced in node records for the subsequent RLPx (DevP2P) transport connection. 4
Every UDP datagram is structured as header || payload, where the header contains a keccak256 hash, a recoverable ECDSA signature, and a 1-byte message type. This allows the sender's identity (PeerId) to be recovered from every packet without a prior handshake. 5
The protocol defines six message types: 6
| ID | Message | Purpose |
|---|---|---|
| 1 | Ping |
Liveness check / endpoint proof initiation |
| 2 | Pong |
Reply to Ping, completing endpoint verification |
| 3 | FindNode |
Request the closest nodes to a target ID |
| 4 | Neighbours |
Response with up to 16 closest nodes |
| 5 | EnrRequest |
Request the node's EIP-868 ENR record |
| 6 | EnrResponse |
Reply with the ENR record |