eth

package
v1.1.3-stable Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2021 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ETH65 = 65
	ETH66 = 66
)

Constants to match up protocol versions and messages

View Source
const (
	// Protocol messages in eth/64
	StatusMsg          = 0x00
	NewBlockHashesMsg  = 0x01
	TransactionsMsg    = 0x02
	GetBlockHeadersMsg = 0x03
	BlockHeadersMsg    = 0x04
	GetBlockBodiesMsg  = 0x05
	BlockBodiesMsg     = 0x06
	NewBlockMsg        = 0x07
	GetNodeDataMsg     = 0x0d
	NodeDataMsg        = 0x0e
	GetReceiptsMsg     = 0x0f
	ReceiptsMsg        = 0x10

	// Protocol messages overloaded in eth/65
	NewPooledTransactionHashesMsg = 0x08
	GetPooledTransactionsMsg      = 0x09
	PooledTransactionsMsg         = 0x0a
)
View Source
const ProtocolName = "eth"

ProtocolName is the official short name of the `eth` protocol used during devp2p capability negotiation.

Variables

View Source
var ProtocolVersions = []uint{ETH66, ETH65}

ProtocolVersions are the supported versions of the `eth` protocol (first is primary).

Functions

func Handle

func Handle(backend Backend, peer *Peer) error

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

func MakeProtocols(backend Backend, network uint64, dnsdisc enode.Iterator) []p2p.Protocol

MakeProtocols constructs the P2P protocol definitions for `eth`.

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

	// StateBloom retrieves the bloom filter - if any - for state trie nodes.
	StateBloom() *trie.SyncBloom

	// 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
}

BlockBodiesPacket is the network packet for block content distribution over eth/66.

type BlockBodiesRLPPacket

type BlockBodiesRLPPacket []rlp.RawValue

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

type BlockHeadersPacket []*types.Header

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
}

BlockHeadersPacket represents a block header response over eth/66.

type Decoder

type Decoder interface {
	Decode(val interface{}) error
	Time() time.Time
}

type GetBlockBodiesPacket

type GetBlockBodiesPacket []common.Hash

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
}

GetBlockBodiesPacket 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
}

GetBlockHeadersPacket represents a block header query over eth/66

type GetNodeDataPacket

type GetNodeDataPacket []common.Hash

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
}

GetNodeDataPacket represents a trie node data query over eth/66.

type GetPooledTransactionsPacket

type GetPooledTransactionsPacket []common.Hash

GetPooledTransactionsPacket represents a transaction query.

func (*GetPooledTransactionsPacket) Kind

func (*GetPooledTransactionsPacket) Name

type GetPooledTransactionsPacket66

type GetPooledTransactionsPacket66 struct {
	RequestId uint64
	GetPooledTransactionsPacket
}

type GetReceiptsPacket

type GetReceiptsPacket []common.Hash

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
}

GetReceiptsPacket represents a block receipts query over eth/66.

type Handler

type Handler func(peer *Peer) error

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.

func (*HashOrNumber) DecodeRLP

func (hn *HashOrNumber) DecodeRLP(s *rlp.Stream) error

DecodeRLP is a specialized decoder for HashOrNumber to decode the contents into either a block hash or a block number.

func (*HashOrNumber) EncodeRLP

func (hn *HashOrNumber) EncodeRLP(w io.Writer) error

EncodeRLP is a specialized encoder for HashOrNumber to encode only one of the two contained union fields.

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

func (*NewBlockHashesPacket) Unpack

func (p *NewBlockHashesPacket) Unpack() ([]common.Hash, []uint64)

Unpack retrieves the block hashes and numbers from the announcement packet and returns them in a split flat format that's more consistent with the internal data structures.

type NewBlockPacket

type NewBlockPacket struct {
	Block *types.Block
	TD    *big.Int
}

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

type NewPooledTransactionHashesPacket []common.Hash

NewPooledTransactionHashesPacket represents a transaction announcement packet.

func (*NewPooledTransactionHashesPacket) Kind

func (*NewPooledTransactionHashesPacket) Name

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
}

NodeDataPacket is the network packet for trie node data distribution over eth/66.

type NodeInfo

type NodeInfo struct {
	Network    uint64              `json:"network"`    // Detonus 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 NewPeer

func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter, txpool TxPool) *Peer

NewPeer create a wrapper for a network connection and negotiated protocol version.

func (*Peer) AsyncSendNewBlock

func (p *Peer) AsyncSendNewBlock(block *types.Block, td *big.Int)

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

func (p *Peer) AsyncSendNewBlockHash(block *types.Block)

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

func (p *Peer) AsyncSendPooledTransactionHashes(hashes []common.Hash)

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

func (p *Peer) AsyncSendTransactions(hashes []common.Hash)

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) ExpectRequestHeadersByNumber

func (p *Peer) ExpectRequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool) error

ExpectRequestHeadersByNumber is a testing method to mirror the recipient side of the RequestHeadersByNumber operation.

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) Head

func (p *Peer) Head() (hash common.Hash, td *big.Int)

Head retrieves the current head hash and total difficulty of the peer.

func (*Peer) ID

func (p *Peer) ID() string

ID retrieves the peer's unique identifier.

