mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
Merge pull request #1457 from maticnetwork/lmartins/include-heimdal-timeout
Include Heimdall Timeout
This commit is contained in:
commit
63e6ea293b
10 changed files with 49 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -2284,6 +2284,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),
|
||||
|
|
|
|||
|
|
@ -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{}),
|
||||
}
|
||||
|
|
@ -294,7 +293,13 @@ func FetchWithRetry[T any](ctx context.Context, client http.Client, url *url.URL
|
|||
log.Warn("an error while trying fetching from Heimdall", "path", url.Path, "attempt", attempt, "error", err)
|
||||
|
||||
// create a new ticker for retrying the request
|
||||
ticker := time.NewTicker(retryCall)
|
||||
var ticker *time.Ticker
|
||||
if client.Timeout != 0 {
|
||||
ticker = time.NewTicker(client.Timeout)
|
||||
} else {
|
||||
// only reach here when HeimdallClient is HeimdallGRPCClient or HeimdallAppClient
|
||||
ticker = time.NewTicker(retryCall)
|
||||
}
|
||||
defer ticker.Stop()
|
||||
|
||||
const logEach = 5
|
||||
|
|
@ -469,7 +474,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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -176,6 +176,9 @@ type Config struct {
|
|||
// URL to connect to Heimdall node
|
||||
HeimdallURL string
|
||||
|
||||
// timeout in heimdall requests
|
||||
HeimdallTimeout time.Duration
|
||||
|
||||
// No heimdall service
|
||||
WithoutHeimdall bool
|
||||
|
||||
|
|
@ -232,7 +235,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
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||
BlobPool blobpool.Config
|
||||
GPO gasprice.Config
|
||||
EnablePreimageRecording bool
|
||||
EnableWitnessCollection bool `toml:"-"`
|
||||
VMTrace string
|
||||
VMTraceJsonConfig string
|
||||
DocRoot string `toml:"-"`
|
||||
|
|
@ -59,6 +60,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
|
||||
|
|
@ -112,6 +114,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
|
||||
|
|
@ -160,6 +163,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
BlobPool *blobpool.Config
|
||||
GPO *gasprice.Config
|
||||
EnablePreimageRecording *bool
|
||||
EnableWitnessCollection *bool `toml:"-"`
|
||||
VMTrace *string
|
||||
VMTraceJsonConfig *string
|
||||
DocRoot *string `toml:"-"`
|
||||
|
|
@ -169,6 +173,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
|
||||
|
|
@ -307,6 +312,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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
||||
|
|
@ -644,6 +646,7 @@ func DefaultConfig() *Config {
|
|||
},
|
||||
Heimdall: &HeimdallConfig{
|
||||
URL: "http://localhost:1317",
|
||||
Timeout: 5 * time.Second,
|
||||
Without: false,
|
||||
GRPCAddress: "",
|
||||
},
|
||||
|
|
@ -930,6 +933,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
|
||||
|
|
|
|||
|
|
@ -167,6 +167,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 period for bor's outgoing requests to heimdall",
|
||||
Value: &c.cliConfig.Heimdall.Timeout,
|
||||
Default: c.cliConfig.Heimdall.Timeout,
|
||||
})
|
||||
f.BoolFlag(&flagset.BoolFlag{
|
||||
Name: "bor.withoutheimdall",
|
||||
Usage: "Run without Heimdall service (for testing purpose)",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue