eth

package
v0.0.0-...-92d349b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// maxHeadersServe is the maximum number of block headers to serve. This number
	// is there to limit the number of disk lookups.
	MaxHeadersServe = 1024

	// maxBodiesServe is the maximum number of block bodies to serve. This number
	// is mostly there to limit the number of disk lookups. With 24KB block sizes
	// nowadays, the practical limit will always be softResponseLimit.
	MaxBodiesServe = 1024
)
View Source
const (
	ETH66 = 66
	ETH67 = 67
	ETH68 = 68
)

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 ProtocolMaxMsgSize = maxMessageSize
View Source
const ProtocolName = "eth"

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

Variables

View Source
var FromProto = map[uint]map[proto_sentry.MessageId]uint64{
	ETH66: {
		proto_sentry.MessageId_GET_BLOCK_HEADERS_66:             GetBlockHeadersMsg,
		proto_sentry.MessageId_BLOCK_HEADERS_66:                 BlockHeadersMsg,
		proto_sentry.MessageId_GET_BLOCK_BODIES_66:              GetBlockBodiesMsg,
		proto_sentry.MessageId_BLOCK_BODIES_66:                  BlockBodiesMsg,
		proto_sentry.MessageId_GET_NODE_DATA_66:                 GetNodeDataMsg,
		proto_sentry.MessageId_NODE_DATA_66:                     NodeDataMsg,
		proto_sentry.MessageId_GET_RECEIPTS_66:                  GetReceiptsMsg,
		proto_sentry.MessageId_RECEIPTS_66:                      ReceiptsMsg,
		proto_sentry.MessageId_NEW_BLOCK_HASHES_66:              NewBlockHashesMsg,
		proto_sentry.MessageId_NEW_BLOCK_66:                     NewBlockMsg,
		proto_sentry.MessageId_TRANSACTIONS_66:                  TransactionsMsg,
		proto_sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_66: NewPooledTransactionHashesMsg,
		proto_sentry.MessageId_GET_POOLED_TRANSACTIONS_66:       GetPooledTransactionsMsg,
		proto_sentry.MessageId_POOLED_TRANSACTIONS_66:           PooledTransactionsMsg,
	},
	ETH67: {
		proto_sentry.MessageId_GET_BLOCK_HEADERS_66:             GetBlockHeadersMsg,
		proto_sentry.MessageId_BLOCK_HEADERS_66:                 BlockHeadersMsg,
		proto_sentry.MessageId_GET_BLOCK_BODIES_66:              GetBlockBodiesMsg,
		proto_sentry.MessageId_BLOCK_BODIES_66:                  BlockBodiesMsg,
		proto_sentry.MessageId_GET_RECEIPTS_66:                  GetReceiptsMsg,
		proto_sentry.MessageId_RECEIPTS_66:                      ReceiptsMsg,
		proto_sentry.MessageId_NEW_BLOCK_HASHES_66:              NewBlockHashesMsg,
		proto_sentry.MessageId_NEW_BLOCK_66:                     NewBlockMsg,
		proto_sentry.MessageId_TRANSACTIONS_66:                  TransactionsMsg,
		proto_sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_66: NewPooledTransactionHashesMsg,
		proto_sentry.MessageId_GET_POOLED_TRANSACTIONS_66:       GetPooledTransactionsMsg,
		proto_sentry.MessageId_POOLED_TRANSACTIONS_66:           PooledTransactionsMsg,
	},
	ETH68: {
		proto_sentry.MessageId_GET_BLOCK_HEADERS_66:             GetBlockHeadersMsg,
		proto_sentry.MessageId_BLOCK_HEADERS_66:                 BlockHeadersMsg,
		proto_sentry.MessageId_GET_BLOCK_BODIES_66:              GetBlockBodiesMsg,
		proto_sentry.MessageId_BLOCK_BODIES_66:                  BlockBodiesMsg,
		proto_sentry.MessageId_GET_RECEIPTS_66:                  GetReceiptsMsg,
		proto_sentry.MessageId_RECEIPTS_66:                      ReceiptsMsg,
		proto_sentry.MessageId_NEW_BLOCK_HASHES_66:              NewBlockHashesMsg,
		proto_sentry.MessageId_NEW_BLOCK_66:                     NewBlockMsg,
		proto_sentry.MessageId_TRANSACTIONS_66:                  TransactionsMsg,
		proto_sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_68: NewPooledTransactionHashesMsg,
		proto_sentry.MessageId_GET_POOLED_TRANSACTIONS_66:       GetPooledTransactionsMsg,
		proto_sentry.MessageId_POOLED_TRANSACTIONS_66:           PooledTransactionsMsg,
	},
}
View Source
var ProtocolToString = map[uint]string{
	ETH66: "eth66",
	ETH67: "eth67",
	ETH68: "eth68",
}
View Source
var ToProto = map[uint]map[uint64]proto_sentry.MessageId{
	ETH66: {
		GetBlockHeadersMsg:            proto_sentry.MessageId_GET_BLOCK_HEADERS_66,
		BlockHeadersMsg:               proto_sentry.MessageId_BLOCK_HEADERS_66,
		GetBlockBodiesMsg:             proto_sentry.MessageId_GET_BLOCK_BODIES_66,
		BlockBodiesMsg:                proto_sentry.MessageId_BLOCK_BODIES_66,
		GetNodeDataMsg:                proto_sentry.MessageId_GET_NODE_DATA_66,
		NodeDataMsg:                   proto_sentry.MessageId_NODE_DATA_66,
		GetReceiptsMsg:                proto_sentry.MessageId_GET_RECEIPTS_66,
		ReceiptsMsg:                   proto_sentry.MessageId_RECEIPTS_66,
		NewBlockHashesMsg:             proto_sentry.MessageId_NEW_BLOCK_HASHES_66,
		NewBlockMsg:                   proto_sentry.MessageId_NEW_BLOCK_66,
		TransactionsMsg:               proto_sentry.MessageId_TRANSACTIONS_66,
		NewPooledTransactionHashesMsg: proto_sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_66,
		GetPooledTransactionsMsg:      proto_sentry.MessageId_GET_POOLED_TRANSACTIONS_66,
		PooledTransactionsMsg:         proto_sentry.MessageId_POOLED_TRANSACTIONS_66,
	},
	ETH67: {
		GetBlockHeadersMsg:            proto_sentry.MessageId_GET_BLOCK_HEADERS_66,
		BlockHeadersMsg:               proto_sentry.MessageId_BLOCK_HEADERS_66,
		GetBlockBodiesMsg:             proto_sentry.MessageId_GET_BLOCK_BODIES_66,
		BlockBodiesMsg:                proto_sentry.MessageId_BLOCK_BODIES_66,
		GetReceiptsMsg:                proto_sentry.MessageId_GET_RECEIPTS_66,
		ReceiptsMsg:                   proto_sentry.MessageId_RECEIPTS_66,
		NewBlockHashesMsg:             proto_sentry.MessageId_NEW_BLOCK_HASHES_66,
		NewBlockMsg:                   proto_sentry.MessageId_NEW_BLOCK_66,
		TransactionsMsg:               proto_sentry.MessageId_TRANSACTIONS_66,
		NewPooledTransactionHashesMsg: proto_sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_66,
		GetPooledTransactionsMsg:      proto_sentry.MessageId_GET_POOLED_TRANSACTIONS_66,
		PooledTransactionsMsg:         proto_sentry.MessageId_POOLED_TRANSACTIONS_66,
	},
	ETH68: {
		GetBlockHeadersMsg:            proto_sentry.MessageId_GET_BLOCK_HEADERS_66,
		BlockHeadersMsg:               proto_sentry.MessageId_BLOCK_HEADERS_66,
		GetBlockBodiesMsg:             proto_sentry.MessageId_GET_BLOCK_BODIES_66,
		BlockBodiesMsg:                proto_sentry.MessageId_BLOCK_BODIES_66,
		GetReceiptsMsg:                proto_sentry.MessageId_GET_RECEIPTS_66,
		ReceiptsMsg:                   proto_sentry.MessageId_RECEIPTS_66,
		NewBlockHashesMsg:             proto_sentry.MessageId_NEW_BLOCK_HASHES_66,
		NewBlockMsg:                   proto_sentry.MessageId_NEW_BLOCK_66,
		TransactionsMsg:               proto_sentry.MessageId_TRANSACTIONS_66,
		NewPooledTransactionHashesMsg: proto_sentry.MessageId_NEW_POOLED_TRANSACTION_HASHES_68,
		GetPooledTransactionsMsg:      proto_sentry.MessageId_GET_POOLED_TRANSACTIONS_66,
		PooledTransactionsMsg:         proto_sentry.MessageId_POOLED_TRANSACTIONS_66,
	},
}

