rpc

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 26 Imported by: 1

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,
	retryInterval time.Duration,
	maxRetrys *big.Int) (*ethclient.Client, error)

DialClientWithBackoff connects a ethereum RPC client at the given URL with a backoff strategy. Added a retry limit so it doesn't retry endlessly

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 GetPendingTxByNonce added in v0.13.0

func GetPendingTxByNonce(
	ctx context.Context,
	cli *Client,
	address common.Address,
	nonce uint64,
) (*types.Transaction, error)

GetPendingTxByNonce tries to retrieve a pending transaction with a given nonce in a node's mempool.

func GetProtocolStateVariables added in v0.1.8

func GetProtocolStateVariables(
	taikoL1Client *bindings.TaikoL1Client,
	opts *bind.CallOpts,
) (*bindings.TaikoDataStateVariables, error)

GetProtocolStateVariables gets the protocol states from TaikoL1 contract.

func IsArchiveNode added in v0.14.0

func IsArchiveNode(ctx context.Context, client *EthClient, l2GenesisHeight uint64) (bool, error)

IsArchiveNode checks if the given node is an archive node.

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 added in v0.9.0

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

NeedNewProof checks whether the L2 block still needs a new 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 added in v0.9.0

func StringToBytes32(str string) [32]byte

StringToBytes32 converts the given string to [32]byte.

func SubscribeBlockProposed added in v0.2.3

func SubscribeBlockProposed(
	taikoL1 *bindings.TaikoL1Client,
	ch chan *bindings.TaikoL1ClientBlockProposed,
) event.Subscription

SubscribeBlockProposed subscribes the protocol's BlockProposed events.

func SubscribeBlockProven added in v0.2.3

func SubscribeBlockProven(
	taikoL1 *bindings.TaikoL1Client,
	ch chan *bindings.TaikoL1ClientBlockProven,
) event.Subscription

SubscribeBlockProven subscribes the protocol's BlockProven events.

func SubscribeBlockVerified added in v0.2.3

func SubscribeBlockVerified(
	taikoL1 *bindings.TaikoL1Client,
	ch chan *bindings.TaikoL1ClientBlockVerified,
) event.Subscription

SubscribeBlockVerified subscribes the protocol's BlockVerified events.

func SubscribeChainHead added in v0.2.3

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

SubscribeChainHead subscribes the new chain heads.

func SubscribeEvent added in v0.2.3

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 added in v0.7.0

func SubscribeXchainSynced(
	taikoL1 *bindings.TaikoL1Client,
	ch chan *bindings.TaikoL1ClientCrossChainSynced,
) event.Subscription

SubscribeXchainSynced subscribes the protocol's XchainSynced events.

func WaitReceipt

func WaitReceipt(
	ctx context.Context,
	client *EthClient,
	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 AccountPoolContent added in v0.13.0

type AccountPoolContent map[string]map[string]*types.Transaction

func ContentFrom added in v0.13.0

func ContentFrom(
	ctx context.Context,
	rawRPC *rpc.Client,
	address common.Address,
) (AccountPoolContent, error)

ContentFrom fetches a given account's transactions list from a node's transactions pool.

type Client

type Client struct {
	// Geth ethclient clients
	L1           *EthClient
	L2           *EthClient
	L2CheckPoint *EthClient
	// 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
	TaikoL1    *bindings.TaikoL1Client
	TaikoL2    *bindings.TaikoL2Client
	TaikoToken *bindings.TaikoToken
	// 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) CheckL1ReorgFromL1Cursor added in v0.13.0

func (c *Client) CheckL1ReorgFromL1Cursor(
	ctx context.Context,
	l1Current *types.Header,
	genesisHeightL1 uint64,
) (bool, *types.Header, *big.Int, error)

CheckL1ReorgFromL1Cursor checks whether the L1 chain has been reorged from the given l1Current cursor, if so, returns the l1Current cursor that need to reset to.

func (*Client) CheckL1ReorgFromL2EE added in v0.13.0

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

CheckL1ReorgFromL2EE checks whether the L1 chain has been reorged from the L1Origin records in L2 EE, 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 added in v0.5.0

func (c *Client) GetPoolContent(
	ctx context.Context,
	beneficiary common.Address,
	baseFee *big.Int,
	blockMaxGasLimit uint32,
	maxBytesPerTxList uint64,
	locals []common.Address,
	maxTransactionsLists uint64,
) ([]types.Transactions, error)

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

func (*Client) GetProtocolStateVariables added in v0.1.8

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

GetProtocolStateVariables gets the protocol states from TaikoL1 contract.

func (*Client) GetStorageRoot added in v0.7.0

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) IsJustSyncedByP2P added in v0.13.0

func (c *Client) IsJustSyncedByP2P(ctx context.Context) (bool, error)

IsJustSyncedByP2P checks whether the given L2 execution engine has just finished a P2P sync.

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 added in v0.2.4

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 added in v0.10.0

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
	L2Endpoint        string
	L2CheckPoint      string
	TaikoL1Address    common.Address
	TaikoL2Address    common.Address
	TaikoTokenAddress common.Address
	L2EngineEndpoint  string
	JwtSecret         string
	RetryInterval     time.Duration
	Timeout           *time.Duration
	BackOffMaxRetrys  *big.Int
}

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,
	retryInterval time.Duration,
	maxRetrys *big.Int,
) (*EngineClient, error)

