Commit 56789460 authored by Joshua Gutow's avatar Joshua Gutow

op-node: Set RPC timeouts

This is done in BaseClient because all RPC calls in the op-node
flow through the base client. I have set it to 10s for the
CallContext and 20s for the BatchCallContext. These values
are large enough to handle complex computation, but will prevent
a slow loris or throttling attack. Smaller timeouts can stil be
set further up the chain.
parent 6e71a8d8
......@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"time"
"github.com/ethereum-optimism/optimism/op-service/backoff"
"github.com/ethereum/go-ethereum"
......@@ -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
// with the client.RPC interface.
// It sets a timeout of 10s on CallContext & 20s on BatchCallContext made through it.
type BaseRPCClient struct {
c *rpc.Client
}
......@@ -75,11 +77,15 @@ func (b *BaseRPCClient) Close() {
}
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 {
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) {
......
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