eth

package
v0.0.0-...-5d8902e Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	ETH68 = 68
)

ETH68 Constants to match up protocol versions and messages

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{ETH68}

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

Functions

func HeadersMatch

func HeadersMatch(expected []*types.Header, headers []*types.Header) bool

HeadersMatch headersMatch returns whether the received headers match the given request

func MakeJWTSecret

func MakeJWTSecret() (string, [32]byte, error)

func OracleCheck

func OracleCheck(packet interface{}, state *OracleState, s *Suite) (interface{}, error)

OracleCheck 检查并修正生成的数据包,然后更新Oracle状态

func RunGeth

func RunGeth(dir string, jwtPath string) (*node.Node, error)

runGeth creates and starts a geth node

Types

type Addresses

type Addresses []common.Address

func (Addresses) Len

func (a Addresses) Len() int

func (Addresses) Less

func (a Addresses) Less(i, j int) bool

func (Addresses) Swap

func (a Addresses) Swap(i, j int)

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

type BlockBodiesRLPResponse []rlp.RawValue

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

type BlockHeadersRLPResponse []rlp.RawValue

BlockHeadersRLPResponse represents a block header response, to use when we already have the headers rlp encoded.

type BlockHeadersRequest

type BlockHeadersRequest []*types.Header

BlockHeadersRequest represents a block header response.

func (*BlockHeadersRequest) Kind

func (*BlockHeadersRequest) Kind() byte

func (*BlockHeadersRequest) Name

func (*BlockHeadersRequest) Name() string

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

func NewChain

func NewChain(dir string) (*Chain, error)

func (*Chain) ForkID

func (c *Chain) ForkID() forkid.ID

ForkID gets the fork id of the chain.

func (*Chain) GetBlock

func (c *Chain) GetBlock(number int) *types.Block

func (*Chain) GetHeaders

func (c *Chain) GetHeaders(req *GetBlockHeadersPacket) ([]*types.Header, error)

GetHeaders returns the headers base on an ethGetPacketHeadersPacket.

func (*Chain) GetSender

func (c *Chain) GetSender(idx int) (common.Address, uint64)

GetSender returns the address associated with account at the index in the pre-funded accounts list.

func (*Chain) Head

func (c *Chain) Head() *types.Block

func (*Chain) Len

func (c *Chain) Len() int

Len returns the length of the chain.

func (*Chain) SignTx

func (c *Chain) SignTx(from common.Address, tx *types.Transaction) (*types.Transaction, error)

SignTx signs a transaction for the specified from account, so long as that account was in the hivechain accounts dump.

func (*Chain) TD

func (c *Chain) TD() *big.Int

TD calculates the total difficulty of the chain at the chain head.

type Conn

type Conn struct {
	*rlpx.Conn
	// contains filtered or unexported fields
}

func (*Conn) Read

func (c *Conn) Read() (uint64, []byte, error)

func (*Conn) ReadEth

func (c *Conn) ReadEth() (any, error)

ReadEth reads an Eth sub-protocol wire message.

func (*Conn) ReadMsg

func (c *Conn) ReadMsg(proto Proto, code uint64, msg any) error

ReadMsg attempts to read a devp2p message with a specific code.

func (*Conn) Write

func (c *Conn) Write(proto Proto, code uint64, msg any) error

type EngineClient

type EngineClient struct {
	// contains filtered or unexported fields
}

EngineClient is a wrapper around engine-related data.

func NewEngineClient

func NewEngineClient(dir, url, jwt string) (*EngineClient, error)

NewEngineClient creates a new engine client.

type GetBlockBodiesPacket

type GetBlockBodiesPacket struct {
	RequestId uint64
	GetBlockBodiesRequest
}

GetBlockBodiesPacket represents a block body query with request ID wrapping.

type GetBlockBodiesRequest

type GetBlockBodiesRequest []common.Hash

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

type GetPooledTransactionsPacket

type GetPooledTransactionsPacket struct {
	RequestId uint64
	GetPooledTransactionsRequest
}

GetPooledTransactionsPacket represents a transaction query with request ID wrapping.

type GetPooledTransactionsRequest

type GetPooledTransactionsRequest []common.Hash

GetPooledTransactionsRequest represents a transaction query.

func (*GetPooledTransactionsRequest) Kind

func (*GetPooledTransactionsRequest) Name

type GetReceiptsPacket

type GetReceiptsPacket struct {
	RequestId uint64
	GetReceiptsRequest
}

GetReceiptsPacket represents a block receipts query with request ID wrapping.

type GetReceiptsRequest

type GetReceiptsRequest []common.Hash

GetReceiptsRequest represents a block receipts query.

func (*GetReceiptsRequest) Kind

func (*GetReceiptsRequest) Kind() byte

func (*GetReceiptsRequest) Name

func (*GetReceiptsRequest) Name() string

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 struct {
	Types  []byte
	Sizes  []uint32
	Hashes []common.Hash
}

NewPooledTransactionHashesPacket represents a transaction announcement packet on eth/68 and newer.

func (*NewPooledTransactionHashesPacket) Kind

func (*NewPooledTransactionHashesPacket) Name

type NewPooledTransactionHashesPacket68

type NewPooledTransactionHashesPacket68 struct {
	Types  []byte
	Sizes  []uint32
	Hashes []common.Hash
}

NewPooledTransactionHashesPacket68 represents a transaction announcement packet on eth/68 and newer.

type OracleState

type OracleState struct {
	LatestBlockNumber       uint64
	TotalDifficulty         *big.Int
	AccountBalances         map[common.Address]string
	AccountNonces           map[common.Address]uint64
	BlockHashes             map[uint64]common.Hash
	NetworkID               uint64
	ProtocolVersion         uint32
	GenesisHash             common.Hash
	PacketHistory           []interface{}
	GasLimit                uint64
	GenesisConfig           *params.ChainConfig
	GenesisBlock            *types.Block
	GenesisAlloc            types.GenesisAlloc
	CurrentHeader           *types.Header
	Senders                 map[common.Address]uint64
	PendingTransactions     []*types.Transaction
	PendingTransactionMap   map[common.Hash]*types.Transaction
	PendingTransactionTypes map[common.Hash]byte
	PendingTransactionSizes map[common.Hash]uint32
	LastPendingUpdateTime   time.Time
}

OracleState 用于维护Oracle的状态

func InitOracleState

func InitOracleState(client *Suite) *OracleState

InitOracleState 初始化Oracle状态

func NewOracleState

func NewOracleState() *OracleState

NewOracleState 创建一个新的OracleState

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 PacketSpecification

type PacketSpecification struct {
	BlockNumbers []int
	BlockHashes  []common.Hash
}

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

type PooledTransactionsRLPResponse []rlp.RawValue

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

type Proto

type Proto int
const (
	BaseProto Proto = iota
	EthProto
	SnapProto
)

type Receipt

type Receipt struct {
	// Consensus fields: These fields are defined by the Yellow Paper
	Type              uint8        `json:"type,omitempty"`
	PostState         []byte       `json:"root"`
	Status            uint64       `json:"status"`
	CumulativeGasUsed uint64       `json:"cumulativeGasUsed" gencodec:"required"`
	Bloom             types.Bloom  `json:"logsBloom"         gencodec:"required"`
	Logs              []*types.Log `json:"logs"              gencodec:"required"`

	// Implementation fields: These fields are added by geth when processing a transaction.
	TxHash            common.Hash    `json:"transactionHash" gencodec:"required"`
	ContractAddress   common.Address `json:"contractAddress"`
	GasUsed           uint64         `json:"gasUsed" gencodec:"required"`
	EffectiveGasPrice *big.Int       `json:"effectiveGasPrice"` // required, but tag omitted for backwards compatibility
	BlobGasUsed       uint64         `json:"blobGasUsed,omitempty"`
	BlobGasPrice      *big.Int       `json:"blobGasPrice,omitempty"`

	// Inclusion information: These fields provide information about the inclusion of the
	// transaction corresponding to this receipt.
	BlockHash        common.Hash `json:"blockHash,omitempty"`
	BlockNumber      *big.Int    `json:"blockNumber,omitempty"`
	TransactionIndex uint        `json:"transactionIndex"`
}

Receipt represents the results of a transaction.

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

type ReceiptsRLPResponse []rlp.RawValue

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

type ReceiptsResponse

type ReceiptsResponse [][]*types.Receipt

ReceiptsResponse is the network packet for block receipts distribution.

func (*ReceiptsResponse) Kind

func (*ReceiptsResponse) Kind() byte

func (*ReceiptsResponse) Name

func (*ReceiptsResponse) Name() string

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 Suite

type Suite struct {
	DestList *enode.Node
	// contains filtered or unexported fields
}

func NewSuite

func NewSuite(dest *enode.Node, chainDir string, pri *ecdsa.PrivateKey, engineURL, jwt string) (*Suite, error)

func (*Suite) GenPacket

func (s *Suite) GenPacket(f *filler.Filler, packetType int) (Packet, error)

func (*Suite) GetHeaders

func (s *Suite) GetHeaders(req *GetBlockHeadersPacket) ([]*types.Header, error)

func (*Suite) InitializeAndConnect

func (s *Suite) InitializeAndConnect() error

InitializeAndConnect 封装了初始化、连接和对等过程

func (*Suite) ReadMsg

func (s *Suite) ReadMsg(proto Proto, code uint64, msg interface{}) error

func (*Suite) SendForkchoiceUpdated

func (s *Suite) SendForkchoiceUpdated() error

func (*Suite) SendMsg

func (s *Suite) SendMsg(proto Proto, code uint64, msg interface{}) error

func (*Suite) SendTxs

func (s *Suite) SendTxs(txs []*types.Transaction) error

SendTxs sends the given transactions to the node and expects the node to accept and propagate them.

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

Jump to

Keyboard shortcuts

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