DialEngineClientWithBackoff connects an ethereum engine RPC client at the given URL with a backoff strategy. Added a retry limit so it doesn't retry endlessly

func (*EngineClient) ExchangeTransitionConfiguration added in v0.11.0

func (c *EngineClient) ExchangeTransitionConfiguration(
	ctx context.Context,
	cfg *engine.TransitionConfigurationV1,
) (*engine.TransitionConfigurationV1, error)

ExchangeTransitionConfiguration exchanges transition configs with the L2 execution engine.

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 EthClient added in v0.14.0

type EthClient struct {
	*ethclient.Client
	// contains filtered or unexported fields
}

EthClient is a wrapper for go-ethereum ethclient with a timeout attached.

func NewEthClientWithDefaultTimeout added in v0.14.0

func NewEthClientWithDefaultTimeout(
	ethclient *ethclient.Client,
) *EthClient

NewEthClientWithDefaultTimeout creates a new EthClient instance with the default timeout.

func NewEthClientWithTimeout added in v0.14.0

func NewEthClientWithTimeout(
	ethclient *ethclient.Client,
	timeout time.Duration,
) *EthClient

NewEthClientWithTimeout creates a new EthClient instance with the given request timeout.

func (*EthClient) BalanceAt added in v0.14.0

func (c *EthClient) BalanceAt(
	ctx context.Context,
	account common.Address,
	blockNumber *big.Int,
) (*big.Int, error)

BalanceAt returns the wei balance of the given account. The block number can be nil, in which case the balance is taken from the latest known block.

func (*EthClient) BlockByHash added in v0.14.0

func (c *EthClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)

BlockByHash returns the given full block.

Note that loading full blocks requires two requests. Use HeaderByHash if you don't need all transactions or uncle headers.

func (*EthClient) BlockByNumber added in v0.14.0

