Documentation ¶
Index ¶
- Constants
- Variables
- func Handle(backend Backend, peer *Peer) error
- func MakeProtocols(backend Backend, network uint64, dnsdisc enode.Iterator) []p2p.Protocol
- func ServiceGetBlockBodiesQuery(chain *core.BlockChain, query GetBlockBodiesRequest) []rlp.RawValue
- func ServiceGetBlockHeadersQuery(chain *core.BlockChain, query *GetBlockHeadersRequest, peer *Peer) []rlp.RawValue
- func ServiceGetReceiptsQuery(chain *core.BlockChain, query GetReceiptsRequest) []rlp.RawValue
- func StartENRUpdater(chain *core.BlockChain, ln *enode.LocalNode)
- type Backend
- type BlockBodiesPacket
- type BlockBodiesRLPPacket
- type BlockBodiesRLPResponse
- type BlockBodiesResponse
- type BlockBody
- type BlockHeadersPacket
- type BlockHeadersRLPPacket
- type BlockHeadersRLPResponse
- type BlockHeadersRequest
- type Decoder
- type GetBlockBodiesPacket
- type GetBlockBodiesRequest
- type GetBlockHeadersPacket
- type GetBlockHeadersRequest
- type GetPooledTransactionsPacket
- type GetPooledTransactionsRequest
- type GetReceiptsPacket
- type GetReceiptsRequest
- type Handler
- type HashOrNumber
- type NewBlockHashesPacket
- type NewBlockPacket
- type NewPooledTransactionHashesPacket
- type NodeInfo
- type Packet
- type Peer
- func (p *Peer) AsyncSendNewBlock(block *types.Block, td *big.Int)
- func (p *Peer) AsyncSendNewBlockHash(block *types.Block)
- func (p *Peer) AsyncSendPooledTransactionHashes(hashes []common.Hash)
- func (p *Peer) AsyncSendTransactions(hashes []common.Hash)
- func (p *Peer) Close()
- func (p *Peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis common.Hash, ...) error
- func (p *Peer) Head() (hash common.Hash, td *big.Int)
- func (p *Peer) ID() string
- func (p *Peer) KnownBlock(hash common.Hash) bool
- func (p *Peer) KnownTransaction(hash common.Hash) bool
- func (p *Peer) ReplyBlockBodiesRLP(id uint64, bodies []rlp.RawValue) error
- func (p *Peer) ReplyBlockHeadersRLP(id uint64, headers []rlp.RawValue) error
- func (p *Peer) ReplyPooledTransactionsRLP(id uint64, hashes []common.Hash, txs []rlp.RawValue) error
- func (p *Peer) ReplyReceiptsRLP(id uint64, receipts []rlp.RawValue) error
- func (p *Peer) RequestBodies(hashes []common.Hash, sink chan *Response) (*Request, error)
- func (p *Peer) RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse bool, sink chan *Response) (*Request, error)
- func (p *Peer) RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool, sink chan *Response) (*Request, error)
- func (p *Peer) RequestOneHeader(hash common.Hash, sink chan *Response) (*Request, error)
- func (p *Peer) RequestReceipts(hashes []common.Hash, sink chan *Response) (*Request, error)
- func (p *Peer) RequestTxs(hashes []common.Hash) error
- func (p *Peer) SendNewBlock(block *types.Block, td *big.Int) error
- func (p *Peer) SendNewBlockHashes(hashes []common.Hash, numbers []uint64) error
- func (p *Peer) SendTransactions(txs types.Transactions) error
- func (p *Peer) SetHead(hash common.Hash, td *big.Int)
- func (p *Peer) Version() uint
- type PooledTransactionsPacket
- type PooledTransactionsRLPPacket
- type PooledTransactionsRLPResponse
- type PooledTransactionsResponse
- type ReceiptsPacket
- type ReceiptsRLPPacket
- type ReceiptsRLPResponse
- type ReceiptsResponse
- type Request
- type Response
- type StatusPacket
- type TransactionsPacket
- type TxPool
Constants ¶
const ( StatusMsg = 0x00 NewBlockHashesMsg = 0x01 TransactionsMsg = 0x02 GetBlockHeadersMsg = 0x03 BlockHeadersMsg = 0x04 GetBlockBodiesMsg = 0x05 BlockBodiesMsg = 0x06 NewBlockMsg = 0x07 NewPooledTransactionHashesMsg = 0x08 GetPooledTransactionsMsg = 0x09 PooledTransactionsMsg = 0x0a GetReceiptsMsg = 0x0f ReceiptsMsg = 0x10 )
const (
ETH68 = 68
)
Constants to match up protocol versions and messages
const ProtocolName = "eth"
ProtocolName is the official short name of the `eth` protocol used during devp2p capability negotiation.
Variables ¶
var ProtocolVersions = []uint{ETH68}
ProtocolVersions are the supported versions of the `eth` protocol (first is primary).
Functions ¶
func Handle ¶
Handle is invoked whenever an `eth` connection is made that successfully passes the protocol handshake. This method will keep processing messages until the connection is torn down.
func MakeProtocols ¶
MakeProtocols constructs the P2P protocol definitions for `eth`.
func ServiceGetBlockBodiesQuery ¶
func ServiceGetBlockBodiesQuery(chain *core.BlockChain, query GetBlockBodiesRequest) []rlp.RawValue
ServiceGetBlockBodiesQuery assembles the response to a body query. It is exposed to allow external packages to test protocol behavior.
func ServiceGetBlockHeadersQuery ¶
func ServiceGetBlockHeadersQuery(chain *core.BlockChain, query *GetBlockHeadersRequest, peer *Peer) []rlp.RawValue
ServiceGetBlockHeadersQuery assembles the response to a header query. It is exposed to allow external packages to test protocol behavior.
func ServiceGetReceiptsQuery ¶
func ServiceGetReceiptsQuery(chain *core.BlockChain, query GetReceiptsRequest) []rlp.RawValue
ServiceGetReceiptsQuery assembles the response to a receipt query. It is exposed to allow external packages to test protocol behavior.
func StartENRUpdater ¶
func StartENRUpdater(chain *core.BlockChain, ln *enode.LocalNode)
StartENRUpdater starts the `eth` ENR updater loop, which listens for chain head events and updates the requested node record whenever a fork is passed.
Types ¶
type Backend ¶
type Backend interface { // Chain retrieves the blockchain object to serve data. Chain() *core.BlockChain // TxPool retrieves the transaction pool object to serve data. TxPool() TxPool // AcceptTxs retrieves whether transaction processing is enabled on the node // or if inbound transactions should simply be dropped. AcceptTxs() bool // RunPeer is invoked when a peer joins on the `eth` protocol. The handler // should do any peer maintenance work, handshakes and validations. If all // is passed, control should be given back to the `handler` to process the // inbound messages going forward. RunPeer(peer *Peer, handler Handler) error // PeerInfo retrieves all known `eth` information about a peer. PeerInfo(id enode.ID) interface{} // Handle is a callback to be invoked when a data packet is received from // the remote peer. Only packets not consumed by the protocol handler will // be forwarded to the backend. Handle(peer *Peer, packet Packet) error }
Backend defines the data retrieval methods to serve remote requests and the callback methods to invoke on remote deliveries.
type BlockBodiesPacket ¶
type BlockBodiesPacket struct { RequestId uint64 BlockBodiesResponse }
BlockBodiesPacket is the network packet for block content distribution with request ID wrapping.
type BlockBodiesRLPPacket ¶
type BlockBodiesRLPPacket struct { RequestId uint64 BlockBodiesRLPResponse }
BlockBodiesRLPPacket is the BlockBodiesRLPResponse with request ID wrapping.
type BlockBodiesRLPResponse ¶
BlockBodiesRLPResponse is used for replying to block body requests, in cases where we already have them RLP-encoded, and thus can avoid the decode-encode roundtrip.
type BlockBodiesResponse ¶
type BlockBodiesResponse []*BlockBody
BlockBodiesResponse is the network packet for block content distribution.
func (*BlockBodiesResponse) Kind ¶
func (*BlockBodiesResponse) Kind() byte
func (*BlockBodiesResponse) Name ¶
func (*BlockBodiesResponse) Name() string
func (*BlockBodiesResponse) Unpack ¶
func (p *BlockBodiesResponse) Unpack() ([][]*types.Transaction, [][]*types.Header, [][]*types.Withdrawal)
Unpack retrieves the transactions and uncles from the range packet and returns them in a split flat format that's more consistent with the internal data structures.
type BlockBody ¶
type BlockBody struct { Transactions []*types.Transaction // Transactions contained within a block Uncles []*types.Header // Uncles contained within a block Withdrawals []*types.Withdrawal `rlp:"optional"` // Withdrawals contained within a block }
BlockBody represents the data content of a single block.
type BlockHeadersPacket ¶
type BlockHeadersPacket struct { RequestId uint64 BlockHeadersRequest }
BlockHeadersPacket represents a block header response over with request ID wrapping.
type BlockHeadersRLPPacket ¶
type BlockHeadersRLPPacket struct { RequestId uint64 BlockHeadersRLPResponse }
BlockHeadersRLPPacket represents a block header response with request ID wrapping.
type BlockHeadersRLPResponse ¶
BlockHeadersRLPResponse represents a block header response, to use when we already have the headers rlp encoded.
type BlockHeadersRequest ¶
BlockHeadersRequest represents a block header response.
func (*BlockHeadersRequest) Kind ¶
func (*BlockHeadersRequest) Kind() byte
func (*BlockHeadersRequest) Name ¶
func (*BlockHeadersRequest) Name() string
type GetBlockBodiesPacket ¶
type GetBlockBodiesPacket struct { RequestId uint64 GetBlockBodiesRequest }
GetBlockBodiesPacket represents a block body query with request ID wrapping.
type GetBlockBodiesRequest ¶
GetBlockBodiesRequest represents a block body query.
func (*GetBlockBodiesRequest) Kind ¶
func (*GetBlockBodiesRequest) Kind() byte
func (*GetBlockBodiesRequest) Name ¶
func (*GetBlockBodiesRequest) Name() string
type GetBlockHeadersPacket ¶
type GetBlockHeadersPacket struct { RequestId uint64 *GetBlockHeadersRequest }
GetBlockHeadersPacket represents a block header query with request ID wrapping.
type GetBlockHeadersRequest ¶
type GetBlockHeadersRequest struct { Origin HashOrNumber // Block from which to retrieve headers Amount uint64 // Maximum number of headers to retrieve Skip uint64 // Blocks to skip between consecutive headers Reverse bool // Query direction (false = rising towards latest, true = falling towards genesis) }
GetBlockHeadersRequest represents a block header query.
func (*GetBlockHeadersRequest) Kind ¶
func (*GetBlockHeadersRequest) Kind() byte
func (*GetBlockHeadersRequest) Name ¶
func (*GetBlockHeadersRequest) Name() string
type GetPooledTransactionsPacket ¶
type GetPooledTransactionsPacket struct { RequestId uint64 GetPooledTransactionsRequest }
GetPooledTransactionsPacket represents a transaction query with request ID wrapping.
type GetPooledTransactionsRequest ¶
GetPooledTransactionsRequest represents a transaction query.
func (*GetPooledTransactionsRequest) Kind ¶
func (*GetPooledTransactionsRequest) Kind() byte
func (*GetPooledTransactionsRequest) Name ¶
func (*GetPooledTransactionsRequest) Name() string
type GetReceiptsPacket ¶
type GetReceiptsPacket struct { RequestId uint64 GetReceiptsRequest }
GetReceiptsPacket represents a block receipts query with request ID wrapping.
type GetReceiptsRequest ¶
GetReceiptsRequest represents a block receipts query.
func (*GetReceiptsRequest) Kind ¶
func (*GetReceiptsRequest) Kind() byte
func (*GetReceiptsRequest) Name ¶
func (*GetReceiptsRequest) Name() string
type Handler ¶
Handler is a callback to invoke from an outside runner after the boilerplate exchanges have passed.
type HashOrNumber ¶
type HashOrNumber struct { Hash common.Hash // Block hash from which to retrieve headers (excludes Number) Number uint64 // Block hash from which to retrieve headers (excludes Hash) }
HashOrNumber is a combined field for specifying an origin block.
type NewBlockHashesPacket ¶
type NewBlockHashesPacket []struct { Hash common.Hash // Hash of one particular block being announced Number uint64 // Number of one particular block being announced }
NewBlockHashesPacket is the network packet for the block announcements.
func (*NewBlockHashesPacket) Kind ¶
func (*NewBlockHashesPacket) Kind() byte
func (*NewBlockHashesPacket) Name ¶
func (*NewBlockHashesPacket) Name() string
type NewBlockPacket ¶
NewBlockPacket is the network packet for the block propagation message.
func (*NewBlockPacket) Kind ¶
func (*NewBlockPacket) Kind() byte
func (*NewBlockPacket) Name ¶
func (*NewBlockPacket) Name() string
type NewPooledTransactionHashesPacket ¶
NewPooledTransactionHashesPacket represents a transaction announcement packet on eth/68 and newer.
func (*NewPooledTransactionHashesPacket) Kind ¶
func (*NewPooledTransactionHashesPacket) Kind() byte
func (*NewPooledTransactionHashesPacket) Name ¶
func (*NewPooledTransactionHashesPacket) Name() string
type NodeInfo ¶
type NodeInfo struct { Network uint64 `json:"network"` // Ethereum network ID (1=Mainnet, Goerli=5) Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules Head common.Hash `json:"head"` // Hex hash of the host's best owned block }
NodeInfo represents a short summary of the `eth` sub-protocol metadata known about the host peer.
type Packet ¶
type Packet interface { Name() string // Name returns a string corresponding to the message type. Kind() byte // Kind returns the message type. }
Packet represents a p2p message in the `eth` protocol.
type Peer ¶
type Peer struct { *p2p.Peer // The embedded P2P package peer // contains filtered or unexported fields }
Peer is a collection of relevant information we have about a `eth` peer.
func (*Peer) AsyncSendNewBlock ¶
AsyncSendNewBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.
func (*Peer) AsyncSendNewBlockHash ¶
AsyncSendNewBlockHash queues the availability of a block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.
func (*Peer) AsyncSendPooledTransactionHashes ¶
AsyncSendPooledTransactionHashes queues a list of transactions hashes to eventually announce to a remote peer. The number of pending sends are capped (new ones will force old sends to be dropped)
func (*Peer) AsyncSendTransactions ¶
AsyncSendTransactions queues a list of transactions (by hash) to eventually propagate to a remote peer. The number of pending sends are capped (new ones will force old sends to be dropped)
func (*Peer) Close ¶
func (p *Peer) Close()
Close signals the broadcast goroutine to terminate. Only ever call this if you created the peer yourself via NewPeer. Otherwise let whoever created it clean it up!
func (*Peer) Handshake ¶
func (p *Peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis common.Hash, forkID forkid.ID, forkFilter forkid.Filter) error
Handshake executes the eth protocol handshake, negotiating version number, network IDs, difficulties, head and genesis blocks.
func (*Peer) KnownBlock ¶
KnownBlock returns whether peer is known to already have a block.
func (*Peer) KnownTransaction ¶
KnownTransaction returns whether peer is known to already have a transaction.
func (*Peer) ReplyBlockBodiesRLP ¶
ReplyBlockBodiesRLP is the response to GetBlockBodies.
func (*Peer) ReplyBlockHeadersRLP ¶
ReplyBlockHeadersRLP is the response to GetBlockHeaders.
func (*Peer) ReplyPooledTransactionsRLP ¶
func (p *Peer) ReplyPooledTransactionsRLP(id uint64, hashes []common.Hash, txs []rlp.RawValue) error
ReplyPooledTransactionsRLP is the response to RequestTxs.
func (*Peer) ReplyReceiptsRLP ¶
ReplyReceiptsRLP is the response to GetReceipts.
func (*Peer) RequestBodies ¶
RequestBodies fetches a batch of blocks' bodies corresponding to the hashes specified.
func (*Peer) RequestHeadersByHash ¶
func (p *Peer) RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse bool, sink chan *Response) (*Request, error)
RequestHeadersByHash fetches a batch of blocks' headers corresponding to the specified header query, based on the hash of an origin block.
func (*Peer) RequestHeadersByNumber ¶
func (p *Peer) RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool, sink chan *Response) (*Request, error)
RequestHeadersByNumber fetches a batch of blocks' headers corresponding to the specified header query, based on the number of an origin block.
func (*Peer) RequestOneHeader ¶
RequestOneHeader is a wrapper around the header query functions to fetch a single header. It is used solely by the fetcher.
func (*Peer) RequestReceipts ¶
RequestReceipts fetches a batch of transaction receipts from a remote node.
func (*Peer) RequestTxs ¶
RequestTxs fetches a batch of transactions from a remote node.
func (*Peer) SendNewBlock ¶
SendNewBlock propagates an entire block to a remote peer.
func (*Peer) SendNewBlockHashes ¶
SendNewBlockHashes announces the availability of a number of blocks through a hash notification.
func (*Peer) SendTransactions ¶
func (p *Peer) SendTransactions(txs types.Transactions) error
SendTransactions sends transactions to the peer and includes the hashes in its transaction hash set for future reference.
This method is a helper used by the async transaction sender. Don't call it directly as the queueing (memory) and transmission (bandwidth) costs should not be managed directly.
The reasons this is public is to allow packages using this protocol to write tests that directly send messages without having to do the async queueing.
type PooledTransactionsPacket ¶
type PooledTransactionsPacket struct { RequestId uint64 PooledTransactionsResponse }
PooledTransactionsPacket is the network packet for transaction distribution with request ID wrapping.
type PooledTransactionsRLPPacket ¶
type PooledTransactionsRLPPacket struct { RequestId uint64 PooledTransactionsRLPResponse }
PooledTransactionsRLPPacket is PooledTransactionsRLPResponse with request ID wrapping.
type PooledTransactionsRLPResponse ¶
PooledTransactionsRLPResponse is the network packet for transaction distribution, used in the cases we already have them in rlp-encoded form
type PooledTransactionsResponse ¶
type PooledTransactionsResponse []*types.Transaction
PooledTransactionsResponse is the network packet for transaction distribution.
func (*PooledTransactionsResponse) Kind ¶
func (*PooledTransactionsResponse) Kind() byte
func (*PooledTransactionsResponse) Name ¶
func (*PooledTransactionsResponse) Name() string
type ReceiptsPacket ¶
type ReceiptsPacket struct { RequestId uint64 ReceiptsResponse }
ReceiptsPacket is the network packet for block receipts distribution with request ID wrapping.
type ReceiptsRLPPacket ¶
type ReceiptsRLPPacket struct { RequestId uint64 ReceiptsRLPResponse }
ReceiptsRLPPacket is ReceiptsRLPResponse with request ID wrapping.
type ReceiptsRLPResponse ¶
ReceiptsRLPResponse is used for receipts, when we already have it encoded
type ReceiptsResponse ¶
ReceiptsResponse is the network packet for block receipts distribution.
func (*ReceiptsResponse) Kind ¶
func (*ReceiptsResponse) Kind() byte
func (*ReceiptsResponse) Name ¶
func (*ReceiptsResponse) Name() string
type Request ¶
type Request struct { Peer string // Demultiplexer if cross-peer requests are batched together Sent time.Time // Timestamp when the request was sent // contains filtered or unexported fields }
Request is a pending request to allow tracking it and delivering a response back to the requester on their chosen channel.
type Response ¶
type Response struct { Req *Request // Original request to cross-reference with Res interface{} // Remote response for the request query Meta interface{} // Metadata generated locally on the receiver thread Time time.Duration // Time it took for the request to be served Done chan error // Channel to signal message handling to the reader // contains filtered or unexported fields }
Response is a reply packet to a previously created request. It is delivered on the channel assigned by the requester subsystem and contains the original request embedded to allow uniquely matching it caller side.
type StatusPacket ¶
type StatusPacket struct { ProtocolVersion uint32 NetworkID uint64 TD *big.Int Head common.Hash Genesis common.Hash ForkID forkid.ID }
StatusPacket is the network packet for the status message.
func (*StatusPacket) Kind ¶
func (*StatusPacket) Kind() byte
func (*StatusPacket) Name ¶
func (*StatusPacket) Name() string
type TransactionsPacket ¶
type TransactionsPacket []*types.Transaction
TransactionsPacket is the network packet for broadcasting new transactions.
func (*TransactionsPacket) Kind ¶
func (*TransactionsPacket) Kind() byte
func (*TransactionsPacket) Name ¶
func (*TransactionsPacket) Name() string