Expand description
Network Types and Utilities.
This crate manages and converts Ethereum network entities such as node records, peer IDs, and Ethereum Node Records (ENRs)
§An overview of Node Record types
Ethereum uses different types of “node records” to represent peers on the network.
The simplest way to identify a peer is by public key. This is the PeerId type, which usually
represents a peer’s secp256k1 public key.
A more complete representation of a peer is the NodeRecord type, which includes the peer’s
IP address, the ports where it is reachable (TCP and UDP), and the peer’s public key. This is
what is returned from discovery v4 queries.
The most comprehensive node record type is the Ethereum Node Record (Enr), which is a
signed, versioned record that includes the information from a NodeRecord along with
additional metadata. This is the data structure returned from discovery v5 queries.
When we need to deserialize an identifier that could be any of these three types (PeerId,
NodeRecord, and Enr), we use the AnyNode type, which is an enum over the three
types. AnyNode is used in reth’s admin_addTrustedPeer RPC method.
The final type is the TrustedPeer type, which is similar to a NodeRecord but may
include a domain name instead of a direct IP address. It includes a resolve method, which can
be used to resolve the domain name, producing a NodeRecord. This is useful for adding
trusted peers at startup, whose IP address may not be static each time the node starts. This is
common in orchestrated environments like Kubernetes, where there is reliable service discovery,
but services do not necessarily have static IPs.
In short, the types are as follows:
PeerId: A simple public key identifier.NodeRecord: A more complete representation of a peer, including IP address and ports.Enr: An Ethereum Node Record, which is a signed, versioned record that includes additional metadata. Useful when interacting with discovery v5, or when custom metadata is required.AnyNode: An enum overPeerId,NodeRecord, andEnr, useful in deserialization when the type of the node record is not known.TrustedPeer: ANodeRecordwith an optional domain name, which can be resolved to aNodeRecord. Useful for adding trusted peers at startup, whose IP address may not be static.
§Feature Flags
net: Support for address lookups.
Re-exports§
pub use node_record::NodeRecord;pub use node_record::NodeRecordParseError;pub use trusted_peer::TrustedPeer;
Modules§
- node_
record - Commonly used
NodeRecordtype for peers. - trusted_
peer NodeRecordtype that uses a domain instead of an IP.
Structs§
- Enr
secp256k1 - The ENR, allowing for arbitrary signing algorithms.
- With
Peer Id - Generic wrapper with peer id
Enums§
- AnyNode
- A peer that can come in ENR or
NodeRecordform.
Statics§
- HOLESKY_
BOOTNODES - Ethereum Foundation Holesky Bootnodes
- HOODI_
BOOTNODES - Ethereum Foundation Hoodi Bootnodes From: https://github.com/eth-clients/hoodi/blob/main/metadata/enodes.yaml
- MAINNET_
BOOTNODES - Ethereum Foundation Go Bootnodes
- OP_
BOOTNODES - OP stack mainnet boot nodes.
- OP_
TESTNET_ BOOTNODES - OP stack testnet boot nodes.
- SEPOLIA_
BOOTNODES - Ethereum Foundation Sepolia Bootnodes
Functions§
- base_
nodes - Returns parsed op-stack base mainnet nodes
- base_
testnet_ nodes - Returns parsed op-stack base testnet nodes
- holesky_
nodes - Returns parsed holesky nodes
- hoodi_
nodes - Returns parsed hoodi nodes
- id2pk
secp256k1 - Converts a
PeerIdto a [secp256k1::PublicKey] by prepending thePeerIdbytes with theSECP256K1_TAG_PUBKEY_UNCOMPRESSEDtag. - mainnet_
nodes - Returns parsed mainnet nodes
- op_
nodes - Returns parsed op-stack mainnet nodes
- op_
testnet_ nodes - Returns parsed op-stack testnet nodes
- parse_
nodes - Parses all the nodes
- pk2id
secp256k1 - Converts a [
secp256k1::PublicKey] to aPeerIdby stripping theSECP256K1_TAG_PUBKEY_UNCOMPRESSEDtag and storing the rest of the slice in thePeerId. - sepolia_
nodes - Returns parsed sepolia nodes
Type Aliases§
- PeerId
- Alias for a peer identifier