func (c *EthClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

BlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.

Note that loading full blocks requires two requests. Use HeaderByNumber if you don't need all transactions or uncle headers.

func (*EthClient) BlockNumber added in v0.14.0

func (c *EthClient) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber returns the most recent block number

func (*EthClient) CallContract added in v0.14.0

func (c *EthClient) CallContract(
	ctx context.Context,
	msg ethereum.CallMsg,
	blockNumber *big.Int,
) ([]byte, error)

CallContract executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.

blockNumber selects the block height at which the call runs. It can be nil, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available.

func (*EthClient) CallContractAtHash added in v0.14.0

func (c *EthClient) CallContractAtHash(
	ctx context.Context,
	msg ethereum.CallMsg,
	blockHash common.Hash,
) ([]byte, error)

CallContractAtHash is almost the same as CallContract except that it selects the block by block hash instead of block height.

func (*EthClient) ChainID added in v0.14.0

func (c *EthClient) ChainID(ctx context.Context) (*big.Int, error)

ChainID retrieves the current chain ID for transaction replay protection.

func (*EthClient) CodeAt added in v0.14.0

func (c *EthClient) CodeAt(
	ctx context.Context,
	account common.Address,
	blockNumber *big.Int,
) ([]byte, error)

CodeAt returns the contract code of the given account. The block number can be nil, in which case the code is taken from the latest known block.

func (*EthClient) EstimateGas added in v0.14.0

func (c *EthClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.

func (*EthClient) FeeHistory added in v0.14.0

func (c *EthClient) FeeHistory(
	ctx context.Context,
	blockCount uint64,
	lastBlock *big.Int,
	rewardPercentiles []float64,
) (*ethereum.FeeHistory, error)

FeeHistory retrieves the fee market history.

func (*EthClient) HeaderByHash added in v0.14.0

func (c *EthClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)

HeaderByHash returns the block header with the given hash.

func (*EthClient) HeaderByNumber added in v0.14.0

func (c *EthClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*EthClient) NetworkID added in v0.14.0

func (c *EthClient) NetworkID(ctx context.Context) (*big.Int, error)

NetworkID returns the network ID for this client.

func (*EthClient) NonceAt added in v0.14.0

func (c *EthClient) NonceAt(
	ctx context.Context,
	account common.Address,
	blockNumber *big.Int,
) (uint64, error)

NonceAt returns the account nonce of the given account. The block number can be nil, in which case the nonce is taken from the latest known block.

func (*EthClient) PeerCount added in v0.14.0

func (c *EthClient) PeerCount(ctx context.Context) (uint64, error)

PeerCount returns the number of p2p peers as reported by the net_peerCount method.

func (*EthClient) PendingBalanceAt added in v0.14.0

func (c *EthClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)

PendingBalanceAt returns the wei balance of the given account in the pending state.

func (*EthClient) PendingCallContract added in v0.14.0

func (c *EthClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

PendingCallContract executes a message call transaction using the EVM. The state seen by the contract call is the pending state.

func (*EthClient) PendingCodeAt added in v0.14.0

func (c *EthClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt returns the contract code of the given account in the pending state.

func (*EthClient) PendingNonceAt added in v0.14.0

func (c *EthClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.

func (*EthClient) PendingStorageAt added in v0.14.0

func (c *EthClient) PendingStorageAt(
	ctx context.Context,
	account common.Address,
	key common.Hash,
) ([]byte, error)

PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.

func (*EthClient) PendingTransactionCount added in v0.14.0

func (c *EthClient) PendingTransactionCount(ctx context.Context) (uint, error)

PendingTransactionCount returns the total number of transactions in the pending state.

func (*EthClient) SendTransaction added in v0.14.0

func (c *EthClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction injects a signed transaction into the pending pool for execution.

If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.

func (*EthClient) StorageAt added in v0.14.0

func (c *EthClient) StorageAt(
	ctx context.Context,
	account common.Address,
	key common.Hash,
	blockNumber *big.Int,
) ([]byte, error)

StorageAt returns the value of key in the contract storage of the given account. The block number can be nil, in which case the value is taken from the latest known block.

func (*EthClient) SuggestGasPrice added in v0.14.0

func (c *EthClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.

func (*EthClient) SuggestGasTipCap added in v0.14.0

func (c *EthClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap retrieves the currently suggested gas tip cap after 1559 to allow a timely execution of a transaction.

func (*EthClient) SyncProgress added in v0.14.0

func (c *EthClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)

SyncProgress retrieves the current progress of the sync algorithm. If there's no sync currently running, it returns nil.

func (*EthClient) TransactionByHash added in v0.14.0

func (c *EthClient) TransactionByHash(
	ctx context.Context,
	hash common.Hash,
) (tx *types.Transaction, isPending bool, err error)

TransactionByHash returns the transaction with the given hash.

func (*EthClient) TransactionCount added in v0.14.0

func (c *EthClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

TransactionCount returns the total number of transactions in the given block.

func (*EthClient) TransactionInBlock added in v0.14.0

func (c *EthClient) TransactionInBlock(
	ctx context.Context,
	blockHash common.Hash,
	index uint,
) (*types.Transaction, error)

TransactionInBlock returns a single transaction at index in the given block.

func (*EthClient) TransactionSender added in v0.14.0

func (c *EthClient) TransactionSender(
	ctx context.Context,
	tx *types.Transaction,
	block common.Hash,
	index uint,
) (common.Address, error)

TransactionSender returns the sender address of the given transaction. The transaction must be known to the remote node and included in the blockchain at the given block and index. The sender is the one derived by the protocol at the time of inclusion.

There is a fast-path for transactions retrieved by TransactionByHash and TransactionInBlock. Getting their sender address can be done without an RPC interaction.

type L2SyncProgress added in v0.2.4

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