discv5¶
Classes¶
| Name | |
|---|---|
| class | discv5::IBootnodeSource Abstract interface for providers of bootstrap seed records. |
| class | discv5::StaticEnrBootnodeSource Bootstrap source backed by a fixed list of "enr:…" URI strings. |
| class | discv5::StaticEnodeBootnodeSource Bootstrap source backed by a fixed list of "enode://…" URI strings. |
| class | discv5::ChainBootnodeRegistry Per-chain bootstrap seed registry. |
| class | discv5::discv5_client Discovery v5 protocol client. |
| struct | discv5::IPv4Wire Wire layout of a 4-byte IPv4 address as stored in an ENR "ip" field. |
| struct | discv5::IPv6Wire Wire layout of a 16-byte IPv6 address as stored in an ENR "ip6" field. |
| struct | discv5::Keccak256Wire Wire layout of a Keccak-256 hash. |
| struct | discv5::CompressedPubKeyWire Wire layout of a compressed secp256k1 public key. |
| struct | discv5::EnrSigWire Wire layout of an ENR compact secp256k1 signature (no recovery id). |
| struct | discv5::UncompressedPubKeyWire Wire layout of an uncompressed secp256k1 public key (with 0x04 prefix). |
| struct | discv5::MaskingIvWire Masking IV that precedes the static packet header. |
| struct | discv5::GcmNonceWire AES-GCM nonce embedded in the discv5 static header. |
| struct | discv5::StaticHeaderWire discv5 static packet header, as defined by the EIP-8020 spec. |
| struct | discv5::WhoareyouAuthDataWire WHOAREYOU auth-data layout: id-nonce + highest ENR sequence. |
| struct | discv5::CrawlerStats Snapshot of crawler activity counters. |
| class | discv5::discv5_crawler Discv5 peer crawler: seed → FINDNODE loop → ValidatedPeer emission. |
| class | discv5::EnrParser Parses and validates Ethereum Node Records (EIP-778). |
| struct | discv5::EnrRecord Parsed Ethereum Node Record as defined by EIP-778. |
| struct | discv5::Discv5Peer A peer discovered by the discv5 crawler. |
| struct | discv5::discv5Config Configuration for the discv5 client and crawler. |
| struct | discv5::ForkId Ethereum EIP-2124 fork identifier used for chain-correctness filtering. |
| struct | discv5::ValidatedPeer Minimal peer descriptor produced by both discv4 and discv5 crawlers. |
Types¶
| Name | |
|---|---|
| enum class uint64_t | ChainId { kEthereumMainnet = 1, kEthereumSepolia = 11155111, kEthereumHolesky = 17000, kPolygonMainnet = 137, kPolygonAmoy = 80002, kBscMainnet = 56, kBscTestnet = 97, kBaseMainnet = 8453, kBaseSepolia = 84532} EVM chain identifiers supported by ChainBootnodeRegistry. |
| enum class | discv5Error { kEnrMissingPrefix, kEnrBase64DecodeFailed, kEnrRlpDecodeFailed, kEnrTooShort, kEnrTooLarge, kEnrSignatureInvalid, kEnrSignatureWrongSize, kEnrMissingSecp256k1Key, kEnrInvalidSecp256k1Key, kEnrMissingAddress, kEnrInvalidIp, kEnrInvalidIp6, kEnrInvalidUdpPort, kEnrInvalidEthEntry, kEnrIdentityUnknown, kEnodeUriMalformed, kEnodeHexPubkeyInvalid, kContextCreationFailed, kCrawlerAlreadyRunning, kCrawlerNotRunning, kNetworkSendFailed, kNetworkReceiveFailed} Enumeration of all error conditions that can be returned by the discv5 module. |
| using asio::ip::udp | udp |
| template <typename T > using outcome::result< T, discv5Error, outcome::policy::all_narrow > |
Result Result type for discv5 operations that return a value. |
| using outcome::result< void, discv5Error, outcome::policy::all_narrow > | VoidResult Result type for discv5 operations that return nothing on success. |
| using std::function< void(const ValidatedPeer &)> | PeerDiscoveredCallback Invoked when a new valid peer has been discovered and passed all configured filters (chain filter, address validation, dedup). |
| using std::function< void(const std::string &)> | ErrorCallback Invoked when a non-fatal error occurs inside the crawler (e.g. a malformed ENR from a remote node). |
| using std::shared_ptr< spdlog::logger > | Logger |
| using std::array< uint8_t, 64 > | NodeId Node identifier — 64-byte uncompressed secp256k1 public key (without the 0x04 prefix). |
Functions¶
| Name | |
|---|---|
| const char * | to_string(discv5Error error) Convert a discv5Error code to a human-readable C string. |
| std::shared_ptr< spdlog::logger > | createLogger(const std::string & tag, const std::string & basepath ="") Create a logger instance. |
Attributes¶
| Name | |
|---|---|
| const std::array< uint8_t, 256 > | kBase64UrlTable Static decode table for the base64url alphabet (RFC-4648 §5). Index = ASCII code, value = 6-bit group (or kBase64Invalid). Built from the named constants in discv5_constants.hpp so that no bare literals appear in the initialiser. |
| uint16_t | kDefaultUdpPort Default UDP port for discv5 (IANA-assigned). |
| uint16_t | kDefaultTcpPort Default TCP/RLPx port advertised to discovered peers. |
| size_t | kNodeIdBytes Bytes in an uncompressed secp256k1 public key WITHOUT the 0x04 prefix. This is the 64-byte "node id" used by discv4 and passed to DialHistory. |
| size_t | kCompressedKeyBytes Bytes in a compressed secp256k1 public key (03/02 prefix + 32 bytes). |
| size_t | kPrivateKeyBytes Bytes in a secp256k1 private key. |
| size_t | kUncompressedPrefixLen Bytes in the 0x04 uncompressed-point prefix. |
| uint8_t | kUncompressedPubKeyPrefix |
| size_t | kUncompressedPubKeyDataOffset |
| size_t | kKeccak256Bytes Keccak-256 (legacy) digest size in bytes. |
| size_t | kIPv4Bytes IPv4 address wire size in bytes. |
| size_t | kIPv6Bytes IPv6 address wire size in bytes. |
| size_t | kIPv4OctetMsb Byte offset of the most-significant octet in a 4-byte IPv4 field. |
| size_t | kIPv4Octet1 Byte offset of the second octet. |
| size_t | kIPv4Octet2 Byte offset of the third octet. |
| size_t | kIPv4OctetLsb Byte offset of the least-significant octet. |
| uint32_t | kIPv4MsbShift Left-shift amount to place the MSB octet in a uint32 (big-endian). |
| uint32_t | kIPv4Octet1Shift Left-shift amount for the second octet. |
| uint32_t | kIPv4Octet2Shift Left-shift amount for the third octet. |
| uint32_t | kIPv4LsbShift Left-shift amount for the least-significant octet (no shift). |
| size_t | kMaxPortBytes Maximum bytes an RLP-encoded UDP/TCP port occupies (big-endian uint16). |
| size_t | kForkHashBytes Byte count of the fork-hash field inside an ENR "eth" entry. |
| size_t | kProtocolIdBytes Byte length of the "discv5" protocol-ID magic string. |
| char[] | kProtocolId The discv5 packet protocol-ID string. |
| size_t | kGcmNonceBytes Byte length of the AES-GCM nonce used for message encryption. |
| size_t | kMaskingIvBytes Byte length of the masking IV that precedes the static header. |
| size_t | kWhoareyouIdNonceBytes Byte length of the WHOAREYOU id-nonce field. |
| size_t | kMinPacketBytes Minimum valid discv5 packet size (go-ethereum minPacketSize). |
| size_t | kMaxPacketBytes Maximum valid discv5 packet size in bytes. |
| size_t | kAes128KeyBytes AES-128 session key size in bytes. |
| size_t | kGcmTagBytes AES-GCM authentication tag size in bytes. |
| size_t | kRandomMessageCiphertextBytes Random encrypted payload size used for pre-handshake message placeholders. |
| uint32_t | kFindNodeDistanceAll FINDNODE distance that requests the full routing table (log2 space upper bound + 1). |
| uint8_t | kHkdfFirstBlockCounter Single-byte HKDF expansion block counter used for the first output block. |
| size_t | kMessageTypePrefixBytes Byte size of the leading message-type prefix in decrypted discv5 payloads. |
| uint8_t | kNodesResponseCountSingle Number of ENR records returned by the local single-record NODES reply helper. |
| size_t | kEnrMaxBytes Maximum total size of a serialised ENR record (EIP-778 SizeLimit). |
| size_t | kEnrSigBytes Compact secp256k1 ECDSA signature size stored in an ENR (no recid). |
| size_t | kEnrPrefixLen Byte length of the "enr:" URI prefix. |
| char[] | kEnrPrefix The "enr:" URI prefix string. |
| uint8_t | kInitialEnrSeq Initial ENR sequence number for locally generated records. |
| char[] | kIdentitySchemeV4 ENR identity scheme string for secp256k1-v4. |
| size_t | kIdentitySchemeV4Bytes |
| char[] | kEnrKeyId Common ENR field key strings and lengths. |
| size_t | kEnrKeyIdBytes |
| char[] | kEnrKeyIp |
| size_t | kEnrKeyIpBytes |
| char[] | kEnrKeySecp256k1 |
| size_t | kEnrKeySecp256k1Bytes |
| char[] | kEnrKeyTcp |
| size_t | kEnrKeyTcpBytes |
| char[] | kEnrKeyUdp |
| size_t | kEnrKeyUdpBytes |
| uint8_t | kBase64UpperCount Number of upper-case letters (A–Z) in the base64url alphabet. |
| uint8_t | kBase64LowerCount Number of lower-case letters (a–z) in the base64url alphabet. |
| uint8_t | kBase64DigitCount Number of decimal digits (0–9) in the base64url alphabet. |
| uint8_t | kBase64LowerStart Start index of the lower-case letter block (after A–Z). |
| uint8_t | kBase64DigitStart Start index of the digit block (after A–Z and a–z). |
| uint8_t | kBase64DashIndex Table index for the '-' character in base64url. |
| uint8_t | kBase64UnderIndex Table index for the '_' character in base64url. |
| uint8_t | kBase64Invalid Sentinel value meaning "not a valid base64url character". |
| size_t | kBase64BitsPerChar Number of bits encoded by one base64 character. |
| size_t | kBase64BitsPerByte Number of bits in one output byte. |
| size_t | kDefaultMaxConcurrent Default maximum concurrent outbound FINDNODE queries. |
| uint32_t | kDefaultQueryIntervalSec Default interval between crawler sweep rounds (seconds). |
| uint32_t | kDefaultPeerExpirySec Seconds before an unseen peer is evicted from the peer table. |
| size_t | kMaxBootnodeEnrs Maximum bootstrap ENR entries accepted per chain source. |
| size_t | kUncompressedKeyBytes Total byte count of an uncompressed public key including the 0x04 prefix. |
| size_t | kStaticHeaderBytes Byte count of the static header (derived from wire struct, NOT a magic literal). |
| size_t | kStaticHeaderVersionOffset |
| size_t | kStaticHeaderFlagOffset |
| size_t | kStaticHeaderNonceOffset |
| size_t | kStaticHeaderAuthSizeOffset |
| size_t | kWhoareyouAuthDataBytes Byte count of WHOAREYOU auth data. |
| size_t | kHandshakeAuthSizeFieldBytes HANDSHAKE auth-data layout prefixes. |
| size_t | kHandshakeAuthSizeFieldCount |
| size_t | kHandshakeAuthSigSizeOffset |
| size_t | kHandshakeAuthPubkeySizeOffset |
| size_t | kHandshakeAuthFixedBytes |
| size_t | kStaticPacketBytes Total fixed bytes at the front of every discv5 packet: masking IV + static header. |
| uint8_t | kFlagMessage Flag value for an ordinary encrypted message packet. |
| uint8_t | kFlagWhoareyou Flag value for a WHOAREYOU session-challenge packet. |
| uint8_t | kFlagHandshake Flag value for a HANDSHAKE message. |
| uint8_t | kMsgPing PING message type byte. |
| uint8_t | kMsgPong PONG message type byte. |
| uint8_t | kMsgFindNode FINDNODE message type byte. |
| uint8_t | kMsgNodes NODES message type byte. |
| uint8_t | kMsgTalkReq TALKREQ message type byte. |
| uint8_t | kMsgTalkResp TALKRESP message type byte. |
| uint16_t | kProtocolVersion discv5 protocol version (current). |
Types Documentation¶
enum ChainId¶
| Enumerator | Value | Description |
|---|---|---|
| kEthereumMainnet | 1 | |
| kEthereumSepolia | 11155111 | |
| kEthereumHolesky | 17000 | |
| kPolygonMainnet | 137 | |
| kPolygonAmoy | 80002 | |
| kBscMainnet | 56 | |
| kBscTestnet | 97 | |
| kBaseMainnet | 8453 | |
| kBaseSepolia | 84532 |
EVM chain identifiers supported by ChainBootnodeRegistry.
Add new entries here when additional chains need to be supported.
enum discv5Error¶
| Enumerator | Value | Description |
|---|---|---|
| kEnrMissingPrefix | Input string does not start with "enr:". | |
| kEnrBase64DecodeFailed | Base64url decode of the ENR body failed. | |
| kEnrRlpDecodeFailed | RLP decode of the ENR record failed. | |
| kEnrTooShort | RLP list has too few items (need ≥ 2). | |
| kEnrTooLarge | Serialised ENR exceeds kEnrMaxBytes (300) bytes. | |
| kEnrSignatureInvalid | Signature verification failed. | |
| kEnrSignatureWrongSize | Signature field is not 64 bytes. | |
| kEnrMissingSecp256k1Key | Required "secp256k1" field is absent. | |
| kEnrInvalidSecp256k1Key | secp256k1 field cannot be parsed as pubkey | |
| kEnrMissingAddress | Neither "ip" nor "ip6" field is present. | |
| kEnrInvalidIp | "ip" field is not exactly 4 bytes | |
| kEnrInvalidIp6 | "ip6" field is not exactly 16 bytes | |
| kEnrInvalidUdpPort | "udp" field value is zero or out of range | |
| kEnrInvalidEthEntry | "eth" entry could not be decoded as [hash, next] | |
| kEnrIdentityUnknown | "id" field does not name a supported scheme | |
| kEnodeUriMalformed | enode:// URI could not be parsed | |
| kEnodeHexPubkeyInvalid | Hex-encoded pubkey in enode URI has wrong length/chars. | |
| kContextCreationFailed | Failed to create secp256k1 context. | |
| kCrawlerAlreadyRunning | start() called while crawler is active | |
| kCrawlerNotRunning | stop() called on an idle crawler | |
| kNetworkSendFailed | UDP send operation failed. | |
| kNetworkReceiveFailed | UDP receive operation failed. |
Enumeration of all error conditions that can be returned by the discv5 module.
Follows the same idiom as discv4::discv4Error: a plain enum class used as the error type in outcome::result
using udp¶
using Result¶
template <typename T >
using discv5::Result = outcome::result<T, discv5Error, outcome::policy::all_narrow>;
Result type for discv5 operations that return a value.
Template Parameters:
- T Success value type.
using VoidResult¶
Result type for discv5 operations that return nothing on success.
using PeerDiscoveredCallback¶
Invoked when a new valid peer has been discovered and passed all configured filters (chain filter, address validation, dedup).
using ErrorCallback¶
Invoked when a non-fatal error occurs inside the crawler (e.g. a malformed ENR from a remote node).
using Logger¶
using NodeId¶
Node identifier — 64-byte uncompressed secp256k1 public key (without the 0x04 prefix).
Functions Documentation¶
function to_string¶
Convert a discv5Error code to a human-readable C string.
Parameters:
- error The error code to describe.
Return: A static null-terminated string. Never returns nullptr.
function createLogger¶
std::shared_ptr< spdlog::logger > createLogger(
const std::string & tag,
const std::string & basepath =""
)
Create a logger instance.
Parameters:
- tag Tagging name for identifying logger.
- basepath Optional base path for log output (platform dependent).
Return: Logger object.
Attributes Documentation¶
variable kBase64UrlTable¶
static const std::array< uint8_t, 256 > kBase64UrlTable = []()
{
std::array<uint8_t, 256> t{};
t.fill(kBase64Invalid);
for (uint8_t i = 0U; i < kBase64UpperCount; ++i)
{
t[static_cast<uint8_t>('A') + i] = i;
}
for (uint8_t i = 0U; i < kBase64LowerCount; ++i)
{
t[static_cast<uint8_t>('a') + i] = static_cast<uint8_t>(kBase64LowerStart + i);
}
for (uint8_t i = 0U; i < kBase64DigitCount; ++i)
{
t[static_cast<uint8_t>('0') + i] = static_cast<uint8_t>(kBase64DigitStart + i);
}
t[static_cast<uint8_t>('-')] = kBase64DashIndex;
t[static_cast<uint8_t>('_')] = kBase64UnderIndex;
return t;
}();
Static decode table for the base64url alphabet (RFC-4648 §5). Index = ASCII code, value = 6-bit group (or kBase64Invalid). Built from the named constants in discv5_constants.hpp so that no bare literals appear in the initialiser.
variable kDefaultUdpPort¶
Default UDP port for discv5 (IANA-assigned).
variable kDefaultTcpPort¶
Default TCP/RLPx port advertised to discovered peers.
variable kNodeIdBytes¶
Bytes in an uncompressed secp256k1 public key WITHOUT the 0x04 prefix. This is the 64-byte "node id" used by discv4 and passed to DialHistory.
variable kCompressedKeyBytes¶
Bytes in a compressed secp256k1 public key (03/02 prefix + 32 bytes).
variable kPrivateKeyBytes¶
Bytes in a secp256k1 private key.
variable kUncompressedPrefixLen¶
Bytes in the 0x04 uncompressed-point prefix.
variable kUncompressedPubKeyPrefix¶
variable kUncompressedPubKeyDataOffset¶
variable kKeccak256Bytes¶
Keccak-256 (legacy) digest size in bytes.
variable kIPv4Bytes¶
IPv4 address wire size in bytes.
variable kIPv6Bytes¶
IPv6 address wire size in bytes.
variable kIPv4OctetMsb¶
Byte offset of the most-significant octet in a 4-byte IPv4 field.
variable kIPv4Octet1¶
Byte offset of the second octet.
variable kIPv4Octet2¶
Byte offset of the third octet.
variable kIPv4OctetLsb¶
Byte offset of the least-significant octet.
variable kIPv4MsbShift¶
Left-shift amount to place the MSB octet in a uint32 (big-endian).
variable kIPv4Octet1Shift¶
Left-shift amount for the second octet.
variable kIPv4Octet2Shift¶
Left-shift amount for the third octet.
variable kIPv4LsbShift¶
Left-shift amount for the least-significant octet (no shift).
variable kMaxPortBytes¶
Maximum bytes an RLP-encoded UDP/TCP port occupies (big-endian uint16).
variable kForkHashBytes¶
Byte count of the fork-hash field inside an ENR "eth" entry.
variable kProtocolIdBytes¶
Byte length of the "discv5" protocol-ID magic string.
variable kProtocolId¶
The discv5 packet protocol-ID string.
variable kGcmNonceBytes¶
Byte length of the AES-GCM nonce used for message encryption.
variable kMaskingIvBytes¶
Byte length of the masking IV that precedes the static header.
variable kWhoareyouIdNonceBytes¶
Byte length of the WHOAREYOU id-nonce field.
variable kMinPacketBytes¶
Minimum valid discv5 packet size (go-ethereum minPacketSize).
variable kMaxPacketBytes¶
Maximum valid discv5 packet size in bytes.
variable kAes128KeyBytes¶
AES-128 session key size in bytes.
variable kGcmTagBytes¶
AES-GCM authentication tag size in bytes.
variable kRandomMessageCiphertextBytes¶
Random encrypted payload size used for pre-handshake message placeholders.
variable kFindNodeDistanceAll¶
FINDNODE distance that requests the full routing table (log2 space upper bound + 1).
variable kHkdfFirstBlockCounter¶
Single-byte HKDF expansion block counter used for the first output block.
variable kMessageTypePrefixBytes¶
Byte size of the leading message-type prefix in decrypted discv5 payloads.
variable kNodesResponseCountSingle¶
Number of ENR records returned by the local single-record NODES reply helper.
variable kEnrMaxBytes¶
Maximum total size of a serialised ENR record (EIP-778 SizeLimit).
variable kEnrSigBytes¶
Compact secp256k1 ECDSA signature size stored in an ENR (no recid).
variable kEnrPrefixLen¶
Byte length of the "enr:" URI prefix.
variable kEnrPrefix¶
The "enr:" URI prefix string.
variable kInitialEnrSeq¶
Initial ENR sequence number for locally generated records.
variable kIdentitySchemeV4¶
ENR identity scheme string for secp256k1-v4.
variable kIdentitySchemeV4Bytes¶
variable kEnrKeyId¶
Common ENR field key strings and lengths.
variable kEnrKeyIdBytes¶
variable kEnrKeyIp¶
variable kEnrKeyIpBytes¶
variable kEnrKeySecp256k1¶
variable kEnrKeySecp256k1Bytes¶
variable kEnrKeyTcp¶
variable kEnrKeyTcpBytes¶
variable kEnrKeyUdp¶
variable kEnrKeyUdpBytes¶
variable kBase64UpperCount¶
Number of upper-case letters (A–Z) in the base64url alphabet.
variable kBase64LowerCount¶
Number of lower-case letters (a–z) in the base64url alphabet.
variable kBase64DigitCount¶
Number of decimal digits (0–9) in the base64url alphabet.
variable kBase64LowerStart¶
Start index of the lower-case letter block (after A–Z).
variable kBase64DigitStart¶
Start index of the digit block (after A–Z and a–z).
variable kBase64DashIndex¶
Table index for the '-' character in base64url.
variable kBase64UnderIndex¶
Table index for the '_' character in base64url.
variable kBase64Invalid¶
Sentinel value meaning "not a valid base64url character".
variable kBase64BitsPerChar¶
Number of bits encoded by one base64 character.
variable kBase64BitsPerByte¶
Number of bits in one output byte.
variable kDefaultMaxConcurrent¶
Default maximum concurrent outbound FINDNODE queries.
variable kDefaultQueryIntervalSec¶
Default interval between crawler sweep rounds (seconds).
variable kDefaultPeerExpirySec¶
Seconds before an unseen peer is evicted from the peer table.
variable kMaxBootnodeEnrs¶
Maximum bootstrap ENR entries accepted per chain source.
variable kUncompressedKeyBytes¶
Total byte count of an uncompressed public key including the 0x04 prefix.
variable kStaticHeaderBytes¶
Byte count of the static header (derived from wire struct, NOT a magic literal).
variable kStaticHeaderVersionOffset¶
variable kStaticHeaderFlagOffset¶
variable kStaticHeaderNonceOffset¶
variable kStaticHeaderAuthSizeOffset¶
variable kWhoareyouAuthDataBytes¶
Byte count of WHOAREYOU auth data.
variable kHandshakeAuthSizeFieldBytes¶
HANDSHAKE auth-data layout prefixes.
variable kHandshakeAuthSizeFieldCount¶
variable kHandshakeAuthSigSizeOffset¶
variable kHandshakeAuthPubkeySizeOffset¶
static size_t kHandshakeAuthPubkeySizeOffset = kHandshakeAuthSigSizeOffset + kHandshakeAuthSizeFieldBytes;
variable kHandshakeAuthFixedBytes¶
static size_t kHandshakeAuthFixedBytes =
kKeccak256Bytes + (kHandshakeAuthSizeFieldCount * kHandshakeAuthSizeFieldBytes);
variable kStaticPacketBytes¶
Total fixed bytes at the front of every discv5 packet: masking IV + static header.
variable kFlagMessage¶
Flag value for an ordinary encrypted message packet.
variable kFlagWhoareyou¶
Flag value for a WHOAREYOU session-challenge packet.
variable kFlagHandshake¶
Flag value for a HANDSHAKE message.
variable kMsgPing¶
PING message type byte.
variable kMsgPong¶
PONG message type byte.
variable kMsgFindNode¶
FINDNODE message type byte.
variable kMsgNodes¶
NODES message type byte.
variable kMsgTalkReq¶
TALKREQ message type byte.
variable kMsgTalkResp¶
TALKRESP message type byte.
variable kProtocolVersion¶
discv5 protocol version (current).
Updated on 2026-04-13 at 23:22:46 -0700