diff --git a/cmd/utils/bor_flags.go b/cmd/utils/bor_flags.go index 76d965746c..7ff4115b77 100644 --- a/cmd/utils/bor_flags.go +++ b/cmd/utils/bor_flags.go @@ -2,6 +2,7 @@ package utils import ( "os" + "time" "github.com/urfave/cli/v2" @@ -22,6 +23,13 @@ var ( Value: "http://localhost:1317", } + // HeimdallTimeoutFlag flag for heimdall timeout + HeimdallTimeoutFlag = &cli.DurationFlag{ + Name: "bor.heimdalltimeout", + Usage: "Timeout of Heimdall service", + Value: 5 * time.Second, + } + // WithoutHeimdallFlag no heimdall (for testing purpose) WithoutHeimdallFlag = &cli.BoolFlag{ Name: "bor.withoutheimdall", @@ -56,6 +64,7 @@ var ( // BorFlags all bor related flags BorFlags = []cli.Flag{ HeimdallURLFlag, + HeimdallTimeoutFlag, WithoutHeimdallFlag, HeimdallgRPCAddressFlag, RunHeimdallFlag, @@ -67,6 +76,7 @@ var ( // SetBorConfig sets bor config func SetBorConfig(ctx *cli.Context, cfg *eth.Config) { cfg.HeimdallURL = ctx.String(HeimdallURLFlag.Name) + cfg.HeimdallTimeout = ctx.Duration(HeimdallTimeoutFlag.Name) cfg.WithoutHeimdall = ctx.Bool(WithoutHeimdallFlag.Name) cfg.HeimdallgRPCAddress = ctx.String(HeimdallgRPCAddressFlag.Name) cfg.RunHeimdall = ctx.Bool(RunHeimdallFlag.Name) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d0ceada34f..444b4ddd05 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2314,6 +2314,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh configs := ðconfig.Config{ Genesis: gspec, HeimdallURL: ctx.String(HeimdallURLFlag.Name), + HeimdallTimeout: ctx.Duration(HeimdallTimeoutFlag.Name), WithoutHeimdall: ctx.Bool(WithoutHeimdallFlag.Name), HeimdallgRPCAddress: ctx.String(HeimdallgRPCAddressFlag.Name), RunHeimdall: ctx.Bool(RunHeimdallArgsFlag.Name), diff --git a/consensus/bor/heimdall/client.go b/consensus/bor/heimdall/client.go index 029164c986..4c21c31fac 100644 --- a/consensus/bor/heimdall/client.go +++ b/consensus/bor/heimdall/client.go @@ -33,7 +33,6 @@ var ( const ( heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB stateFetchLimit = 50 - apiHeimdallTimeout = 5 * time.Second retryCall = 5 * time.Second ) @@ -59,11 +58,11 @@ type Request struct { start time.Time } -func NewHeimdallClient(urlString string) *HeimdallClient { +func NewHeimdallClient(urlString string, timeout time.Duration) *HeimdallClient { return &HeimdallClient{ urlString: urlString, client: http.Client{ - Timeout: apiHeimdallTimeout, + Timeout: timeout, }, closeCh: make(chan struct{}), } @@ -469,7 +468,7 @@ func internalFetch(ctx context.Context, client http.Client, u *url.URL) ([]byte, } func internalFetchWithTimeout(ctx context.Context, client http.Client, url *url.URL) ([]byte, error) { - ctx, cancel := context.WithTimeout(ctx, apiHeimdallTimeout) + ctx, cancel := context.WithTimeout(ctx, client.Timeout) defer cancel() // request data once diff --git a/consensus/bor/heimdall/client_test.go b/consensus/bor/heimdall/client_test.go index 0fa7665048..d2fb06df72 100644 --- a/consensus/bor/heimdall/client_test.go +++ b/consensus/bor/heimdall/client_test.go @@ -143,7 +143,7 @@ func TestFetchCheckpointFromMockHeimdall(t *testing.T) { require.NoError(t, err, "expect no error in starting mock heimdall server") // Create a new heimdall client and use same port for connection - client := NewHeimdallClient(fmt.Sprintf("http://localhost:%d", port)) + client := NewHeimdallClient(fmt.Sprintf("http://localhost:%d", port), 5*time.Second) _, err = client.FetchCheckpoint(context.Background(), -1) require.NoError(t, err, "expect no error in fetching checkpoint") @@ -194,7 +194,7 @@ func TestFetchMilestoneFromMockHeimdall(t *testing.T) { require.NoError(t, err, "expect no error in starting mock heimdall server") // Create a new heimdall client and use same port for connection - client := NewHeimdallClient(fmt.Sprintf("http://localhost:%d", port)) + client := NewHeimdallClient(fmt.Sprintf("http://localhost:%d", port), 5*time.Second) _, err = client.FetchMilestone(context.Background()) require.NoError(t, err, "expect no error in fetching milestone") @@ -250,7 +250,7 @@ func TestFetchShutdown(t *testing.T) { require.NoError(t, err, "expect no error in starting mock heimdall server") // Create a new heimdall client and use same port for connection - client := NewHeimdallClient(fmt.Sprintf("http://localhost:%d", port)) + client := NewHeimdallClient(fmt.Sprintf("http://localhost:%d", port), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) diff --git a/docs/cli/server.md b/docs/cli/server.md index 4c4c86b004..3094b18705 100644 --- a/docs/cli/server.md +++ b/docs/cli/server.md @@ -8,6 +8,8 @@ The ```bor server``` command runs the Bor client. - ```bor.heimdall```: URL of Heimdall service (default: http://localhost:1317) +- ```bor.heimdalltimeout```: Timeout of Heimdall service (default: 5s) + - ```bor.heimdallgRPC```: Address of Heimdall gRPC service - ```bor.logs```: Enables bor log retrieval (default: false) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index b49c6e6079..5905bca861 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -186,6 +186,9 @@ type Config struct { // URL to connect to Heimdall node HeimdallURL string + // timeout in heimdall requests + HeimdallTimeout time.Duration + // No heimdall service WithoutHeimdall bool @@ -242,7 +245,7 @@ func CreateConsensusEngine(chainConfig *params.ChainConfig, ethConfig *Config, d } else if ethConfig.HeimdallgRPCAddress != "" { heimdallClient = heimdallgrpc.NewHeimdallGRPCClient(ethConfig.HeimdallgRPCAddress) } else { - heimdallClient = heimdall.NewHeimdallClient(ethConfig.HeimdallURL) + heimdallClient = heimdall.NewHeimdallClient(ethConfig.HeimdallURL, ethConfig.HeimdallTimeout) } return bor.New(chainConfig, db, blockchainAPI, spanner, heimdallClient, genesisContractsClient, false), nil diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 082e093578..ebfc37b86d 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -26,6 +26,9 @@ func (c Config) MarshalTOML() (interface{}, error) { NoPruning bool NoPrefetch bool TxLookupLimit uint64 `toml:",omitempty"` + TransactionHistory uint64 `toml:",omitempty"` + StateHistory uint64 `toml:",omitempty"` + StateScheme string `toml:",omitempty"` RequiredBlocks map[uint64]common.Hash `toml:"-"` LightServ int `toml:",omitempty"` LightIngress int `toml:",omitempty"` @@ -53,9 +56,9 @@ func (c Config) MarshalTOML() (interface{}, error) { BlobPool blobpool.Config GPO gasprice.Config EnablePreimageRecording bool - EnableWitnessCollection bool `toml:"-"` - VMTrace string - VMTraceJsonConfig string + EnableWitnessCollection bool `toml:"-"` + VMTrace string + VMTraceJsonConfig string DocRoot string `toml:"-"` RPCGasCap uint64 RPCReturnDataLimit uint64 @@ -63,6 +66,7 @@ func (c Config) MarshalTOML() (interface{}, error) { RPCTxFeeCap float64 OverrideCancun *big.Int `toml:",omitempty"` HeimdallURL string + HeimdallTimeout time.Duration WithoutHeimdall bool HeimdallgRPCAddress string RunHeimdall bool @@ -72,6 +76,7 @@ func (c Config) MarshalTOML() (interface{}, error) { ParallelEVM core.ParallelEVMConfig `toml:",omitempty"` DevFakeAuthor bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"` OverrideVerkle *big.Int `toml:",omitempty"` + EnableBlockTracking bool } var enc Config enc.Genesis = c.Genesis @@ -82,6 +87,9 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.NoPruning = c.NoPruning enc.NoPrefetch = c.NoPrefetch enc.TxLookupLimit = c.TxLookupLimit + enc.TransactionHistory = c.TransactionHistory + enc.StateHistory = c.StateHistory + enc.StateScheme = c.StateScheme enc.RequiredBlocks = c.RequiredBlocks enc.LightServ = c.LightServ enc.LightIngress = c.LightIngress @@ -119,6 +127,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.RPCTxFeeCap = c.RPCTxFeeCap enc.OverrideCancun = c.OverrideCancun enc.HeimdallURL = c.HeimdallURL + enc.HeimdallTimeout = c.HeimdallTimeout enc.WithoutHeimdall = c.WithoutHeimdall enc.HeimdallgRPCAddress = c.HeimdallgRPCAddress enc.RunHeimdall = c.RunHeimdall @@ -128,6 +137,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.ParallelEVM = c.ParallelEVM enc.DevFakeAuthor = c.DevFakeAuthor enc.OverrideVerkle = c.OverrideVerkle + enc.EnableBlockTracking = c.EnableBlockTracking return &enc, nil } @@ -142,6 +152,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { NoPruning *bool NoPrefetch *bool TxLookupLimit *uint64 `toml:",omitempty"` + TransactionHistory *uint64 `toml:",omitempty"` + StateHistory *uint64 `toml:",omitempty"` + StateScheme *string `toml:",omitempty"` RequiredBlocks map[uint64]common.Hash `toml:"-"` LightServ *int `toml:",omitempty"` LightIngress *int `toml:",omitempty"` @@ -169,9 +182,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { BlobPool *blobpool.Config GPO *gasprice.Config EnablePreimageRecording *bool - EnableWitnessCollection *bool `toml:"-"` - VMTrace *string - VMTraceJsonConfig *string + EnableWitnessCollection *bool `toml:"-"` + VMTrace *string + VMTraceJsonConfig *string DocRoot *string `toml:"-"` RPCGasCap *uint64 RPCReturnDataLimit *uint64 @@ -179,6 +192,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { RPCTxFeeCap *float64 OverrideCancun *big.Int `toml:",omitempty"` HeimdallURL *string + HeimdallTimeout *time.Duration WithoutHeimdall *bool HeimdallgRPCAddress *string RunHeimdall *bool @@ -188,6 +202,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { ParallelEVM *core.ParallelEVMConfig `toml:",omitempty"` DevFakeAuthor *bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"` OverrideVerkle *big.Int `toml:",omitempty"` + EnableBlockTracking *bool } var dec Config if err := unmarshal(&dec); err != nil { @@ -217,6 +232,15 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.TxLookupLimit != nil { c.TxLookupLimit = *dec.TxLookupLimit } + if dec.TransactionHistory != nil { + c.TransactionHistory = *dec.TransactionHistory + } + if dec.StateHistory != nil { + c.StateHistory = *dec.StateHistory + } + if dec.StateScheme != nil { + c.StateScheme = *dec.StateScheme + } if dec.RequiredBlocks != nil { c.RequiredBlocks = dec.RequiredBlocks } @@ -328,6 +352,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.HeimdallURL != nil { c.HeimdallURL = *dec.HeimdallURL } + if dec.HeimdallTimeout != nil { + c.HeimdallTimeout = *dec.HeimdallTimeout + } if dec.WithoutHeimdall != nil { c.WithoutHeimdall = *dec.WithoutHeimdall } @@ -355,5 +382,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverrideVerkle != nil { c.OverrideVerkle = dec.OverrideVerkle } + if dec.EnableBlockTracking != nil { + c.EnableBlockTracking = *dec.EnableBlockTracking + } return nil } diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 1f6e451dbf..ead556ffeb 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -254,6 +254,8 @@ type HeimdallConfig struct { // URL is the url of the heimdall server URL string `hcl:"url,optional" toml:"url,optional"` + Timeout time.Duration `hcl:"timeout,optional" toml:"timeout,optional"` + // Without is used to disable remote heimdall during testing Without bool `hcl:"bor.without,optional" toml:"bor.without,optional"` @@ -930,6 +932,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (* } n.HeimdallURL = c.Heimdall.URL + n.HeimdallTimeout = c.Heimdall.Timeout n.WithoutHeimdall = c.Heimdall.Without n.HeimdallgRPCAddress = c.Heimdall.GRPCAddress n.RunHeimdall = c.Heimdall.RunHeimdall diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index 25fc6ce7ba..f09bc32fa0 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -1,6 +1,8 @@ package server import ( + "time" + "github.com/ethereum/go-ethereum/internal/cli/flagset" ) @@ -167,6 +169,12 @@ func (c *Command) Flags(config *Config) *flagset.Flagset { Value: &c.cliConfig.Heimdall.URL, Default: c.cliConfig.Heimdall.URL, }) + f.DurationFlag(&flagset.DurationFlag{ + Name: "bor.heimdalltimeout", + Usage: "Timeout of Heimdall service", + Value: &c.cliConfig.Heimdall.Timeout, + Default: 5 * time.Second, + }) f.BoolFlag(&flagset.BoolFlag{ Name: "bor.withoutheimdall", Usage: "Run without Heimdall service (for testing purpose)", diff --git a/scripts/getconfig.go b/scripts/getconfig.go index 44ea9b51f3..0614065896 100644 --- a/scripts/getconfig.go +++ b/scripts/getconfig.go @@ -110,6 +110,7 @@ var nameTagMap = map[string]string{ "0-snapshot": "snapshot", "\"bor.logs\"": "bor.logs", "url": "bor.heimdall", + "timeout": "bor.heimdalltimeout", "\"bor.without\"": "bor.withoutheimdall", "grpc-address": "bor.heimdallgRPC", "\"bor.runheimdall\"": "bor.runheimdall",