eth

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 21 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// Unsafe is:
	// - L1: absolute head of the chain
	// - L2: absolute head of the chain, not confirmed on L1
	Unsafe = "latest"
	// Safe is:
	// - L1: Justified checkpoint, beacon chain: 1 epoch of 2/3 of the validators attesting the epoch.
	// - L2: Derived chain tip from L1 data
	Safe = "safe"
	// Finalized is:
	// - L1: Finalized checkpoint, beacon chain: 2+ justified epochs with "supermajority link" (see FFG docs).
	//       More about FFG: https://ethereum.org/en/developers/docs/consensus-mechanisms/pos/gasper/
	// - L2: Derived chain tip from finalized L1 data
	Finalized = "finalized"
)

Variables

This section is empty.

Functions

func ForkchoiceUpdateErr

func ForkchoiceUpdateErr(payloadStatus PayloadStatusV1) error

func NewPayloadErr

func NewPayloadErr(payload *ExecutionPayload, payloadStatus *PayloadStatusV1) error

func PollBlockChanges

func PollBlockChanges(ctx context.Context, log log.Logger, src L1BlockRefsSource, fn HeadSignalFn,
	label BlockLabel, interval time.Duration, timeout time.Duration) ethereum.Subscription

PollBlockChanges opens a polling loop to fetch the L1 block reference with the given label, on provided interval and with request timeout. Results are returned with provided callback fn, which may block to pause/back-pressure polling.

func WatchHeadChanges

func WatchHeadChanges(ctx context.Context, src NewHeadSource, fn HeadSignalFn) (ethereum.Subscription, error)

WatchHeadChanges wraps a new-head subscription from NewHeadSource to feed the given Tracker

Types

type AccountResult

type AccountResult struct {
	AccountProof []hexutil.Bytes `json:"accountProof"`

	Address     common.Address `json:"address"`
	Balance     *hexutil.Big   `json:"balance"`
	CodeHash    common.Hash    `json:"codeHash"`
	Nonce       hexutil.Uint64 `json:"nonce"`
	StorageHash common.Hash    `json:"storageHash"`
}

func (*AccountResult) Verify

func (res *AccountResult) Verify(stateRoot common.Hash) error

Verify an account proof from the getProof RPC. See https://eips.ethereum.org/EIPS/eip-1186

type BlockID

type BlockID struct {
	Hash   common.Hash `json:"hash"`
	Number uint64      `json:"number"`
}

func (BlockID) String

func (id BlockID) String() string

func (BlockID) TerminalString

func (id BlockID) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type BlockInfo

type BlockInfo interface {
	Hash() common.Hash
	ParentHash() common.Hash
	Coinbase() common.Address
	Root() common.Hash // state-root
	NumberU64() uint64
	Time() uint64
	// MixDigest field, reused for randomness after The Merge (Bellatrix hardfork)
	MixDigest() common.Hash
	BaseFee() *big.Int
	ID() BlockID
	ReceiptHash() common.Hash
}

type BlockLabel

type BlockLabel string

type Bytes256

type Bytes256 [256]byte

func (Bytes256) MarshalText

func (b Bytes256) MarshalText() ([]byte, error)

func (Bytes256) String

func (b Bytes256) String() string

func (Bytes256) TerminalString

func (b Bytes256) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Bytes256) UnmarshalJSON

func (b *Bytes256) UnmarshalJSON(text []byte) error

func (*Bytes256) UnmarshalText

func (b *Bytes256) UnmarshalText(text []byte) error

type Bytes32

type Bytes32 [32]byte

func (Bytes32) MarshalText

func (b Bytes32) MarshalText() ([]byte, error)

func (Bytes32) String

func (b Bytes32) String() string

func (Bytes32) TerminalString

func (b Bytes32) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Bytes32) UnmarshalJSON

func (b *Bytes32) UnmarshalJSON(text []byte) error

func (*Bytes32) UnmarshalText

func (b *Bytes32) UnmarshalText(text []byte) error

type BytesMax32

type BytesMax32 []byte

func (BytesMax32) MarshalText

func (b BytesMax32) MarshalText() ([]byte, error)

func (BytesMax32) String

func (b BytesMax32) String() string

func (*BytesMax32) UnmarshalJSON

func (b *BytesMax32) UnmarshalJSON(text []byte) error

func (*BytesMax32) UnmarshalText

func (b *BytesMax32) UnmarshalText(text []byte) error

type Data

type Data = hexutil.Bytes

