Commit 107a41e0 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #4659 from ethereum-optimism/jg/rpc_timeouts

op-node: Set RPC timeouts
parents 6e71a8d8 56789460
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"regexp" "regexp"
"time"
"github.com/ethereum-optimism/optimism/op-service/backoff" "github.com/ethereum-optimism/optimism/op-service/backoff"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
...@@ -62,6 +63,7 @@ func DialRPCClientWithBackoff(ctx context.Context, log log.Logger, addr string, ...@@ -62,6 +63,7 @@ func DialRPCClientWithBackoff(ctx context.Context, log log.Logger, addr string,
// BaseRPCClient is a wrapper around a concrete *rpc.Client instance to make it compliant // BaseRPCClient is a wrapper around a concrete *rpc.Client instance to make it compliant
// with the client.RPC interface. // with the client.RPC interface.
// It sets a timeout of 10s on CallContext & 20s on BatchCallContext made through it.
type BaseRPCClient struct { type BaseRPCClient struct {
c *rpc.Client c *rpc.Client
} }
...@@ -75,11 +77,15 @@ func (b *BaseRPCClient) Close() { ...@@ -75,11 +77,15 @@ func (b *BaseRPCClient) Close() {
} }
func (b *BaseRPCClient) CallContext(ctx context.Context, result any, method string, args ...any) error { func (b *BaseRPCClient) CallContext(ctx context.Context, result any, method string, args ...any) error {
return b.c.CallContext(ctx, result, method, args...) cCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
return b.c.CallContext(cCtx, result, method, args...)
} }
func (b *BaseRPCClient) BatchCallContext(ctx context.Context, batch []rpc.BatchElem) error { func (b *BaseRPCClient) BatchCallContext(ctx context.Context, batch []rpc.BatchElem) error {
return b.c.BatchCallContext(ctx, batch) cCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
return b.c.BatchCallContext(cCtx, batch)
} }
func (b *BaseRPCClient) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error) { func (b *BaseRPCClient) EthSubscribe(ctx context.Context, channel any, args ...any) (ethereum.Subscription, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment