sources

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 22 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitRPC

func LimitRPC(c client.RPC, concurrentRequests int) client.RPC

LimitRPC limits concurrent RPC requests (excluding subscriptions) to a given number by wrapping the client with a semaphore.

func NewReceiptsFetcher

func NewReceiptsFetcher(block eth.BlockID, receiptHash common.Hash, txHashes []common.Hash, getBatch BatchCallContextFn, batchSize int) eth.ReceiptsFetcher

NewReceiptsFetcher creates a receipt fetcher that can iteratively fetch the receipts matching the given txs.

Types

type BatchCallContextFn

type BatchCallContextFn func(ctx context.Context, b []rpc.BatchElem) error

type EngineClient

type EngineClient struct {
	*L2Client
}

EngineClient extends L2Client with engine API bindings.

func NewEngineClient

func NewEngineClient(client client.RPC, log log.Logger, metrics caching.Metrics, config *EngineClientConfig) (*EngineClient, error)

func (*EngineClient) ForkchoiceUpdate

func (s *EngineClient) ForkchoiceUpdate(ctx context.Context, fc *eth.ForkchoiceState, attributes *eth.PayloadAttributes) (*eth.ForkchoiceUpdatedResult, error)

ForkchoiceUpdate updates the forkchoice on the execution client. If attributes is not nil, the engine client will also begin building a block based on attributes after the new head block and return the payload ID.

The RPC may return three types of errors: 1. Processing error: ForkchoiceUpdatedResult.PayloadStatusV1.ValidationError or other non-success PayloadStatusV1, 2. `error` as eth.InputError: the forkchoice state or attributes are not valid. 3. Other types of `error`: temporary RPC errors, like timeouts.

func (*EngineClient) GetPayload

func (s *EngineClient) GetPayload(ctx context.Context, payloadId eth.PayloadID) (*eth.ExecutionPayload, error)

GetPayload gets the execution payload associated with the PayloadId. There may be two types of error: 1. `error` as eth.InputError: the payload ID may be unknown 2. Other types of `error`: temporary RPC errors, like timeouts.

func (*EngineClient) NewPayload

func (s *EngineClient) NewPayload(ctx context.Context, payload *eth.ExecutionPayload) (*eth.PayloadStatusV1, error)

NewPayload executes a full block on the execution engine. This returns a PayloadStatusV1 which encodes any validation/processing error, and this type of error is kept separate from the returned `error` used for RPC errors, like timeouts.

type EngineClientConfig

type EngineClientConfig struct {
	L2ClientConfig
}

func EngineClientDefaultConfig

func EngineClientDefaultConfig(config *rollup.Config) *EngineClientConfig

type EthClient

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

EthClient retrieves ethereum data with optimized batch requests, cached results, and flag to not trust the RPC.

func NewEthClient

func NewEthClient(client client.RPC, log log.Logger, metrics caching.Metrics, config *EthClientConfig) (*EthClient, error)

NewEthClient wraps a RPC with bindings to fetch ethereum data, while logging errors, parallel-requests constraint, tracking metrics (optional), and caching.

func (*EthClient) BlockIDRange added in v0.6.0

func (s *EthClient) BlockIDRange(ctx context.Context, begin eth.BlockID, max uint64) ([]eth.BlockID, error)

BlockIDRange returns a range of block IDs from the provided begin up to max blocks after the begin. This batch-requests all blocks by number in the range at once, and then verifies the consistency

func (*EthClient) Close

func (s *EthClient) Close()

func (*EthClient) Fetch added in v0.6.0

func (*EthClient) GetProof

func (s *EthClient) GetProof(ctx context.Context, address common.Address, blockTag string) (*eth.AccountResult, error)

func (*EthClient) InfoAndTxsByHash

func (s *EthClient) InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error)

func (*EthClient) InfoAndTxsByLabel

func (s *EthClient) InfoAndTxsByLabel(ctx context.Context, label eth.BlockLabel) (eth.BlockInfo, types.Transactions, error)

func (*EthClient) InfoAndTxsByNumber

