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 GetBlockBodiesPacket) []rlp.RawValue
- func ServiceGetBlockHeadersQuery(chain *core.BlockChain, query *GetBlockHeadersPacket, peer *Peer) []rlp.RawValue
- func ServiceGetNodeDataQuery(chain *core.BlockChain, query GetNodeDataPacket) [][]byte
- func ServiceGetReceiptsQuery(chain *core.BlockChain, query GetReceiptsPacket) []rlp.RawValue
- func StartENRUpdater(chain *core.BlockChain, ln *enode.LocalNode)
- type Backend
- type BlockBodiesPacket
- type BlockBodiesPacket66
- type BlockBodiesRLPPacket
- type BlockBodiesRLPPacket66
- type BlockBody
- type BlockHeadersPacket
- type BlockHeadersPacket66
- type BlockHeadersRLPPacket
- type BlockHeadersRLPPacket66
- type Decoder
- type GetBlockBodiesPacket
- type GetBlockBodiesPacket66
- type GetBlockHeadersPacket
- type GetBlockHeadersPacket66
- type GetNodeDataPacket
- type GetNodeDataPacket66
- type GetPooledTransactionsPacket
- type GetPooledTransactionsPacket66
- type GetReceiptsPacket
- type GetReceiptsPacket66
- type Handler
- type HashOrNumber
- type NewBlockHashesPacket
- type NewBlockPacket
- type NewPooledTransactionHashesPacket
- type NodeDataPacket
- type NodeDataPacket66
- 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) ReplyNodeData(id uint64, data [][]byte) 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) RequestNodeData(hashes []common.Hash, 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 PooledTransactionsPacket66
- type PooledTransactionsRLPPacket
- type PooledTransactionsRLPPacket66
- type ReceiptsPacket
- type ReceiptsPacket66
- type ReceiptsRLPPacket
- type ReceiptsRLPPacket66
- type Request
- type Response
- type StatusPacket
- type TransactionsPacket
- type TxPool
Constants ¶
const ( ETH66 = 66 ETH67 = 67 )
Constants to match up protocol versions and messages
const ( StatusMsg = 0x00 NewBlockHashesMsg = 0x01 TransactionsMsg = 0x02 GetBlockHeadersMsg = 0x03 BlockHeadersMsg = 0x04 GetBlockBodiesMsg = 0x05 BlockBodiesMsg = 0x06 NewBlockMsg = 0x07 GetNodeDataMsg = 0x0d NodeDataMsg = 0x0e GetReceiptsMsg = 0x0f ReceiptsMsg = 0x10 NewPooledTransactionHashesMsg = 0x08 GetPooledTransactionsMsg = 0x09 PooledTransactionsMsg = 0x0a )
const ProtocolName = "eth"
ProtocolName is the official short name of the `eth` protocol used during devp2p capability negotiation.
Variables ¶
var ProtocolVersions = []uint{ETH67, ETH66}
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 GetBlockBodiesPacket) []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 *GetBlockHeadersPacket, peer *Peer) []rlp.RawValue
ServiceGetBlockHeadersQuery assembles the response to a header query. It is exposed to allow external packages to test protocol behavior.
func ServiceGetNodeDataQuery ¶
func ServiceGetNodeDataQuery(chain *core.BlockChain, query GetNodeDataPacket) [][]byte
ServiceGetNodeDataQuery assembles the response to a node data query. It is exposed to allow external packages to test protocol behavior.
func ServiceGetReceiptsQuery ¶
func ServiceGetReceiptsQuery(chain *core.BlockChain, query GetReceiptsPacket) []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 []*BlockBody
BlockBodiesPacket is the network packet for block content distribution.
func (*BlockBodiesPacket) Kind ¶
func (*BlockBodiesPacket) Kind() byte
func (*BlockBodiesPacket) Name ¶
func (*BlockBodiesPacket) Name() string
func (*BlockBodiesPacket) Unpack ¶
func (p *BlockBodiesPacket) Unpack() ([][]*types.Transaction, [][]*types.Header)
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 BlockBodiesPacket66 ¶
type BlockBodiesPacket66 struct { RequestId uint64 BlockBodiesPacket }
BlockBodiesPacket66 is the network packet for block content distribution over eth/66.
type BlockBodiesRLPPacket ¶
BlockBodiesRLPPacket 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 BlockBodiesRLPPacket66 ¶
type BlockBodiesRLPPacket66 struct { RequestId uint64 BlockBodiesRLPPacket }
BlockBodiesRLPPacket66 is the BlockBodiesRLPPacket over eth/66
type BlockBody ¶
type BlockBody struct { Transactions []*types.Transaction // Transactions contained within a block Uncles []*types.Header // Uncles contained within a block }
BlockBody represents the data content of a single block.
type BlockHeadersPacket ¶
BlockHeadersPacket represents a block header response.
func (*BlockHeadersPacket) Kind ¶
func (*BlockHeadersPacket) Kind() byte
func (*BlockHeadersPacket) Name ¶
func (*BlockHeadersPacket) Name() string
type BlockHeadersPacket66 ¶
type BlockHeadersPacket66 struct { RequestId uint64 BlockHeadersPacket }
BlockHeadersPacket66 represents a block header response over eth/66.
type BlockHeadersRLPPacket ¶
BlockHeadersRLPPacket represents a block header response, to use when we already have the headers rlp encoded.
type BlockHeadersRLPPacket66 ¶
type BlockHeadersRLPPacket66 struct { RequestId uint64 BlockHeadersRLPPacket }
BlockHeadersRLPPacket66 represents a block header response over eth/66.
type GetBlockBodiesPacket ¶
GetBlockBodiesPacket represents a block body query.
func (*GetBlockBodiesPacket) Kind ¶
func (*GetBlockBodiesPacket) Kind() byte
func (*GetBlockBodiesPacket) Name ¶
func (*GetBlockBodiesPacket) Name() string
type GetBlockBodiesPacket66 ¶
type GetBlockBodiesPacket66 struct { RequestId uint64 GetBlockBodiesPacket }
GetBlockBodiesPacket66 represents a block body query over eth/66.
type GetBlockHeadersPacket ¶
type GetBlockHeadersPacket 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) }
GetBlockHeadersPacket represents a block header query.
func (*GetBlockHeadersPacket) Kind ¶
func (*GetBlockHeadersPacket) Kind() byte
func (*GetBlockHeadersPacket) Name ¶
func (*GetBlockHeadersPacket) Name() string
type GetBlockHeadersPacket66 ¶
type GetBlockHeadersPacket66 struct { RequestId uint64 *GetBlockHeadersPacket }
GetBlockHeadersPacket66 represents a block header query over eth/66
type GetNodeDataPacket ¶
GetNodeDataPacket represents a trie node data query.
func (*GetNodeDataPacket) Kind ¶
func (*GetNodeDataPacket) Kind() byte
func (*GetNodeDataPacket) Name ¶
func (*GetNodeDataPacket) Name() string
type GetNodeDataPacket66 ¶
type GetNodeDataPacket66 struct { RequestId uint64 GetNodeDataPacket }
GetNodeDataPacket66 represents a trie node data query over eth/66.
type GetPooledTransactionsPacket ¶
GetPooledTransactionsPacket represents a transaction query.
func (*GetPooledTransactionsPacket) Kind ¶
func (*GetPooledTransactionsPacket) Kind() byte
func (*GetPooledTransactionsPacket) Name ¶
func (*GetPooledTransactionsPacket) Name() string
type GetPooledTransactionsPacket66 ¶
type GetPooledTransactionsPacket66 struct { RequestId uint64 GetPooledTransactionsPacket }
type GetReceiptsPacket ¶
GetReceiptsPacket represents a block receipts query.
func (*GetReceiptsPacket) Kind ¶
func (*GetReceiptsPacket) Kind() byte
func (*GetReceiptsPacket) Name ¶
func (*GetReceiptsPacket) Name() string
type GetReceiptsPacket66 ¶
type GetReceiptsPacket66 struct { RequestId uint64 GetReceiptsPacket }
GetReceiptsPacket66 represents a block receipts query over eth/66.
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.
func (*NewPooledTransactionHashesPacket) Kind ¶
func (*NewPooledTransactionHashesPacket) Kind() byte
func (*NewPooledTransactionHashesPacket) Name ¶
func (*NewPooledTransactionHashesPacket) Name() string
type NodeDataPacket ¶
type NodeDataPacket [][]byte
NodeDataPacket is the network packet for trie node data distribution.
func (*NodeDataPacket) Kind ¶
func (*NodeDataPacket) Kind() byte
func (*NodeDataPacket) Name ¶
func (*NodeDataPacket) Name() string
type NodeDataPacket66 ¶
type NodeDataPacket66 struct { RequestId uint64 NodeDataPacket }
NodeDataPacket66 is the network packet for trie node data distribution over eth/66.
type NodeInfo ¶
type NodeInfo struct { Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4) 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 eth/66 response to GetBlockBodies.
func (*Peer) ReplyBlockHeadersRLP ¶
ReplyBlockHeadersRLP is the eth/66 response to GetBlockHeaders.
func (*Peer) ReplyNodeData ¶
ReplyNodeData is the eth/66 response to GetNodeData.
func (*Peer) ReplyPooledTransactionsRLP ¶
func (p *Peer) ReplyPooledTransactionsRLP(id uint64, hashes []common.Hash, txs []rlp.RawValue) error
ReplyPooledTransactionsRLP is the eth/66 version of SendPooledTransactionsRLP.
func (*Peer) ReplyReceiptsRLP ¶
ReplyReceiptsRLP is the eth/66 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) RequestNodeData ¶
RequestNodeData fetches a batch of arbitrary data from a node's known state data, corresponding to the specified hashes.
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 asyn queueing.
type PooledTransactionsPacket ¶
type PooledTransactionsPacket []*types.Transaction
PooledTransactionsPacket is the network packet for transaction distribution.
func (*PooledTransactionsPacket) Kind ¶
func (*PooledTransactionsPacket) Kind() byte
func (*PooledTransactionsPacket) Name ¶
func (*PooledTransactionsPacket) Name() string
type PooledTransactionsPacket66 ¶
type PooledTransactionsPacket66 struct { RequestId uint64 PooledTransactionsPacket }
PooledTransactionsPacket66 is the network packet for transaction distribution over eth/66.
type PooledTransactionsRLPPacket ¶
PooledTransactionsRLPPacket is the network packet for transaction distribution, used in the cases we already have them in rlp-encoded form
type PooledTransactionsRLPPacket66 ¶
type PooledTransactionsRLPPacket66 struct { RequestId uint64 PooledTransactionsRLPPacket }
PooledTransactionsRLPPacket66 is the eth/66 form of PooledTransactionsRLPPacket
type ReceiptsPacket ¶
ReceiptsPacket is the network packet for block receipts distribution.
func (*ReceiptsPacket) Kind ¶
func (*ReceiptsPacket) Kind() byte
func (*ReceiptsPacket) Name ¶
func (*ReceiptsPacket) Name() string
type ReceiptsPacket66 ¶
type ReceiptsPacket66 struct { RequestId uint64 ReceiptsPacket }
ReceiptsPacket66 is the network packet for block receipts distribution over eth/66.
type ReceiptsRLPPacket ¶
ReceiptsRLPPacket is used for receipts, when we already have it encoded
type ReceiptsRLPPacket66 ¶
type ReceiptsRLPPacket66 struct { RequestId uint64 ReceiptsRLPPacket }
ReceiptsRLPPacket66 is the eth-66 version of ReceiptsRLPPacket
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 for eth/64 and later.
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