cmd, eth, internal/ethapi: allow for flag configured timeouts for eth_call #23645 (#1593)

This commit is contained in:
Daniel Liu 2025-09-26 19:01:02 +08:00 committed by GitHub
parent e4ee00adf0
commit 0ece8529c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 29 additions and 8 deletions

View file

@ -150,6 +150,7 @@ var (
rpcFlags = []cli.Flag{
utils.HTTPEnabledFlag,
utils.RPCGlobalGasCapFlag,
utils.RPCGlobalEVMTimeoutFlag,
utils.HTTPListenAddrFlag,
utils.HTTPPortFlag,
utils.HTTPReadTimeoutFlag,

View file

@ -395,6 +395,12 @@ var (
Value: ethconfig.Defaults.RPCGasCap,
Category: flags.APICategory,
}
RPCGlobalEVMTimeoutFlag = &cli.DurationFlag{
Name: "rpc-evmtimeout",
Usage: "Sets a timeout used for eth_call (0=infinite)",
Value: ethconfig.Defaults.RPCEVMTimeout,
Category: flags.APICategory,
}
RPCGlobalTxFeeCap = &cli.Float64Flag{
Name: "rpc-txfeecap",
Aliases: []string{"rpc.txfeecap"},
@ -1618,6 +1624,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
} else {
log.Info("Global gas cap disabled")
}
if ctx.IsSet(RPCGlobalEVMTimeoutFlag.Name) {
cfg.RPCEVMTimeout = ctx.Duration(RPCGlobalEVMTimeoutFlag.Name)
}
if ctx.IsSet(StoreRewardFlag.Name) {
common.StoreRewardFolder = filepath.Join(stack.DataDir(), "XDC", "rewards")
if !common.FileExist(common.StoreRewardFolder) {

View file

@ -23,6 +23,7 @@ import (
"math/big"
"os"
"path/filepath"
"time"
"github.com/XinFinOrg/XDPoSChain/XDCx"
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
@ -393,6 +394,10 @@ func (b *EthAPIBackend) RPCGasCap() uint64 {
return b.eth.config.RPCGasCap
}
func (b *EthAPIBackend) RPCEVMTimeout() time.Duration {
return b.eth.config.RPCEVMTimeout
}
func (b *EthAPIBackend) AccountManager() *accounts.Manager {
return b.eth.AccountManager()
}

View file

@ -52,10 +52,11 @@ var Defaults = Config{
FilterLogCacheSize: 32,
GasPrice: big.NewInt(0.25 * params.Shannon),
TxPool: txpool.DefaultConfig,
RPCGasCap: 50000000,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
TxPool: txpool.DefaultConfig,
RPCGasCap: 50000000,
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
}
//go:generate go run github.com/fjl/gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
@ -112,6 +113,9 @@ type Config struct {
// RPCGasCap is the global gas cap for eth-call variants.
RPCGasCap uint64
// RPCEVMTimeout is the global timeout for eth-call.
RPCEVMTimeout time.Duration
// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
// send-transction variants. The unit is ether.
RPCTxFeeCap float64

View file

@ -1230,7 +1230,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
latest := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
blockNrOrHash = &latest
}
timeout := 5 * time.Second
timeout := s.b.RPCEVMTimeout()
if args.To != nil && *args.To == common.MasternodeVotingSMCBinary {
timeout = 0
}

View file

@ -20,6 +20,7 @@ package ethapi
import (
"context"
"math/big"
"time"
"github.com/XinFinOrg/XDPoSChain/XDCx"
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
@ -51,9 +52,10 @@ type Backend interface {
BlobBaseFee(ctx context.Context) *big.Int
ChainDb() ethdb.Database
AccountManager() *accounts.Manager
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
UnprotectedAllowed() bool // allows only for EIP155 transactions.
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
UnprotectedAllowed() bool // allows only for EIP155 transactions.
XDCxService() *XDCx.XDCX
LendingService() *XDCxlending.Lending