rpc

package
v0.0.0-...-1d04f91 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// FallbackGasTipCap is the default fallback gasTipCap used when we are
	// unable to query an L1 backend for a suggested gasTipCap.
	FallbackGasTipCap = big.NewInt(1500000000)
)

Taken from https://github.com/ethereum-optimism/optimism/blob/develop/bss-core/drivers/max_priority_fee_fallback.go

Functions

func DialClientWithBackoff

func DialClientWithBackoff(ctx context.Context, url string) (*ethclient.Client, error)

DialClientWithBackoff connects a ethereum RPC client at the given URL with a backoff strategy.

func DialEngineClient

func DialEngineClient(ctx context.Context, endpointUrl string, jwtSecret string) (*rpc.Client, error)

DialEngineClient initializes an RPC connection with authentication headers. Taken from https://github.com/prysmaticlabs/prysm/blob/v2.1.4/beacon-chain/execution/rpc_connection.go#L151

func GetProtocolStateVariables

func GetProtocolStateVariables(
	mxcL1Client *bindings.MxcL1Client,
	opts *bind.CallOpts,
) (*bindings.MxcDataStateVariables, error)

GetProtocolStateVariables gets the protocol states from MxcL1 contract.

func GetReceiptsByBlock

func GetReceiptsByBlock(ctx context.Context, cli *rpc.Client, block *types.Block) (types.Receipts, error)

GetReceiptsByBlock fetches all transaction receipts in a block.

func IsMaxPriorityFeePerGasNotFoundError

func IsMaxPriorityFeePerGasNotFoundError(err error) bool

IsMaxPriorityFeePerGasNotFoundError returns true if the provided error signals that the backend does not support the eth_maxPrirorityFeePerGas method. In this case, the caller should fallback to using the constant above.

func NeedNewProof

func NeedNewProof(
	ctx context.Context,
	cli *Client,
	id *big.Int,
	proverAddress common.Address,
	realProofSkipSize *big.Int,
) (bool, error)

NeedNewProof checks whether the L2 block still needs a new proof.

func NeedNewSystemProof

func NeedNewSystemProof(ctx context.Context, cli *Client, id *big.Int, realProofSkipSize *big.Int) (bool, error)

NeedNewSystemProof checks whether the L2 block still needs a new system proof.

func SetHead

func SetHead(ctx context.Context, rpc *rpc.Client, headNum *big.Int) error

SetHead makes a `debug_setHead` RPC call to set the chain's head, should only be used for testing purpose.

func StringToBytes32

func StringToBytes32(str string) [32]byte

StringToBytes32 converts the given string to [32]byte.

func SubscribeBlockProposed

func SubscribeBlockProposed(
	mxcL1 *bindings.MxcL1Client,
	ch chan *bindings.MxcL1ClientBlockProposed,
) event.Subscription

SubscribeBlockProposed subscribes the protocol's BlockProposed events.

func SubscribeBlockProven

func SubscribeBlockProven(
	mxcL1 *bindings.MxcL1Client,
	ch chan *bindings.MxcL1ClientBlockProven,
) event.Subscription

SubscribeBlockProven subscribes the protocol's BlockProven events.

func SubscribeBlockVerified

func SubscribeBlockVerified(
	mxcL1 *bindings.MxcL1Client,
	ch chan *bindings.MxcL1ClientBlockVerified,
) event.Subscription

SubscribeBlockVerified subscribes the protocol's BlockVerified events.

func SubscribeChainHead

func SubscribeChainHead(
	client *ethclient.Client,
	ch chan *types.Header,
) event.Subscription

SubscribeChainHead subscribes the new chain heads.

func SubscribeEvent

func SubscribeEvent(
	eventName string,
	handler func(ctx context.Context) (event.Subscription, error),
) event.Subscription

SubscribeEvent creates a event subscription, will retry if the established subscription failed.

func SubscribeXchainSynced

func SubscribeXchainSynced(
	mxcL1 *bindings.MxcL1Client,
	ch chan *bindings.MxcL1ClientCrossChainSynced,
) event.Subscription

SubscribeXchainSynced subscribes the protocol's XchainSynced events.

func WaitConfirmations

func WaitConfirmations(ctx context.Context, client *ethclient.Client, confirmations uint64, begin uint64) error

WaitConfirmations won't return before N blocks confirmations have been seen on destination chain.

func WaitReceipt

func WaitReceipt(ctx context.Context, client *ethclient.Client, tx *types.Transaction) (*types.Receipt, error)

WaitReceipt keeps waiting until the given transaction has an execution receipt to know whether it was reverted or not.

Types

type Client

type Client struct {
	// Geth ethclient clients
	L1           *ethclient.Client
	L2           *ethclient.Client
	L2CheckPoint *ethclient.Client
	// Geth gethclient clients
	L1GethClient *gethclient.Client
	L2GethClient *gethclient.Client
	// Geth raw RPC clients
	L1RawRPC *rpc.Client
	L2RawRPC *rpc.Client
	// Geth Engine API clients
	L2Engine *EngineClient
	// Protocol contracts clients
	MxcL1    *bindings.MxcL1Client
	MxcL2    *bindings.MxcL2Client
	LPWAN    *bindings.LPWANClient
	MxcToken *bindings.MxcTokenClient
	// Chain IDs
	L1ChainID *big.Int
	L2ChainID *big.Int
}

Client contains all L1/L2 RPC clients that a driver needs.

func NewClient

func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error)

NewClient initializes all RPC clients used by Taiko client softwares.

func (*Client) CheckL1Reorg

func (c *Client) CheckL1Reorg(ctx context.Context, blockID *big.Int) (bool, *types.Header, *big.Int, error)

CheckL1Reorg checks whether the L1 chain has been reorged, if so, returns the l1Current cursor and L2 blockID that need to reset to.

func (*Client) GetGenesisL1Header

func (c *Client) GetGenesisL1Header(ctx context.Context) (*types.Header, error)

GetGenesisL1Header fetches the L1 header that including L2 genesis block.

func (*Client) GetPoolContent

func (c *Client) GetPoolContent(
	ctx context.Context,
	maxTransactionsPerBlock uint64,
	blockMaxGasLimit uint64,
	maxBytesPerTxList uint64,
	locals []common.Address,
	blockedAddresses []common.Address,
) ([]types.Transactions, error)

GetPoolContent fetches the transactions list from L2 execution engine's transactions pool with given upper limit.

func (*Client) GetProtocolStateVariables

func (c *Client) GetProtocolStateVariables(opts *bind.CallOpts) (*bindings.MxcDataStateVariables, error)

GetProtocolStateVariables gets the protocol states from MxcL1 contract.

func (*Client) GetStorageRoot

func (c *Client) GetStorageRoot(
	ctx context.Context,
	gethclient *gethclient.Client,
	contract common.Address,
	height *big.Int,
) (common.Hash, error)

GetStorageRoot returns a contract's storage root at the given height.

func (*Client) L2AccountNonce

func (c *Client) L2AccountNonce(
	ctx context.Context,
	account common.Address,
	height *big.Int,
) (uint64, error)

L2AccountNonce fetches the nonce of the given L2 account at a specified height.

func (*Client) L2ExecutionEngineSyncProgress

func (c *Client) L2ExecutionEngineSyncProgress(ctx context.Context) (*L2SyncProgress, error)

L2ExecutionEngineSyncProgress fetches the sync progress of the given L2 execution engine.

func (*Client) L2ParentByBlockId

func (c *Client) L2ParentByBlockId(ctx context.Context, blockID *big.Int) (*types.Header, error)

L2ParentByBlockId fetches the block header from L2 execution engine with the largest block id that smaller than the given `blockId`.

func (*Client) LatestL2KnownL1Header

func (c *Client) LatestL2KnownL1Header(ctx context.Context) (*types.Header, error)

LatestL2KnownL1Header fetches the L2 execution engine's latest known L1 header.

func (*Client) WaitL1Origin

func (c *Client) WaitL1Origin(ctx context.Context, blockID *big.Int) (*rawdb.L1Origin, error)

WaitL1Origin keeps waiting until the L1Origin with given block ID appears on the L2 execution engine.

func (*Client) WaitTillL2ExecutionEngineSynced

func (c *Client) WaitTillL2ExecutionEngineSynced(ctx context.Context) error

WaitTillL2ExecutionEngineSynced keeps waiting until the L2 execution engine is fully synced.

type ClientConfig

type ClientConfig struct {
	L1Endpoint       string
	L1HTTPEndpoint   string
	L2Endpoint       string
	L2CheckPoint     string
	MxcL1Address     common.Address
	MxcL2Address     common.Address
	LPWANAddress     *common.Address
	MxcTokenAddress  *common.Address
	L2EngineEndpoint string
	JwtSecret        string
}

ClientConfig contains all configs which will be used to initializing an RPC client. If not providing L2EngineEndpoint or JwtSecret, then the L2Engine client won't be initialized.

type EngineClient

type EngineClient struct {
	*rpc.Client
}

EngineClient represents a RPC client connecting to an Ethereum Engine API endpoint. ref: https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md

func DialEngineClientWithBackoff

func DialEngineClientWithBackoff(ctx context.Context, url string, jwtSecret string) (*EngineClient, error)

DialEngineClientWithBackoff connects an ethereum engine RPC client at the given URL with a backoff strategy.

func (*EngineClient) ForkchoiceUpdate

func (c *EngineClient) ForkchoiceUpdate(
	ctx context.Context,
	fc *engine.ForkchoiceStateV1,
	attributes *engine.PayloadAttributes,
) (*engine.ForkChoiceResponse, error)

ForkchoiceUpdate updates the forkchoice on the execution client.

func (*EngineClient) GetPayload

func (c *EngineClient) GetPayload(
	ctx context.Context,
	payloadID *engine.PayloadID,
) (*engine.ExecutableData, error)

GetPayload gets the execution payload associated with the payload ID.

func (*EngineClient) NewPayload

func (c *EngineClient) NewPayload(
	ctx context.Context,
	payload *engine.ExecutableData,
) (*engine.PayloadStatusV1, error)

ExecutePayload executes a built block on the execution engine.

type L2SyncProgress

type L2SyncProgress struct {
	*ethereum.SyncProgress
	CurrentBlockID *big.Int
	HighestBlockID *big.Int
}

L2SyncProgress represents the sync progress of a L2 execution engine, `ethereum.SyncProgress` is used to check the sync progress of verified blocks, and block IDs are used to check the sync progress of pending blocks.

Jump to

Keyboard shortcuts

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