Crate kona_peers

Source
Expand description

§kona-peers

CI Kona Peers License Codecov

Networking Utilities ported from reth.

Much of this module is ported from https://github.com/paradigmxyz/reth/blob/0e087ae1c35502f0b8d128c64e4c57269af20c0e/crates/net/peers/src/lib.rs.

This module manages and converts Ethereum network entities such as node records, peer IDs, and Ethereum Node Records (ENRs)

§Node Record Overview

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 (discv5::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 discv5::Enr), we use the AnyNode type, which is an enum over the three types. AnyNode is used in reth’s admin_addTrustedPeer RPC method.

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.
  • discv5::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 discv5::Enr, useful in deserialization when the type of the node record is not known.

Structs§

BootNodes
Bootnodes for OP Stack chains.
BootStore
On-disk storage for Enrs.
NodeRecord
Represents an ENR in discovery.
OpStackEnr
The unique L2 network identifier
PeerMonitoring
Specifies how to monitor peer scores and ban poorly performing peers.

Enums§

AnyNode
A peer that can come in Enr or NodeRecord form.
BootNode
A boot node can be added either as a string in either ‘enode’ URL scheme or serialized from Enr type.
DialOptsError
An error that can occur when converting an AnyNode to DialOpts.
EnrValidation
Validates the Enr for the OP Stack.
NodeRecordParseError
Possible error types when parsing a NodeRecord
OpStackEnrError
The error type that can be returned when trying to convert an Enr to an OpStackEnr.
PeerIdConversionError
An error that can occur when converting a PeerId to a libp2p::PeerId.
PeerScoreLevel
The peer scoring level is used to determine how peers are scored based on their behavior.

Statics§

OP_RAW_BOOTNODES
OP stack mainnet boot nodes.
OP_RAW_TESTNET_BOOTNODES
OP stack testnet boot nodes.

Functions§

enr_to_multiaddr
Converts an Enr into a Multiaddr.
local_id_to_p2p_id
Converts an uncoded PeerId to a libp2p::PeerId. These two types represent the same underlying concept (secp256k1 public key) but using different encodings (the local PeerId is the uncompressed representation of the public key, while the “p2plib” libp2p::PeerId is a more complex representation, involving protobuf encoding and bitcoin encoding, defined here: https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md).
peer_id_to_secp256k1_pubkey
Converts an uncompressed PeerId to a secp256k1::PublicKey by prepending the PeerId bytes with the SECP256K1_TAG_PUBKEY_UNCOMPRESSED tag.

Type Aliases§

PeerId
Alias for a peer identifier.