Skip to content

Commit 802feaf

Browse files
authored
override the 5 secs default time out for eth_call (#1085)
1 parent 7196f19 commit 802feaf

File tree

12 files changed

+60
-7
lines changed

12 files changed

+60
-7
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ var (
168168
utils.PluginLocalVerifyFlag,
169169
utils.PluginPublicKeyFlag,
170170
utils.AllowedFutureBlockTimeFlag,
171+
utils.EVMCallTimeOutFlag,
171172
// End-Quorum
172173
}
173174

cmd/geth/usage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ var AppHelpFlagGroups = []flagGroup{
239239
utils.VMEnableDebugFlag,
240240
utils.EVMInterpreterFlag,
241241
utils.EWASMInterpreterFlag,
242+
// Quorum - timout for calls
243+
utils.EVMCallTimeOutFlag,
242244
},
243245
},
244246
{

cmd/utils/flags.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,13 @@ var (
787787
Value: "",
788788
}
789789

790+
// Quorum - added configurable call timeout for execution of calls
791+
EVMCallTimeOutFlag = cli.IntFlag{
792+
Name: "vm.calltimeout",
793+
Usage: "Timeout duration in seconds for message call execution without creating a transaction. Value 0 means no timeout.",
794+
Value: 5,
795+
}
796+
790797
// Quorum
791798
// immutability threshold which can be passed as a parameter at geth start
792799
QuorumImmutabilityThreshold = cli.IntFlag{
@@ -1543,6 +1550,13 @@ func setRaft(ctx *cli.Context, cfg *eth.Config) {
15431550
cfg.RaftMode = ctx.GlobalBool(RaftModeFlag.Name)
15441551
}
15451552

1553+
func setQuorumConfig(ctx *cli.Context, cfg *eth.Config) {
1554+
cfg.EVMCallTimeOut = time.Duration(ctx.GlobalInt(EVMCallTimeOutFlag.Name)) * time.Second
1555+
1556+
setIstanbul(ctx, cfg)
1557+
setRaft(ctx, cfg)
1558+
}
1559+
15461560
// CheckExclusive verifies that only a single instance of the provided flags was
15471561
// set by the user. Each flag might optionally be followed by a string type to
15481562
// specialize it further.
@@ -1617,8 +1631,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
16171631
setLes(ctx, cfg)
16181632

16191633
// Quorum
1620-
setIstanbul(ctx, cfg)
1621-
setRaft(ctx, cfg)
1634+
setQuorumConfig(ctx, cfg)
16221635

16231636
if ctx.GlobalIsSet(SyncModeFlag.Name) {
16241637
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)

cmd/utils/flags_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ func TestSetImmutabilityThreshold(t *testing.T) {
7878
assert.Equal(t, 100000, arbitraryCLIContext.GlobalInt(QuorumImmutabilityThreshold.Name), "immutability threshold value not set")
7979
}
8080

81+
func TestSetTimeOutForCall(t *testing.T) {
82+
fs := &flag.FlagSet{}
83+
fs.Int(EVMCallTimeOutFlag.Name, 0, "")
84+
arbitraryCLIContext := cli.NewContext(nil, fs, nil)
85+
assert.NoError(t, arbitraryCLIContext.GlobalSet(EVMCallTimeOutFlag.Name, strconv.Itoa(10)))
86+
assert.True(t, arbitraryCLIContext.GlobalIsSet(EVMCallTimeOutFlag.Name), "timeoutforcall flag not set")
87+
assert.Equal(t, 10, arbitraryCLIContext.GlobalInt(EVMCallTimeOutFlag.Name), "timeoutforcall value not set")
88+
}
89+
8190
func TestSetPlugins_whenTypical(t *testing.T) {
8291
tmpDir, err := ioutil.TempDir("", "q-")
8392
if err != nil {

eth/api_backend.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"math/big"
24+
"time"
2425

2526
"github.com/ethereum/go-ethereum/accounts"
2627
"github.com/ethereum/go-ethereum/common"
@@ -49,6 +50,9 @@ type EthAPIBackend struct {
4950
//
5051
// hex node id from node public key
5152
hexNodeId string
53+
54+
// timeout value for call
55+
evmCallTimeOut time.Duration
5256
}
5357

5458
// ChainConfig returns the active chain configuration.
@@ -332,6 +336,10 @@ func (b *EthAPIBackend) ExtRPCEnabled() bool {
332336
return b.extRPCEnabled
333337
}
334338

339+
func (b *EthAPIBackend) CallTimeOut() time.Duration {
340+
return b.evmCallTimeOut
341+
}
342+
335343
func (b *EthAPIBackend) RPCGasCap() *big.Int {
336344
return b.eth.config.RPCGasCap
337345
}

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
244244
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData, eth.blockchain.Config().IsQuorum))
245245

246246
hexNodeId := fmt.Sprintf("%x", crypto.FromECDSAPub(&ctx.NodeKey().PublicKey)[1:]) // Quorum
247-
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, hexNodeId}
247+
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, hexNodeId, config.EVMCallTimeOut}
248248
gpoParams := config.GPO
249249
if gpoParams.Default == nil {
250250
gpoParams.Default = config.Miner.GasPrice

eth/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,7 @@ type Config struct {
165165

166166
// Istanbul block override (TODO: remove after the fork)
167167
OverrideIstanbul *big.Int
168+
169+
// timeout value for call
170+
EVMCallTimeOut time.Duration
168171
}

graphql/graphql.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package graphql
2020
import (
2121
"context"
2222
"errors"
23-
"time"
2423

2524
"github.com/ethereum/go-ethereum"
2625
"github.com/ethereum/go-ethereum/common"
@@ -832,7 +831,9 @@ func (b *Block) Call(ctx context.Context, args struct {
832831
return nil, err
833832
}
834833
}
835-
result, gas, failed, err := ethapi.DoCall(ctx, b.backend, args.Data, *b.numberOrHash, nil, vm.Config{}, 5*time.Second, b.backend.RPCGasCap())
834+
835+
// Quorum - replaced the default 5s time out with the value passed in vm.calltimeout
836+
result, gas, failed, err := ethapi.DoCall(ctx, b.backend, args.Data, *b.numberOrHash, nil, vm.Config{}, b.backend.CallTimeOut(), b.backend.RPCGasCap())
836837
status := hexutil.Uint64(1)
837838
if failed {
838839
status = 0
@@ -898,7 +899,9 @@ func (p *Pending) Call(ctx context.Context, args struct {
898899
Data ethapi.CallArgs
899900
}) (*CallResult, error) {
900901
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
901-
result, gas, failed, err := ethapi.DoCall(ctx, p.backend, args.Data, pendingBlockNr, nil, vm.Config{}, 5*time.Second, p.backend.RPCGasCap())
902+
903+
// Quorum - replaced the default 5s time out with the value passed in vm.calltimeout
904+
result, gas, failed, err := ethapi.DoCall(ctx, p.backend, args.Data, pendingBlockNr, nil, vm.Config{}, p.backend.CallTimeOut(), p.backend.RPCGasCap())
902905
status := hexutil.Uint64(1)
903906
if failed {
904907
status = 0

internal/ethapi/api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,9 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
980980
if overrides != nil {
981981
accounts = *overrides
982982
}
983-
result, _, _, err := DoCall(ctx, s.b, args, blockNrOrHash, accounts, vm.Config{}, 5*time.Second, s.b.RPCGasCap())
983+
984+
// Quorum - replaced the default 5s time out with the value passed in vm.calltimeout
985+
result, _, _, err := DoCall(ctx, s.b, args, blockNrOrHash, accounts, vm.Config{}, s.b.CallTimeOut(), s.b.RPCGasCap())
984986
return (hexutil.Bytes)(result), err
985987
}
986988

internal/ethapi/api_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/big"
66
"os"
77
"testing"
8+
"time"
89

910
"github.com/ethereum/go-ethereum/accounts"
1011
"github.com/ethereum/go-ethereum/common"
@@ -490,6 +491,10 @@ func (sb *StubBackend) ExtRPCEnabled() bool {
490491
panic("implement me")
491492
}
492493

494+
func (sb *StubBackend) CallTimeOut() time.Duration {
495+
panic("implement me")
496+
}
497+
493498
func (sb *StubBackend) RPCGasCap() *big.Int {
494499
panic("implement me")
495500
}

0 commit comments

Comments
 (0)