func (s *EthClient) InfoAndTxsByNumber(ctx context.Context, number uint64) (eth.BlockInfo, types.Transactions, error)

func (*EthClient) InfoByHash

func (s *EthClient) InfoByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, error)

func (*EthClient) InfoByLabel

func (s *EthClient) InfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.BlockInfo, error)

func (*EthClient) InfoByNumber

func (s *EthClient) InfoByNumber(ctx context.Context, number uint64) (eth.BlockInfo, error)

func (*EthClient) InfoByRpcNumber added in v0.6.0

func (s *EthClient) InfoByRpcNumber(ctx context.Context, num rpc.BlockNumber) (eth.BlockInfo, error)

func (*EthClient) PayloadByHash

func (s *EthClient) PayloadByHash(ctx context.Context, hash common.Hash) (*eth.ExecutionPayload, error)

func (*EthClient) PayloadByLabel

func (s *EthClient) PayloadByLabel(ctx context.Context, label eth.BlockLabel) (*eth.ExecutionPayload, error)

func (*EthClient) PayloadByNumber

func (s *EthClient) PayloadByNumber(ctx context.Context, number uint64) (*eth.ExecutionPayload, error)

func (*EthClient) SubscribeNewHead

func (s *EthClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

SubscribeNewHead subscribes to notifications about the current blockchain head on the given channel.

type EthClientConfig

type EthClientConfig struct {
	// Maximum number of requests to make per batch
	MaxRequestsPerBatch int

	// limit concurrent requests, applies to the source as a whole
	MaxConcurrentRequests int

	// Number of blocks worth of receipts to cache
	ReceiptsCacheSize int
	// Number of blocks worth of transactions to cache
	TransactionsCacheSize int
	// Number of block headers to cache
	HeadersCacheSize int
	// Number of payloads to cache
	PayloadsCacheSize int

	// If the RPC is untrusted, then we should not use cached information from responses,
	// and instead verify against the block-hash.
	// Of real L1 blocks no deposits can be missed/faked, no batches can be missed/faked,
	// only the wrong L1 blocks can be retrieved.
	TrustRPC bool

	// If the RPC must ensure that the results fit the ExecutionPayload(Header) format.
	// If this is not checked, disabled header fields like the nonce or difficulty
	// may be used to get a different block-hash.
	MustBePostMerge bool
}

func (*EthClientConfig) Check

func (c *EthClientConfig) Check() error

type HeaderInfo

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

HeaderInfo contains all the header-info required to implement the eth.BlockInfo interface, used in the rollup state-transition, with pre-computed block hash.

func (*HeaderInfo) BaseFee

func (info *HeaderInfo) BaseFee() *big.Int

func (*HeaderInfo) Coinbase

func (info *HeaderInfo) Coinbase() common.Address

func (*HeaderInfo) Hash

func (info *HeaderInfo) Hash() common.Hash

func (*HeaderInfo) ID

func (info *HeaderInfo) ID() eth.BlockID

func (*HeaderInfo) MixDigest

func (info *HeaderInfo) MixDigest() common.Hash

func (*HeaderInfo) NumberU64

func (info *HeaderInfo) NumberU64() uint64

func (*HeaderInfo) ParentHash

func (info *HeaderInfo) ParentHash() common.Hash

func (*HeaderInfo) ReceiptHash

func (info *HeaderInfo) ReceiptHash() common.Hash

func (*HeaderInfo) Root

func (info *HeaderInfo) Root() common.Hash

func (*HeaderInfo) Time

func (info *HeaderInfo) Time() uint64

type IterativeBatchCall

type IterativeBatchCall[K any, V any, O any] struct {
	// contains filtered or unexported fields
}

IterativeBatchCall is an util to create a job to fetch many RPC requests in batches, and enable the caller to parallelize easily and safely, handle and re-try errors, and pick a batch size all by simply calling Fetch again and again until it returns io.EOF.

func NewIterativeBatchCall

func NewIterativeBatchCall[K any, V any, O any](
	requestsKeys []K,
	makeRequest func(K) (V, rpc.BatchElem),
	makeResults func([]K, []V) (O, error),
	getBatch BatchCallContextFn,
	batchSize int) *IterativeBatchCall[K, V, O]

NewIterativeBatchCall constructs a batch call, fetching the values with the given keys, and transforms them into a verified final result.

func (*IterativeBatchCall[K, V, O]) Complete

func (ibc *IterativeBatchCall[K, V, O]) Complete() bool

Complete indicates if the batch call is done.

func (*IterativeBatchCall[K, V, O]) Fetch

func (ibc *IterativeBatchCall[K, V, O]) Fetch(ctx context.Context) error

Fetch fetches more of the data, and returns io.EOF when all data has been fetched. This method is safe to call concurrently: it will parallelize the fetching work. If no work is available, but the fetching is not done yet, then Fetch will block until the next thing can be fetched, or until the context expires.

func (*IterativeBatchCall[K, V, O]) Reset

func (ibc *IterativeBatchCall[K, V, O]) Reset()

Reset will clear the batch call, to start fetching all contents from scratch.

func (*IterativeBatchCall[K, V, O]) Result

func (ibc *IterativeBatchCall[K, V, O]) Result() (O, error)

Result returns the fetched values, checked and transformed to the final output type, if available. If the check fails, the IterativeBatchCall will Reset itself, to be ready for a re-attempt in fetching new data.

type L1Client

type L1Client struct {
	*EthClient
	// contains filtered or unexported fields
}

L1Client provides typed bindings to retrieve L1 data from an RPC source, with optimized batch requests, cached results, and flag to not trust the RPC (i.e. to verify all returned contents against corresponding block hashes).

func NewL1Client

func NewL1Client(client client.RPC, log log.Logger, metrics caching.Metrics, config *L1ClientConfig) (*L1Client, error)

NewL1Client wraps a RPC with bindings to fetch L1 data, while logging errors, tracking metrics (optional), and caching.

func (*L1Client) L1BlockRefByHash

func (s *L1Client) L1BlockRefByHash(ctx context.Context, hash common.Hash) (eth.L1BlockRef, error)

func (*L1Client) L1BlockRefByLabel

func (s *L1Client) L1BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L1BlockRef, error)

func (*L1Client) L1BlockRefByNumber

func (s *L1Client) L1BlockRefByNumber(ctx context.Context, num uint64) (eth.L1BlockRef, error)

type L1ClientConfig

type L1ClientConfig struct {
	EthClientConfig

	L1BlockRefsCacheSize int
}

func L1ClientDefaultConfig

func L1ClientDefaultConfig(config *rollup.Config, trustRPC bool) *L1ClientConfig

type L2Client

type L2Client struct {
	*EthClient
	// contains filtered or unexported fields
}

L2Client extends EthClient with functions to fetch and cache eth.L2BlockRef values.

func NewL2Client

func NewL2Client(client client.RPC, log log.Logger, metrics caching.Metrics, config *L2ClientConfig) (*L2Client, error)

func (*L2Client) L2BlockRefByHash

func (s *L2Client) L2BlockRefByHash(ctx context.Context, hash common.Hash) (eth.L2BlockRef, error)

L2BlockRefByHash returns the L2 block reference for the given block hash. The returned BlockRef may not be in the canonical chain.

func (*L2Client) L2BlockRefByLabel

func (s *L2Client) L2BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L2BlockRef, error)

L2BlockRefByLabel returns the L2 block reference for the given label.

func (*L2Client) L2BlockRefByNumber

func (s *L2Client) L2BlockRefByNumber(ctx context.Context, num uint64) (eth.L2BlockRef, error)

L2BlockRefByNumber returns the L2 block reference for the given block number.

type L2ClientConfig

type L2ClientConfig struct {
	EthClientConfig

	L2BlockRefsCacheSize int

	Genesis rollup.Genesis
}

func L2ClientDefaultConfig

func L2ClientDefaultConfig(config *rollup.Config, trustRPC bool) *L2ClientConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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