mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
including heimdall timeout on config
This commit is contained in:
parent
f4f30d9fa3
commit
e2f114b19b
10 changed files with 71 additions and 14 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)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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,13 @@ type Request struct {
|
|||
start time.Time
|
||||
}
|
||||
|
||||
func NewHeimdallClient(urlString string) *HeimdallClient {
|
||||
func NewHeimdallClient(urlString string, timeout time.Duration) *HeimdallClient {
|
||||
// REMOVE BEFORE PR
|
||||
log.Info("############### timeout set on heimdall client", "valueSetByConfig", timeout)
|
||||
return &HeimdallClient{
|
||||
urlString: urlString,
|
||||
client: http.Client{
|
||||
Timeout: apiHeimdallTimeout,
|
||||
Timeout: timeout,
|
||||
},
|
||||
closeCh: make(chan struct{}),
|
||||
}
|
||||
|
|
@ -469,7 +470,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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 of Heimdall service",
|
||||
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