Functions

func AnswerGetBlockBodiesQuery

func AnswerGetBlockBodiesQuery(db kv.Tx, query GetBlockBodiesPacket) []rlp.RawValue

func AnswerGetBlockHeadersQuery

func AnswerGetBlockHeadersQuery(db kv.Tx, query *GetBlockHeadersPacket, blockReader services.HeaderAndCanonicalReader) ([]*types.Header, error)

func AnswerGetReceiptsQuery

func AnswerGetReceiptsQuery(db kv.Tx, query GetReceiptsPacket) ([]rlp.RawValue, error)

func CurrentENREntryFromForks

func CurrentENREntryFromForks(heightForks, timeForks []uint64, genesisHash libcommon.Hash, headHeight, headTime uint64) *enrEntry

CurrentENREntryFromForks constructs an `eth` ENR entry based on the current state of the chain.

func LoadENRForkID

func LoadENRForkID(r *enr.Record) (*forkid.ID, error)

Types

type BlockBodiesPacket

type BlockBodiesPacket []*types.Body

BlockBodiesPacket is the network packet for block content distribution.

func (*BlockBodiesPacket) Kind

func (*BlockBodiesPacket) Kind() byte

func (*BlockBodiesPacket) Name

func (*BlockBodiesPacket) Name() string

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