type ErrorCode

type ErrorCode int
const (
	UnknownPayload           ErrorCode = -32001 // Payload does not exist / is not available.
	InvalidForkchoiceState   ErrorCode = -38002 // Forkchoice state is invalid / inconsistent.
	InvalidPayloadAttributes ErrorCode = -38003 // Payload attributes are invalid / inconsistent.
)

type ExecutePayloadStatus

type ExecutePayloadStatus string
const (
	// given payload is valid
	ExecutionValid ExecutePayloadStatus = "VALID"
	// given payload is invalid
	ExecutionInvalid ExecutePayloadStatus = "INVALID"
	// sync process is in progress
	ExecutionSyncing ExecutePayloadStatus = "SYNCING"
	// returned if the payload is not fully validated, and does not extend the canonical chain,
	// but will be remembered for later (on reorgs or sync updates and such)
	ExecutionAccepted ExecutePayloadStatus = "ACCEPTED"
	// if the block-hash in the payload is not correct
	ExecutionInvalidBlockHash ExecutePayloadStatus = "INVALID_BLOCK_HASH"
	// proof-of-stake transition only, not used in rollup
	ExecutionInvalidTerminalBlock ExecutePayloadStatus = "INVALID_TERMINAL_BLOCK"
)

type ExecutionPayload

type ExecutionPayload struct {
	ParentHash    common.Hash     `json:"parentHash"`
	FeeRecipient  common.Address  `json:"feeRecipient"`
	StateRoot     Bytes32         `json:"stateRoot"`
	ReceiptsRoot  Bytes32         `json:"receiptsRoot"`
	LogsBloom     Bytes256        `json:"logsBloom"`
	PrevRandao    Bytes32         `json:"prevRandao"`
	BlockNumber   Uint64Quantity  `json:"blockNumber"`
	GasLimit      Uint64Quantity  `json:"gasLimit"`
	GasUsed       Uint64Quantity  `json:"gasUsed"`
	Timestamp     Uint64Quantity  `json:"timestamp"`
	ExtraData     BytesMax32      `json:"extraData"`
	BaseFeePerGas Uint256Quantity `json:"baseFeePerGas"`
	BlockHash     common.Hash     `json:"blockHash"`
	// Array of transaction objects, each object is a byte list (DATA) representing
	// TransactionType || TransactionPayload or LegacyTransaction as defined in EIP-2718
	Transactions []Data `json:"transactions"`
}

func BlockAsPayload

func BlockAsPayload(bl *types.Block) (*ExecutionPayload, error)

func (*ExecutionPayload) CheckBlockHash

func (payload *ExecutionPayload) CheckBlockHash() (actual common.Hash, ok bool)

CheckBlockHash recomputes the block hash and returns if the embedded block hash matches.

func (*ExecutionPayload) ID

func (payload *ExecutionPayload) ID() BlockID

func (*ExecutionPayload) MarshalSSZ

func (payload *ExecutionPayload) MarshalSSZ(w io.Writer) (n int, err error)

MarshalSSZ encodes the ExecutionPayload as SSZ type

func (*ExecutionPayload) ParentID

func (payload *ExecutionPayload) ParentID() BlockID

func (*ExecutionPayload) SizeSSZ

func (payload *ExecutionPayload) SizeSSZ() (full uint32)

func (*ExecutionPayload) UnmarshalSSZ

func (payload *ExecutionPayload) UnmarshalSSZ(scope uint32, r io.Reader) error

UnmarshalSSZ decodes the ExecutionPayload as SSZ type

type FetchedReceipts

type FetchedReceipts types.Receipts

FetchedReceipts is a simple util to implement the ReceiptsFetcher with readily available receipts.

func (FetchedReceipts) Complete

func (f FetchedReceipts) Complete() bool

func (FetchedReceipts) Fetch

func (f FetchedReceipts) Fetch(ctx context.Context) error

func (FetchedReceipts) Reset

func (f FetchedReceipts) Reset()

func (FetchedReceipts) Result

func (f FetchedReceipts) Result() (types.Receipts, error)

type ForkchoiceState

type ForkchoiceState struct {
	// block hash of the head of the canonical chain
	HeadBlockHash common.Hash `json:"headBlockHash"`
	// safe block hash in the canonical chain
	SafeBlockHash common.Hash `json:"safeBlockHash"`
	// block hash of the most recent finalized block
	FinalizedBlockHash common.Hash `json:"finalizedBlockHash"`
}

