From 0ece8529c43ee251c4ad2db5fa9795db55efbc5a Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 26 Sep 2025 19:01:02 +0800 Subject: [PATCH] cmd, eth, internal/ethapi: allow for flag configured timeouts for eth_call #23645 (#1593) --- cmd/XDC/main.go | 1 + cmd/utils/flags.go | 9 +++++++++ eth/api_backend.go | 5 +++++ eth/ethconfig/config.go | 12 ++++++++---- internal/ethapi/api.go | 2 +- internal/ethapi/backend.go | 8 +++++--- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/cmd/XDC/main.go b/cmd/XDC/main.go index 1508b3c35c..83e6e67df2 100644 --- a/cmd/XDC/main.go +++ b/cmd/XDC/main.go @@ -150,6 +150,7 @@ var ( rpcFlags = []cli.Flag{ utils.HTTPEnabledFlag, utils.RPCGlobalGasCapFlag, + utils.RPCGlobalEVMTimeoutFlag, utils.HTTPListenAddrFlag, utils.HTTPPortFlag, utils.HTTPReadTimeoutFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5dcc5bbb1a..7288683d07 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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) { diff --git a/eth/api_backend.go b/eth/api_backend.go index 9f3f92f5f6..55a8980c25 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -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() } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 8a2490ebfb..211ec29425 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -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 diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 289061063c..36dda2f30b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -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 } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index f19c0fd9e3..70157564c8 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -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