Documentation
¶
Index ¶
- Variables
- func Dial(n *enode.Node, opts DialOpts) (*rlpxConn, error)
- func Listen(ln *enode.LocalNode) (*net.UDPConn, error)
- func NewEthProtocol(version uint, opts EthProtocolOptions) ethp2p.Protocol
- func ParseBootnodes(bootnodes string) ([]*enode.Node, error)
- func ParseNode(source string) (*enode.Node, error)
- func ParsePrivateKey(file string, key string) (*ecdsa.PrivateKey, error)
- func ReadNodeSet(file string) ([]*enode.Node, error)
- func WriteDNSTreeNodes(file string, tree *dnsdisc.Tree) error
- func WriteNodeSet(file string, ns NodeSet, writeErrors bool) error
- func WritePeers(file string, urls []string) error
- func WriteURLs(file string, ns NodeSet) error
- type AccountRange
- type BlockBodies
- type BlockCache
- type BlockHeaders
- type BlockMetrics
- type BorStatusPacket69
- type ByteCodes
- type Conns
- func (c *Conns) Add(cn *conn)
- func (c *Conns) AddTxs(txs []*types.Transaction) []common.Hash
- func (c *Conns) Blocks() *ds.LRU[common.Hash, BlockCache]
- func (c *Conns) BroadcastBlock(block *types.Block, td *big.Int) int
- func (c *Conns) BroadcastBlockHashes(hashes []common.Hash, numbers []uint64) int
- func (c *Conns) BroadcastTx(tx *types.Transaction) int
- func (c *Conns) BroadcastTxHashes(hashes []common.Hash) int
- func (c *Conns) BroadcastTxs(txs types.Transactions) int
- func (c *Conns) GetPeerMessages(peerID string) *PeerMessages
- func (c *Conns) GetPeerName(peerID string) string
- func (c *Conns) GetPeerVersion(peerID string) uint
- func (c *Conns) HeadBlock() eth.NewBlockPacket
- func (c *Conns) KnownBlocksMax() int
- func (c *Conns) KnownTxsOpts() ds.BloomSetOptions
- func (c *Conns) Nodes() []*enode.Node
- func (c *Conns) OldestBlock() *types.Header
- func (c *Conns) PeekTxs(hashes []common.Hash) []*types.Transaction
- func (c *Conns) PeekTxsWithHashes(hashes []common.Hash) ([]common.Hash, []*types.Transaction)
- func (c *Conns) PeerConnectedAt(peerID string) time.Time
- func (c *Conns) Remove(cn *conn)
- func (c *Conns) ShouldBroadcastBlockHashes() bool
- func (c *Conns) ShouldBroadcastBlocks() bool
- func (c *Conns) ShouldBroadcastTx() bool
- func (c *Conns) ShouldBroadcastTxHashes() bool
- func (c *Conns) UpdateHeadBlock(packet eth.NewBlockPacket) bool
- type ConnsOptions
- type DialOpts
- type Direction
- type Disconnect
- type Disconnects
- type Error
- type EthProtocolOptions
- type GetAccountRange
- type GetBlockBodies
- type GetBlockHeaders
- type GetByteCodes
- type GetPooledTransactions
- type GetStorageRanges
- type GetTrieNodes
- type GetWitnessPacket
- type GetWitnessRequest
- type Hello
- type Message
- type MessageCount
- type NewBlock
- type NewBlockHashes
- type NewPooledTransactionHashes
- type NewPooledTransactionHashes66
- type NewWitnessHashesPacket
- type NewWitnessPacket
- type NodeJSON
- type NodeSet
- type PeerMessages
- type Ping
- type Pong
- type PooledTransactions
- type Status
- type StorageRanges
- type Transactions
- type TrieNodes
- type WitnessPacketRLPPacket
- type WitnessPacketResponse
- type WitnessPageRequest
- type WitnessPageResponse
Constants ¶
This section is empty.
Variables ¶
var SensorMsgCounter = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: "sensor", Name: "messages", Help: "The number and type of messages the sensor has sent and received", }, []string{"message", "direction"})
SensorMsgCounter is a global Prometheus counter for tracking message counts. It only uses "message" and "direction" labels to maintain O(1) cardinality instead of tracking per-peer metrics which causes high cardinality issues.
Functions ¶
func Dial ¶
Dial attempts to Dial the given node and perform a handshake, returning the created Conn if successful.
func NewEthProtocol ¶
func NewEthProtocol(version uint, opts EthProtocolOptions) ethp2p.Protocol
NewEthProtocol creates the new eth protocol. This will handle writing the status exchange, message handling, and writing blocks/txs to the database.
func ParseBootnodes ¶
ParseBootnodes parses the bootnodes string and returns a node slice.
func ParsePrivateKey ¶ added in v0.1.90
func ParsePrivateKey(file string, key string) (*ecdsa.PrivateKey, error)
ParsePrivateKey loads a private key from a file path or hex string. If file is provided, it attempts to load from the file path first. If the file doesn't exist, it generates a new key and saves it to the file. If key is provided instead, it parses the hex-encoded private key string. If neither file nor key is provided, it generates and returns a new private key.
func ReadNodeSet ¶
ReadNodeSet parses a list of discovery node URLs loaded from a JSON file.
func WriteDNSTreeNodes ¶ added in v0.1.61
func WritePeers ¶
Types ¶
type AccountRange ¶
type AccountRange snap.AccountRangePacket
func (AccountRange) Code ¶
func (msg AccountRange) Code() int
func (AccountRange) ReqID ¶
func (msg AccountRange) ReqID() uint64
type BlockBodies ¶
type BlockBodies eth.BlockBodiesPacket
BlockBodies is the network packet for block content distribution.
func (BlockBodies) Code ¶
func (msg BlockBodies) Code() int
func (BlockBodies) ReqID ¶
func (msg BlockBodies) ReqID() uint64
type BlockCache ¶ added in v0.1.94
BlockCache stores the actual block data to avoid duplicate fetches and database queries.
type BlockHeaders ¶
type BlockHeaders eth.BlockHeadersPacket
func (BlockHeaders) Code ¶
func (msg BlockHeaders) Code() int
func (BlockHeaders) ReqID ¶
func (msg BlockHeaders) ReqID() uint64
type BlockMetrics ¶ added in v0.1.97
type BlockMetrics struct {
HeadBlockNumber prometheus.Gauge
HeadBlockTimestamp prometheus.Gauge
HeadBlockAge prometheus.Gauge
OldestBlockNumber prometheus.Gauge
BlockRange prometheus.Gauge
}
BlockMetrics contains Prometheus metrics for tracking head and oldest blocks.
func NewBlockMetrics ¶ added in v0.1.97
func NewBlockMetrics(block *types.Block) *BlockMetrics
NewBlockMetrics creates and registers all block-related Prometheus metrics.
type BorStatusPacket69 ¶ added in v0.1.107
type BorStatusPacket69 struct {
ProtocolVersion uint32
NetworkID uint64
TD *big.Int
Genesis common.Hash
ForkID forkid.ID
EarliestBlock uint64
LatestBlock uint64
LatestBlockHash common.Hash
}
BorStatusPacket69 is the Bor-compatible status packet for ETH69. Bor's implementation includes the TD field which upstream go-ethereum removed.
func (*BorStatusPacket69) Kind ¶ added in v0.1.107
func (*BorStatusPacket69) Kind() byte
func (*BorStatusPacket69) Name ¶ added in v0.1.107
func (*BorStatusPacket69) Name() string
type ByteCodes ¶
type ByteCodes snap.ByteCodesPacket
type Conns ¶ added in v0.1.89
type Conns struct {
// contains filtered or unexported fields
}
Conns manages a collection of active peer connections for transaction broadcasting. It also maintains a global cache of blocks written to the database.
func NewConns ¶ added in v0.1.89
func NewConns(opts ConnsOptions) *Conns
NewConns creates a new connection manager with a blocks cache.
func (*Conns) Add ¶ added in v0.1.89
func (c *Conns) Add(cn *conn)
Add adds a connection to the manager.
func (*Conns) AddTxs ¶ added in v0.1.107
func (c *Conns) AddTxs(txs []*types.Transaction) []common.Hash
AddTxs adds multiple transactions to the shared cache in a single lock operation. Returns the computed hashes for reuse by the caller.
func (*Conns) BroadcastBlock ¶ added in v0.1.107
BroadcastBlock broadcasts a full block to peers that don't already know about it and returns the number of peers the block was successfully sent to. If broadcast flags are disabled, this is a no-op.
func (*Conns) BroadcastBlockHashes ¶ added in v0.1.107
BroadcastBlockHashes enqueues block hashes to per-peer broadcast queues. Each peer has a dedicated goroutine that drains the queue and sends. Returns the number of peers the hashes were enqueued to. If broadcast flags are disabled, this is a no-op.
func (*Conns) BroadcastTx ¶ added in v0.1.89
func (c *Conns) BroadcastTx(tx *types.Transaction) int
BroadcastTx broadcasts a single transaction to all connected peers. Returns the number of peers the transaction was successfully sent to.
func (*Conns) BroadcastTxHashes ¶ added in v0.1.107
BroadcastTxHashes enqueues transaction hashes to per-peer broadcast queues. Each peer has a dedicated goroutine that drains the queue and batches sends. Returns the number of peers the hashes were enqueued to. If broadcast flags are disabled, this is a no-op.
func (*Conns) BroadcastTxs ¶ added in v0.1.89
func (c *Conns) BroadcastTxs(txs types.Transactions) int
BroadcastTxs broadcasts multiple transactions to all connected peers, filtering out transactions that each peer already knows about. Returns the number of peers the transactions were successfully sent to. If broadcast flags are disabled, this is a no-op.
func (*Conns) GetPeerMessages ¶ added in v0.1.104
func (c *Conns) GetPeerMessages(peerID string) *PeerMessages
GetPeerMessages returns a snapshot of message counts for a specific peer. Returns nil if the peer is not found.
func (*Conns) GetPeerName ¶ added in v0.1.104
GetPeerName returns the fullname (client identifier) for a specific peer. Returns empty string if the peer is not found.
func (*Conns) GetPeerVersion ¶ added in v0.1.107
GetPeerVersion returns the negotiated eth protocol version for a specific peer. Returns 0 if the peer is not found.
func (*Conns) HeadBlock ¶ added in v0.1.97
func (c *Conns) HeadBlock() eth.NewBlockPacket
HeadBlock returns the current head block packet.
func (*Conns) KnownBlocksMax ¶ added in v0.1.107
KnownBlocksMax returns the maximum size for per-peer known block caches.
func (*Conns) KnownTxsOpts ¶ added in v0.1.107
func (c *Conns) KnownTxsOpts() ds.BloomSetOptions
KnownTxsOpts returns the bloom filter options for per-peer known tx tracking.
func (*Conns) OldestBlock ¶ added in v0.1.97
OldestBlock returns the oldest block the sensor will fetch parents for. This is set once at initialization to the head block and acts as a floor to prevent the sensor from crawling backwards indefinitely.
func (*Conns) PeekTxs ¶ added in v0.1.107
func (c *Conns) PeekTxs(hashes []common.Hash) []*types.Transaction
PeekTxs retrieves multiple transactions from the shared cache without updating LRU ordering. Uses a single read lock for better concurrency when LRU ordering is not needed.
func (*Conns) PeekTxsWithHashes ¶ added in v0.1.107
PeekTxsWithHashes retrieves multiple transactions with their hashes from the cache. Returns parallel slices of found hashes and transactions. Uses a single read lock.
func (*Conns) PeerConnectedAt ¶ added in v0.1.97
PeerConnectedAt returns the connection time for a peer by their ID. Returns zero time if the peer is not found.
func (*Conns) Remove ¶ added in v0.1.89
func (c *Conns) Remove(cn *conn)
Remove removes a connection from the manager when a peer disconnects.
func (*Conns) ShouldBroadcastBlockHashes ¶ added in v0.1.107
ShouldBroadcastBlockHashes returns whether block hash broadcasting is enabled.
func (*Conns) ShouldBroadcastBlocks ¶ added in v0.1.107
ShouldBroadcastBlocks returns whether full block broadcasting is enabled.
func (*Conns) ShouldBroadcastTx ¶ added in v0.1.107
ShouldBroadcastTx returns whether full transaction broadcasting is enabled.
func (*Conns) ShouldBroadcastTxHashes ¶ added in v0.1.107
ShouldBroadcastTxHashes returns whether transaction hash broadcasting is enabled.
func (*Conns) UpdateHeadBlock ¶ added in v0.1.97
func (c *Conns) UpdateHeadBlock(packet eth.NewBlockPacket) bool
UpdateHeadBlock updates the head block if the provided block is newer. Returns true if the head block was updated, false otherwise.
type ConnsOptions ¶ added in v0.1.94
type ConnsOptions struct {
BlocksCache ds.LRUOptions
TxsCache ds.LRUOptions
KnownTxsBloom ds.BloomSetOptions
KnownBlocksMax int
Head eth.NewBlockPacket
ShouldBroadcastTx bool
ShouldBroadcastTxHashes bool
ShouldBroadcastBlocks bool
ShouldBroadcastBlockHashes bool
}
ConnsOptions contains configuration options for creating a new Conns manager.
type DialOpts ¶ added in v0.1.90
func NewDialOpts ¶ added in v0.1.90
func NewDialOpts() DialOpts
type Direction ¶ added in v0.1.91
type Direction string
Direction represents the direction of a message (sent or received).
type Disconnect ¶
type Disconnect struct {
Reason p2p.DiscReason
}
Disconnect is the RLP structure for a disconnect message.
func (Disconnect) Code ¶
func (msg Disconnect) Code() int
func (Disconnect) ReqID ¶
func (msg Disconnect) ReqID() uint64
type Disconnects ¶
type Disconnects []p2p.DiscReason
Disconnects is the RLP structure for disconnect messages.
func (Disconnects) Code ¶
func (msg Disconnects) Code() int
func (Disconnects) ReqID ¶
func (msg Disconnects) ReqID() uint64
type EthProtocolOptions ¶
type EthProtocolOptions struct {
Context context.Context
Database database.Database
GenesisHash common.Hash
RPC string
SensorID string
NetworkID uint64
Conns *Conns
ForkID forkid.ID
// Cache configurations
RequestsCache ds.LRUOptions
ParentsCache ds.LRUOptions
// Broadcast flags control what gets rebroadcasted to other peers
ShouldBroadcastTx bool
ShouldBroadcastTxHashes bool
ShouldBroadcastBlocks bool
ShouldBroadcastBlockHashes bool
}
EthProtocolOptions is the options used when creating a new eth protocol.
type GetAccountRange ¶
type GetAccountRange snap.GetAccountRangePacket
GetAccountRange represents an account range query.
func (GetAccountRange) Code ¶
func (msg GetAccountRange) Code() int
func (GetAccountRange) ReqID ¶
func (msg GetAccountRange) ReqID() uint64
type GetBlockBodies ¶
type GetBlockBodies eth.GetBlockBodiesPacket
GetBlockBodies represents a GetBlockBodies request
func (GetBlockBodies) Code ¶
func (msg GetBlockBodies) Code() int
func (GetBlockBodies) ReqID ¶
func (msg GetBlockBodies) ReqID() uint64
type GetBlockHeaders ¶
type GetBlockHeaders eth.GetBlockHeadersPacket
GetBlockHeaders represents a block header query.
func (GetBlockHeaders) Code ¶
func (msg GetBlockHeaders) Code() int
func (GetBlockHeaders) ReqID ¶
func (msg GetBlockHeaders) ReqID() uint64
type GetByteCodes ¶
type GetByteCodes snap.GetByteCodesPacket
func (GetByteCodes) Code ¶
func (msg GetByteCodes) Code() int
func (GetByteCodes) ReqID ¶
func (msg GetByteCodes) ReqID() uint64
type GetPooledTransactions ¶
type GetPooledTransactions eth.GetPooledTransactionsPacket
func (GetPooledTransactions) Code ¶
func (msg GetPooledTransactions) Code() int
func (GetPooledTransactions) ReqID ¶
func (msg GetPooledTransactions) ReqID() uint64
type GetStorageRanges ¶
type GetStorageRanges snap.GetStorageRangesPacket
func (GetStorageRanges) Code ¶
func (msg GetStorageRanges) Code() int
func (GetStorageRanges) ReqID ¶
func (msg GetStorageRanges) ReqID() uint64
type GetTrieNodes ¶
type GetTrieNodes snap.GetTrieNodesPacket
func (GetTrieNodes) Code ¶
func (msg GetTrieNodes) Code() int
func (GetTrieNodes) ReqID ¶
func (msg GetTrieNodes) ReqID() uint64
type GetWitnessPacket ¶ added in v0.1.90
type GetWitnessPacket struct {
RequestId uint64
*GetWitnessRequest
}
GetWitnessPacket represents a witness query with request ID wrapping.
func (GetWitnessPacket) Code ¶ added in v0.1.90
func (msg GetWitnessPacket) Code() int
func (GetWitnessPacket) ReqID ¶ added in v0.1.90
func (msg GetWitnessPacket) ReqID() uint64
type GetWitnessRequest ¶ added in v0.1.90
type GetWitnessRequest struct {
WitnessPages []WitnessPageRequest // Request by list of witness pages
}
GetWitnessRequest represents a list of witnesses query by witness pages.
type Hello ¶
type Hello struct {
Version uint64
Name string
Caps []p2p.Cap
ListenPort uint64
ID []byte // secp256k1 public key
// Ignore additional fields (for forward compatibility).
Rest []rlp.RawValue `rlp:"tail"`
}
Hello is the RLP structure of the protocol handshake.
type MessageCount ¶
type MessageCount struct {
BlockHeaders int64 `json:"block_headers,omitempty"`
BlockBodies int64 `json:"block_bodies,omitempty"`
Blocks int64 `json:"blocks,omitempty"`
BlockHashes int64 `json:"block_hashes,omitempty"`
BlockHeaderRequests int64 `json:"block_header_requests,omitempty"`
BlockBodiesRequests int64 `json:"block_bodies_requests,omitempty"`
Transactions int64 `json:"transactions,omitempty"`
TransactionHashes int64 `json:"transaction_hashes,omitempty"`
TransactionRequests int64 `json:"transaction_requests,omitempty"`
Pings int64 `json:"pings,omitempty"`
Errors int64 `json:"errors,omitempty"`
Disconnects int64 `json:"disconnects,omitempty"`
NewWitness int64 `json:"new_witness,omitempty"`
NewWitnessHashes int64 `json:"new_witness_hashes,omitempty"`
GetWitnessRequest int64 `json:"get_witness_request,omitempty"`
Witness int64 `json:"witness,omitempty"`
}
MessageCount is used to help the outer goroutine to receive summary of the number and type of messages that were sent. This is used for distributed logging. It can be used to count the different types of messages received across all peer connections to provide a summary.
func (*MessageCount) Clear ¶
func (mc *MessageCount) Clear()
Clear clears all of the counts from the message counter.
func (*MessageCount) IncrementByName ¶ added in v0.1.104
func (mc *MessageCount) IncrementByName(name string, count int64)
IncrementByName increments the appropriate field based on message name.
func (*MessageCount) IsEmpty ¶
func (c *MessageCount) IsEmpty() bool
IsEmpty checks whether the sum of all the counts is empty. Make sure to call Load before this method to get an accurate count.
func (*MessageCount) Load ¶
func (mc *MessageCount) Load() MessageCount
Load takes a snapshot of all the counts in a thread-safe manner. Make sure you call this and read from the returned object.
type NewBlock ¶
type NewBlock eth.NewBlockPacket
NewBlock is the network packet for the block propagation message.
type NewBlockHashes ¶
type NewBlockHashes eth.NewBlockHashesPacket
NewBlockHashes is the network packet for the block announcements.
func (NewBlockHashes) Code ¶
func (msg NewBlockHashes) Code() int
func (NewBlockHashes) ReqID ¶
func (msg NewBlockHashes) ReqID() uint64
type NewPooledTransactionHashes ¶
NewPooledTransactionHashes is the network packet for the tx hash propagation message.
func (NewPooledTransactionHashes) Code ¶
func (msg NewPooledTransactionHashes) Code() int
func (NewPooledTransactionHashes) ReqID ¶
func (msg NewPooledTransactionHashes) ReqID() uint64
type NewPooledTransactionHashes66 ¶
NewPooledTransactionHashes66 is the network packet for the tx hash propagation message.
func (NewPooledTransactionHashes66) Code ¶
func (msg NewPooledTransactionHashes66) Code() int
func (NewPooledTransactionHashes66) ReqID ¶
func (msg NewPooledTransactionHashes66) ReqID() uint64
type NewWitnessHashesPacket ¶ added in v0.1.90
func (NewWitnessHashesPacket) Code ¶ added in v0.1.90
func (msg NewWitnessHashesPacket) Code() int
func (NewWitnessHashesPacket) ReqID ¶ added in v0.1.90
func (msg NewWitnessHashesPacket) ReqID() uint64
type NewWitnessPacket ¶ added in v0.1.90
func (NewWitnessPacket) Code ¶ added in v0.1.90
func (msg NewWitnessPacket) Code() int
func (NewWitnessPacket) ReqID ¶ added in v0.1.90
func (msg NewWitnessPacket) ReqID() uint64
type PeerMessages ¶ added in v0.1.104
type PeerMessages struct {
Received MessageCount
Sent MessageCount
PacketsReceived MessageCount
PacketsSent MessageCount
}
PeerMessages tracks message counts for a single peer connection. This is used to provide per-peer visibility via the API without creating high-cardinality Prometheus metrics.
func NewPeerMessages ¶ added in v0.1.104
func NewPeerMessages() *PeerMessages
NewPeerMessages creates a new PeerMessages instance.
func (*PeerMessages) IncrementReceived ¶ added in v0.1.104
func (pm *PeerMessages) IncrementReceived(name string, count int64)
IncrementReceived increments the received message count.
func (*PeerMessages) IncrementSent ¶ added in v0.1.104
func (pm *PeerMessages) IncrementSent(name string, count int64)
IncrementSent increments the sent message count.
func (*PeerMessages) Load ¶ added in v0.1.104
func (pm *PeerMessages) Load() PeerMessages
Load returns a snapshot of all message counts.
type PooledTransactions ¶
type PooledTransactions eth.PooledTransactionsPacket
func (PooledTransactions) Code ¶
func (msg PooledTransactions) Code() int
func (PooledTransactions) ReqID ¶
func (msg PooledTransactions) ReqID() uint64
type Status ¶
type Status eth.StatusPacket68
Status is the network packet for the status message for eth/64 and later.
type StorageRanges ¶
type StorageRanges snap.StorageRangesPacket
func (StorageRanges) Code ¶
func (msg StorageRanges) Code() int
func (StorageRanges) ReqID ¶
func (msg StorageRanges) ReqID() uint64
type Transactions ¶
type Transactions eth.TransactionsPacket
func (Transactions) Code ¶
func (msg Transactions) Code() int
func (Transactions) ReqID ¶
func (msg Transactions) ReqID() uint64
type TrieNodes ¶
type TrieNodes snap.TrieNodesPacket
type WitnessPacketRLPPacket ¶ added in v0.1.90
type WitnessPacketRLPPacket struct {
RequestId uint64
WitnessPacketResponse
}
WitnessPacketRLPPacket represents a witness response with request ID wrapping.
func (WitnessPacketRLPPacket) Code ¶ added in v0.1.90
func (msg WitnessPacketRLPPacket) Code() int
func (WitnessPacketRLPPacket) ReqID ¶ added in v0.1.90
func (msg WitnessPacketRLPPacket) ReqID() uint64
type WitnessPacketResponse ¶ added in v0.1.90
type WitnessPacketResponse []WitnessPageResponse
WitnessPacketResponse represents a witness response, to use when we already have the witness rlp encoded.