Crate reth_network_peers

Source
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 over PeerId, NodeRecord, and Enr, useful in deserialization when the type of the node record is not known.
  • TrustedPeer: A NodeRecord with an optional domain name, which can be resolved to a NodeRecord. 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 NodeRecord type for peers.
trusted_peer
NodeRecord type that uses a domain instead of an IP.

Structs§

Enrsecp256k1
The ENR, allowing for arbitrary signing algorithms.
WithPeerId
Generic wrapper with peer id

Enums§

AnyNode
A peer that can come in ENR or NodeRecord form.

Statics§

HOLESKY_BOOTNODES
Ethereum Foundation Holesky Bootnodes
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
id2pksecp256k1
Converts a PeerId to a [secp256k1::PublicKey] by prepending the PeerId bytes with the SECP256K1_TAG_PUBKEY_UNCOMPRESSED tag.
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
pk2idsecp256k1
Converts a [secp256k1::PublicKey] to a PeerId by stripping the SECP256K1_TAG_PUBKEY_UNCOMPRESSED tag and storing the rest of the slice in the PeerId.
sepolia_nodes
Returns parsed sepolia nodes

Type Aliases§

PeerId
Alias for a peer identifier