func (*Peer) KnownBlock

func (p *Peer) KnownBlock(hash common.Hash) bool

KnownBlock returns whether peer is known to already have a block.

func (*Peer) KnownTransaction

func (p *Peer) KnownTransaction(hash common.Hash) bool

KnownTransaction returns whether peer is known to already have a transaction.

func (*Peer) ReplyBlockBodiesRLP

func (p *Peer) ReplyBlockBodiesRLP(id uint64, bodies []rlp.RawValue) error

ReplyBlockBodiesRLP is the eth/66 version of SendBlockBodiesRLP.

func (*Peer) ReplyBlockHeaders

func (p *Peer) ReplyBlockHeaders(id uint64, headers []*types.Header) error

ReplyBlockHeaders is the eth/66 version of SendBlockHeaders.

func (*Peer) ReplyNodeData

func (p *Peer) ReplyNodeData(id uint64, data [][]byte) error

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

func (p *Peer) ReplyReceiptsRLP(id uint64, receipts []rlp.RawValue) error

ReplyReceiptsRLP is the eth/66 response to GetReceipts.

func (*Peer) RequestBodies

func (p *Peer) RequestBodies(hashes []common.Hash) error

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) 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) 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

func (p *Peer) RequestNodeData(hashes []common.Hash) error

RequestNodeData fetches a batch of arbitrary data from a node's known state data, corresponding to the specified hashes.

func (*Peer) RequestOneHeader

func (p *Peer) RequestOneHeader(hash common.Hash) error

RequestOneHeader is a wrapper around the header query functions to fetch a single header. It is used solely by the fetcher.

func (*Peer) RequestReceipts

func (p *Peer) RequestReceipts(hashes []common.Hash) error

RequestReceipts fetches a batch of transaction receipts from a remote node.

func (*Peer) RequestTxs

func (p *Peer) RequestTxs(hashes []common.Hash) error

RequestTxs fetches a batch of transactions from a remote node.

func (*Peer) SendBlockBodiesRLP

func (p *Peer) SendBlockBodiesRLP(bodies []rlp.RawValue) error

SendBlockBodiesRLP sends a batch of block contents to the remote peer from an already RLP encoded format.

func (*Peer) SendBlockHeaders

func (p *Peer) SendBlockHeaders(headers []*types.Header) error

SendBlockHeaders sends a batch of block headers to the remote peer.

func (*Peer) SendNewBlock

func (p *Peer) SendNewBlock(block *types.Block, td *big.Int) error

SendNewBlock propagates an entire block to a remote peer.

func (*Peer) SendNewBlockHashes

func (p *Peer) SendNewBlockHashes(hashes []common.Hash, numbers []uint64) error

SendNewBlockHashes announces the availability of a number of blocks through a hash notification.

func (*Peer) SendNodeData

func (p *Peer) SendNodeData(data [][]byte) error

SendNodeDataRLP sends a batch of arbitrary internal data, corresponding to the hashes requested.

func (*Peer) SendPooledTransactionsRLP

func (p *Peer) SendPooledTransactionsRLP(hashes []common.Hash, txs []rlp.RawValue) error

SendPooledTransactionsRLP sends requested transactions to the peer and adds the hashes in its transaction hash set for future reference.

Note, the method assumes the hashes are correct and correspond to the list of transactions being sent.

func (*Peer) SendReceiptsRLP

func (p *Peer) SendReceiptsRLP(receipts []rlp.RawValue) error

SendReceiptsRLP sends a batch of transaction receipts, corresponding to the ones requested from an already RLP encoded format.

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.

func (*Peer) SetHead

func (p *Peer) SetHead(hash common.Hash, td *big.Int)

SetHead updates the head hash and total difficulty of the peer.

func (*Peer) Version

func (p *Peer) Version() uint

Version retrieves the peer's negoatiated `eth` protocol version.

type PooledTransactionsPacket

type PooledTransactionsPacket []*types.Transaction

PooledTransactionsPacket is the network packet for transaction distribution.

func (*PooledTransactionsPacket) Kind

func (*PooledTransactionsPacket) Name

type PooledTransactionsPacket66

type PooledTransactionsPacket66 struct {
	RequestId uint64
	PooledTransactionsPacket
}

PooledTransactionsPacket is the network packet for transaction distribution over eth/66.

type PooledTransactionsRLPPacket

type PooledTransactionsRLPPacket []rlp.RawValue

PooledTransactionsPacket 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

type ReceiptsPacket [][]*types.Receipt

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
}

ReceiptsPacket is the network packet for block receipts distribution over eth/66.

type ReceiptsRLPPacket

type ReceiptsRLPPacket []rlp.RawValue

ReceiptsRLPPacket is used for receipts, when we already have it encoded

type ReceiptsRLPPacket66

type ReceiptsRLPPacket66 struct {
	RequestId uint64
	ReceiptsRLPPacket
}

ReceiptsPacket66 is the eth-66 version of ReceiptsRLPPacket

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

type TxPool

type TxPool interface {
	// Get retrieves the the transaction from the local txpool with the given hash.
	Get(hash common.Hash) *types.Transaction
}

TxPool defines the methods needed by the protocol handler to serve transactions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL