Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taiko-client): add defaultRequestTimeout for SGXProofProducer #17724

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/taiko-client/pkg/rpc/beaconclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewBeaconClient(endpoint string, timeout time.Duration) (*BeaconClient, err

// GetBlobs returns the sidecars for a given slot.
func (c *BeaconClient) GetBlobs(ctx context.Context, time uint64) ([]*blob.Sidecar, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

slot, err := c.timeToSlot(time)
Expand Down
4 changes: 2 additions & 2 deletions packages/taiko-client/pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {

// Keep retrying to connect to the RPC endpoints until success or context is cancelled.
if err := backoff.Retry(func() error {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()

if l1Client, err = NewEthClient(ctxWithTimeout, cfg.L1Endpoint, cfg.Timeout); err != nil {
Expand Down Expand Up @@ -100,7 +100,7 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
return nil, err
}

ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()

taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1Client)
Expand Down
4 changes: 2 additions & 2 deletions packages/taiko-client/pkg/rpc/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func DialClientWithBackoff(
var client *ethclient.Client
if err := backoff.Retry(
func() (err error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()

client, err = ethclient.DialContext(ctxWithTimeout, url)
Expand Down Expand Up @@ -52,7 +52,7 @@ func DialEngineClientWithBackoff(
var engineClient *EngineClient
if err := backoff.Retry(
func() (err error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()

jwtAuth := node.NewJWTAuth(StringToBytes32(jwtSecret))
Expand Down
60 changes: 30 additions & 30 deletions packages/taiko-client/pkg/rpc/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewEthClient(ctx context.Context, url string, timeout time.Duration) (*EthC
// Note that loading full blocks requires two requests. Use HeaderByHash
// if you don't need all transactions or uncle headers.
func (c *EthClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.BlockByHash(ctxWithTimeout, hash)
Expand All @@ -77,31 +77,31 @@ func (c *EthClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.B
// Note that loading full blocks requires two requests. Use HeaderByNumber
// if you don't need all transactions or uncle headers.
func (c *EthClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.BlockByNumber(ctxWithTimeout, number)
}

// BlockNumber returns the most recent block number
func (c *EthClient) BlockNumber(ctx context.Context) (uint64, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.BlockNumber(ctxWithTimeout)
}

// PeerCount returns the number of p2p peers as reported by the net_peerCount method.
func (c *EthClient) PeerCount(ctx context.Context) (uint64, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.PeerCount(ctxWithTimeout)
}

// HeaderByHash returns the block header with the given hash.
func (c *EthClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.HeaderByHash(ctxWithTimeout, hash)
Expand All @@ -110,7 +110,7 @@ func (c *EthClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.
// HeaderByNumber returns a block header from the current canonical chain. If number is
// nil, the latest known header is returned.
func (c *EthClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.HeaderByNumber(ctxWithTimeout, number)
Expand All @@ -121,7 +121,7 @@ func (c *EthClient) TransactionByHash(
ctx context.Context,
hash common.Hash,
) (tx *types.Transaction, isPending bool, err error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.TransactionByHash(ctxWithTimeout, hash)
Expand All @@ -139,15 +139,15 @@ func (c *EthClient) TransactionSender(
block common.Hash,
index uint,
) (common.Address, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.TransactionSender(ctxWithTimeout, tx, block, index)
}

// TransactionCount returns the total number of transactions in the given block.
func (c *EthClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.TransactionCount(ctxWithTimeout, blockHash)
Expand All @@ -159,7 +159,7 @@ func (c *EthClient) TransactionInBlock(
blockHash common.Hash,
index uint,
) (*types.Transaction, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.TransactionInBlock(ctxWithTimeout, blockHash, index)
Expand All @@ -168,15 +168,15 @@ func (c *EthClient) TransactionInBlock(
// SyncProgress retrieves the current progress of the sync algorithm. If there's
// no sync currently running, it returns nil.
func (c *EthClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.SyncProgress(ctxWithTimeout)
}

// NetworkID returns the network ID for this client.
func (c *EthClient) NetworkID(ctx context.Context) (*big.Int, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.NetworkID(ctxWithTimeout)
Expand All @@ -189,7 +189,7 @@ func (c *EthClient) BalanceAt(
account common.Address,
blockNumber *big.Int,
) (*big.Int, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.BalanceAt(ctxWithTimeout, account, blockNumber)
Expand All @@ -203,7 +203,7 @@ func (c *EthClient) StorageAt(
key common.Hash,
blockNumber *big.Int,
) ([]byte, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.StorageAt(ctxWithTimeout, account, key, blockNumber)
Expand All @@ -216,7 +216,7 @@ func (c *EthClient) CodeAt(
account common.Address,
blockNumber *big.Int,
) ([]byte, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.CodeAt(ctxWithTimeout, account, blockNumber)
Expand All @@ -229,15 +229,15 @@ func (c *EthClient) NonceAt(
account common.Address,
blockNumber *big.Int,
) (uint64, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.NonceAt(ctxWithTimeout, account, blockNumber)
}

// PendingBalanceAt returns the wei balance of the given account in the pending state.
func (c *EthClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.PendingBalanceAt(ctxWithTimeout, account)
Expand All @@ -249,15 +249,15 @@ func (c *EthClient) PendingStorageAt(
account common.Address,
key common.Hash,
) ([]byte, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.PendingStorageAt(ctxWithTimeout, account, key)
}

// PendingCodeAt returns the contract code of the given account in the pending state.
func (c *EthClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.PendingCodeAt(ctxWithTimeout, account)
Expand All @@ -266,15 +266,15 @@ func (c *EthClient) PendingCodeAt(ctx context.Context, account common.Address) (
// 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 (c *EthClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.PendingNonceAt(ctxWithTimeout, account)
}

// PendingTransactionCount returns the total number of transactions in the pending state.
func (c *EthClient) PendingTransactionCount(ctx context.Context) (uint, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.PendingTransactionCount(ctxWithTimeout)
Expand All @@ -291,7 +291,7 @@ func (c *EthClient) CallContract(
msg ethereum.CallMsg,
blockNumber *big.Int,
) ([]byte, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.CallContract(ctxWithTimeout, msg, blockNumber)
Expand All @@ -304,7 +304,7 @@ func (c *EthClient) CallContractAtHash(
msg ethereum.CallMsg,
blockHash common.Hash,
) ([]byte, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.CallContractAtHash(ctxWithTimeout, msg, blockHash)
Expand All @@ -313,7 +313,7 @@ func (c *EthClient) CallContractAtHash(
// PendingCallContract executes a message call transaction using the EVM.
// The state seen by the contract call is the pending state.
func (c *EthClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.PendingCallContract(ctxWithTimeout, msg)
Expand All @@ -322,7 +322,7 @@ func (c *EthClient) PendingCallContract(ctx context.Context, msg ethereum.CallMs
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
// execution of a transaction.
func (c *EthClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.SuggestGasPrice(ctxWithTimeout)
Expand All @@ -331,7 +331,7 @@ func (c *EthClient) SuggestGasPrice(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 (c *EthClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.SuggestGasTipCap(ctxWithTimeout)
Expand All @@ -344,7 +344,7 @@ func (c *EthClient) FeeHistory(
lastBlock *big.Int,
rewardPercentiles []float64,
) (*ethereum.FeeHistory, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.FeeHistory(ctxWithTimeout, blockCount, lastBlock, rewardPercentiles)
Expand All @@ -355,7 +355,7 @@ func (c *EthClient) FeeHistory(
// 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 (c *EthClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.EstimateGas(ctxWithTimeout, msg)
Expand All @@ -366,7 +366,7 @@ func (c *EthClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint
// If the transaction was a contract creation use the TransactionReceipt method to get the
// contract address after the transaction has been mined.
func (c *EthClient) SendTransaction(ctx context.Context, tx *types.Transaction) error {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

return c.ethClient.SendTransaction(ctxWithTimeout, tx)
Expand Down Expand Up @@ -407,7 +407,7 @@ type SignTransactionResult struct {

// FillTransaction fill transaction.
func (c *EthClient) FillTransaction(ctx context.Context, args *TransactionArgs) (*types.Transaction, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, c.timeout)
ctxWithTimeout, cancel := CtxWithTimeoutOrDefault(ctx, c.timeout)
defer cancel()

var result SignTransactionResult
Expand Down
Loading
Loading