Skip to content

Commit 633e7ef

Browse files
authored
eth,rpc: allow for flag configured timeouts for eth_call (#23645)
* eth,rpc: allow for flag configured timeouts for eth_call * lint: account for package-local import order * cr: rename `rpc.calltimeout` to `rpc.evmtimeout`
1 parent 3d11a22 commit 633e7ef

File tree

10 files changed

+42
-11
lines changed

10 files changed

+42
-11
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ var (
173173
utils.IPCPathFlag,
174174
utils.InsecureUnlockAllowedFlag,
175175
utils.RPCGlobalGasCapFlag,
176+
utils.RPCGlobalEVMTimeoutFlag,
176177
utils.RPCGlobalTxFeeCapFlag,
177178
utils.AllowUnprotectedTxs,
178179
}

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
150150
utils.GraphQLCORSDomainFlag,
151151
utils.GraphQLVirtualHostsFlag,
152152
utils.RPCGlobalGasCapFlag,
153+
utils.RPCGlobalEVMTimeoutFlag,
153154
utils.RPCGlobalTxFeeCapFlag,
154155
utils.AllowUnprotectedTxs,
155156
utils.JSpathFlag,

cmd/utils/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ var (
493493
Usage: "Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite)",
494494
Value: ethconfig.Defaults.RPCGasCap,
495495
}
496+
RPCGlobalEVMTimeoutFlag = cli.DurationFlag{
497+
Name: "rpc.evmtimeout",
498+
Usage: "Sets a timeout used for eth_call (0=infinite)",
499+
Value: ethconfig.Defaults.RPCEVMTimeout,
500+
}
496501
RPCGlobalTxFeeCapFlag = cli.Float64Flag{
497502
Name: "rpc.txfeecap",
498503
Usage: "Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap)",
@@ -1563,6 +1568,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
15631568
} else {
15641569
log.Info("Global gas cap disabled")
15651570
}
1571+
if ctx.GlobalIsSet(RPCGlobalEVMTimeoutFlag.Name) {
1572+
cfg.RPCEVMTimeout = ctx.GlobalDuration(RPCGlobalEVMTimeoutFlag.Name)
1573+
}
15661574
if ctx.GlobalIsSet(RPCGlobalTxFeeCapFlag.Name) {
15671575
cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCapFlag.Name)
15681576
}

eth/api_backend.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"math/big"
23+
"time"
2324

2425
"github.com/ethereum/go-ethereum"
2526
"github.com/ethereum/go-ethereum/accounts"
@@ -319,6 +320,10 @@ func (b *EthAPIBackend) RPCGasCap() uint64 {
319320
return b.eth.config.RPCGasCap
320321
}
321322

323+
func (b *EthAPIBackend) RPCEVMTimeout() time.Duration {
324+
return b.eth.config.RPCEVMTimeout
325+
}
326+
322327
func (b *EthAPIBackend) RPCTxFeeCap() float64 {
323328
return b.eth.config.RPCTxFeeCap
324329
}

eth/ethconfig/config.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ var Defaults = Config{
8787
GasPrice: big.NewInt(params.GWei),
8888
Recommit: 3 * time.Second,
8989
},
90-
TxPool: core.DefaultTxPoolConfig,
91-
RPCGasCap: 50000000,
92-
GPO: FullNodeGPO,
93-
RPCTxFeeCap: 1, // 1 ether
90+
TxPool: core.DefaultTxPoolConfig,
91+
RPCGasCap: 50000000,
92+
RPCEVMTimeout: 5 * time.Second,
93+
GPO: FullNodeGPO,
94+
RPCTxFeeCap: 1, // 1 ether
9495
}
9596

9697
func init() {
@@ -188,6 +189,9 @@ type Config struct {
188189
// RPCGasCap is the global gas cap for eth-call variants.
189190
RPCGasCap uint64
190191

192+
// RPCEVMTimeout is the global timeout for eth-call.
193+
RPCEVMTimeout time.Duration
194+
191195
// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
192196
// send-transction variants. The unit is ether.
193197
RPCTxFeeCap float64

eth/ethconfig/gen_config.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graphql/graphql.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"fmt"
2424
"math/big"
2525
"strconv"
26-
"time"
2726

2827
"github.com/ethereum/go-ethereum"
2928
"github.com/ethereum/go-ethereum/common"
@@ -954,7 +953,7 @@ func (b *Block) Call(ctx context.Context, args struct {
954953
return nil, err
955954
}
956955
}
957-
result, err := ethapi.DoCall(ctx, b.backend, args.Data, *b.numberOrHash, nil, 5*time.Second, b.backend.RPCGasCap())
956+
result, err := ethapi.DoCall(ctx, b.backend, args.Data, *b.numberOrHash, nil, b.backend.RPCEVMTimeout(), b.backend.RPCGasCap())
958957
if err != nil {
959958
return nil, err
960959
}
@@ -1024,7 +1023,7 @@ func (p *Pending) Call(ctx context.Context, args struct {
10241023
Data ethapi.TransactionArgs
10251024
}) (*CallResult, error) {
10261025
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
1027-
result, err := ethapi.DoCall(ctx, p.backend, args.Data, pendingBlockNr, nil, 5*time.Second, p.backend.RPCGasCap())
1026+
result, err := ethapi.DoCall(ctx, p.backend, args.Data, pendingBlockNr, nil, p.backend.RPCEVMTimeout(), p.backend.RPCGasCap())
10281027
if err != nil {
10291028
return nil, err
10301029
}

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ func (e *revertError) ErrorData() interface{} {
972972
// Note, this function doesn't make and changes in the state/blockchain and is
973973
// useful to execute and retrieve values.
974974
func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) {
975-
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, 5*time.Second, s.b.RPCGasCap())
975+
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
976976
if err != nil {
977977
return nil, err
978978
}

internal/ethapi/backend.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package ethapi
2020
import (
2121
"context"
2222
"math/big"
23+
"time"
2324

2425
"github.com/ethereum/go-ethereum"
2526
"github.com/ethereum/go-ethereum/accounts"
@@ -47,9 +48,10 @@ type Backend interface {
4748
ChainDb() ethdb.Database
4849
AccountManager() *accounts.Manager
4950
ExtRPCEnabled() bool
50-
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
51-
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
52-
UnprotectedAllowed() bool // allows only for EIP155 transactions.
51+
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
52+
RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection
53+
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
54+
UnprotectedAllowed() bool // allows only for EIP155 transactions.
5355

5456
// Blockchain API
5557
SetHead(number uint64)

les/api_backend.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"math/big"
23+
"time"
2324

2425
"github.com/ethereum/go-ethereum"
2526
"github.com/ethereum/go-ethereum/accounts"
@@ -293,6 +294,10 @@ func (b *LesApiBackend) RPCGasCap() uint64 {
293294
return b.eth.config.RPCGasCap
294295
}
295296

297+
func (b *LesApiBackend) RPCEVMTimeout() time.Duration {
298+
return b.eth.config.RPCEVMTimeout
299+
}
300+
296301
func (b *LesApiBackend) RPCTxFeeCap() float64 {
297302
return b.eth.config.RPCTxFeeCap
298303
}

0 commit comments

Comments
 (0)