type BlockRawBodiesPacket []*types.RawBody

BlockRawBodiesPacket is the network packet for block content distribution.

func (*BlockRawBodiesPacket) Unpack

func (p *BlockRawBodiesPacket) Unpack() ([][][]byte, [][]*types.Header, []types.Withdrawals)

Unpack retrieves the transactions, uncles, and withdrawals from the range packet and returns them in a split flat format that's more consistent with the internal data structures.

type BlockRawBodiesPacket66

type BlockRawBodiesPacket66 struct {
	RequestId uint64
	BlockRawBodiesPacket
}

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

type GetBlockBodiesPacket

type GetBlockBodiesPacket []libcommon.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 []libcommon.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 []libcommon.Hash

GetPooledTransactionsPacket represents a transaction query.

func (*GetPooledTransactionsPacket) Kind

func (*GetPooledTransactionsPacket) Name

type GetPooledTransactionsPacket66

type GetPooledTransactionsPacket66 struct {
	RequestId uint64
	GetPooledTransactionsPacket
}

type GetReceiptsPacket

type GetReceiptsPacket []libcommon.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 HashOrNumber

type HashOrNumber struct {
	Hash   libcommon.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   libcommon.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

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

NewBlockPacket is the network packet for the block propagation message.

func (*NewBlockPacket) DecodeRLP

func (nbp *NewBlockPacket) DecodeRLP(s *rlp.Stream) error

func (NewBlockPacket) EncodeRLP

func (nbp NewBlockPacket) EncodeRLP(w io.Writer) error

func (*NewBlockPacket) Kind

func (*NewBlockPacket) Kind() byte

func (*NewBlockPacket) Name

func (*NewBlockPacket) Name() string

func (*NewBlockPacket) SanityCheck

func (request *NewBlockPacket) SanityCheck() error

SanityCheck verifies that the values are reasonable, as a DoS protection

type NewPooledTransactionHashesPacket

type NewPooledTransactionHashesPacket []libcommon.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"`    // Ethereum network ID (1=Frontier, Rinkeby=4, Görli=5)
	Difficulty *big.Int       `json:"difficulty"` // Total difficulty of the host's blockchain
	Genesis    libcommon.Hash `json:"genesis"`    // SHA3 hash of the host's genesis block
	Config     *chain.Config  `json:"config"`     // ChainDB configuration for the fork rules
	Head       libcommon.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.

func ReadNodeInfo

func ReadNodeInfo(getter kv.Getter, config *chain.Config, genesisHash libcommon.Hash, network uint64) *NodeInfo

ReadNodeInfo retrieves some `eth` protocol metadata about the running host node.

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 PooledTransactionsPacket

type PooledTransactionsPacket []types.Transaction

PooledTransactionsPacket is the network packet for transaction distribution.

func (*PooledTransactionsPacket) DecodeRLP

func (ptp *PooledTransactionsPacket) DecodeRLP(s *rlp.Stream) error

func (PooledTransactionsPacket) EncodeRLP

func (ptp PooledTransactionsPacket) EncodeRLP(w io.Writer) error

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.

func (*PooledTransactionsPacket66) DecodeRLP

func (ptp66 *PooledTransactionsPacket66) DecodeRLP(s *rlp.Stream) error

func (PooledTransactionsPacket66) EncodeRLP

func (ptp66 PooledTransactionsPacket66) EncodeRLP(w io.Writer) error

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            libcommon.Hash
	Genesis         libcommon.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) DecodeRLP

func (tp *TransactionsPacket) DecodeRLP(s *rlp.Stream) error

func (TransactionsPacket) EncodeRLP

func (tp TransactionsPacket) EncodeRLP(w io.Writer) error

func (*TransactionsPacket) Kind

func (*TransactionsPacket) Kind() byte

func (*TransactionsPacket) Name

func (*TransactionsPacket) Name() string

Jump to

Keyboard shortcuts

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