type ForkchoiceUpdatedResult

type ForkchoiceUpdatedResult struct {
	// the result of the payload execution
	PayloadStatus PayloadStatusV1 `json:"payloadStatus"`
	// the payload id if requested
	PayloadID *PayloadID `json:"payloadId"`
}

type HeadSignalFn

type HeadSignalFn func(ctx context.Context, sig L1BlockRef)

HeadSignalFn is used as callback function to accept head-signals

type InputError

type InputError struct {
	Inner error
	Code  ErrorCode
}

InputError distinguishes an user-input error from regular rpc errors, to help the (Engine) API user divert from accidental input mistakes.

func (InputError) Error

func (ie InputError) Error() string

func (InputError) Is

func (ie InputError) Is(target error) bool

Is checks if the error is the given target type. Any type of InputError counts, regardless of code.

func (InputError) Unwrap

func (ie InputError) Unwrap() error

type L1BlockRef

type L1BlockRef struct {
	Hash       common.Hash `json:"hash"`
	Number     uint64      `json:"number"`
	ParentHash common.Hash `json:"parentHash"`
	Time       uint64      `json:"timestamp"`
}

func InfoToL1BlockRef

func InfoToL1BlockRef(info BlockInfo) L1BlockRef

func (L1BlockRef) ID

func (id L1BlockRef) ID() BlockID

func (L1BlockRef) ParentID

func (id L1BlockRef) ParentID() BlockID

func (L1BlockRef) String

func (id L1BlockRef) String() string

func (L1BlockRef) TerminalString

func (id L1BlockRef) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type L1BlockRefsSource

type L1BlockRefsSource interface {
	L1BlockRefByLabel(ctx context.Context, label BlockLabel) (L1BlockRef, error)
}

type L2BlockRef

type L2BlockRef struct {
	Hash           common.Hash `json:"hash"`
	Number         uint64      `json:"number"`
	ParentHash     common.Hash `json:"parentHash"`
	Time           uint64      `json:"timestamp"`
	L1Origin       BlockID     `json:"l1origin"`
	SequenceNumber uint64      `json:"sequenceNumber"` // distance to first block of epoch
}

func (L2BlockRef) ID

func (id L2BlockRef) ID() BlockID

func (L2BlockRef) ParentID

func (id L2BlockRef) ParentID() BlockID

func (L2BlockRef) String

func (id L2BlockRef) String() string

func (L2BlockRef) TerminalString

func (id L2BlockRef) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type NewHeadSource

type NewHeadSource interface {
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
}

type PayloadAttributes

type PayloadAttributes struct {
	// value for the timestamp field of the new payload
	Timestamp Uint64Quantity `json:"timestamp"`
	// value for the random field of the new payload
	PrevRandao Bytes32 `json:"prevRandao"`
	// suggested value for the coinbase field of the new payload
	SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient"`
	// Transactions to force into the block (always at the start of the transactions list).
	Transactions []Data `json:"transactions,omitempty"`
	// NoTxPool to disable adding any transactions from the transaction-pool.
	NoTxPool bool `json:"noTxPool,omitempty"`
}

type PayloadID

type PayloadID = beacon.PayloadID

type PayloadStatusV1

type PayloadStatusV1 struct {
	// the result of the payload execution
	Status ExecutePayloadStatus `json:"status"`
	// the hash of the most recent valid block in the branch defined by payload and its ancestors (optional field)
	LatestValidHash *common.Hash `json:"latestValidHash,omitempty"`
	// additional details on the result (optional field)
	ValidationError *string `json:"validationError,omitempty"`
}

type ReceiptsFetcher

type ReceiptsFetcher interface {
	// Reset clears the previously fetched results for a fresh re-attempt.
	Reset()
	// Fetch retrieves receipts in batches, until it returns io.EOF to indicate completion.
	Fetch(ctx context.Context) error
	// Complete indicates when all data has been fetched.
	Complete() bool
	// Result returns the receipts, or an error if the Fetch-ing is not Complete,
	// or an error if the results are invalid.
	// If an error is returned, the fetcher is Reset automatically.
	Result() (types.Receipts, error)
}

ReceiptsFetcher fetches receipts of a block, and enables the caller to parallelize fetching and backoff on fetching errors as needed.

type Uint256Quantity

type Uint256Quantity = uint256.Int

type Uint64Quantity

type Uint64Quantity = hexutil.Uint64

Jump to

Keyboard shortcuts

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