including heimdall timeout on config

This commit is contained in:
Lucca Martins 2025-02-19 17:15:43 -03:00
parent f4f30d9fa3
commit e2f114b19b
No known key found for this signature in database
GPG key ID: DC3D7F76BDAE23BF
10 changed files with 71 additions and 14 deletions

View file

@ -2,6 +2,7 @@ package utils
import ( import (
"os" "os"
"time"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -22,6 +23,13 @@ var (
Value: "http://localhost:1317", 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 no heimdall (for testing purpose)
WithoutHeimdallFlag = &cli.BoolFlag{ WithoutHeimdallFlag = &cli.BoolFlag{
Name: "bor.withoutheimdall", Name: "bor.withoutheimdall",
@ -56,6 +64,7 @@ var (
// BorFlags all bor related flags // BorFlags all bor related flags
BorFlags = []cli.Flag{ BorFlags = []cli.Flag{
HeimdallURLFlag, HeimdallURLFlag,
HeimdallTimeoutFlag,
WithoutHeimdallFlag, WithoutHeimdallFlag,
HeimdallgRPCAddressFlag, HeimdallgRPCAddressFlag,
RunHeimdallFlag, RunHeimdallFlag,
@ -67,6 +76,7 @@ var (
// SetBorConfig sets bor config // SetBorConfig sets bor config
func SetBorConfig(ctx *cli.Context, cfg *eth.Config) { func SetBorConfig(ctx *cli.Context, cfg *eth.Config) {
cfg.HeimdallURL = ctx.String(HeimdallURLFlag.Name) cfg.HeimdallURL = ctx.String(HeimdallURLFlag.Name)
cfg.HeimdallTimeout = ctx.Duration(HeimdallTimeoutFlag.Name)
cfg.WithoutHeimdall = ctx.Bool(WithoutHeimdallFlag.Name) cfg.WithoutHeimdall = ctx.Bool(WithoutHeimdallFlag.Name)
cfg.HeimdallgRPCAddress = ctx.String(HeimdallgRPCAddressFlag.Name) cfg.HeimdallgRPCAddress = ctx.String(HeimdallgRPCAddressFlag.Name)
cfg.RunHeimdall = ctx.Bool(RunHeimdallFlag.Name) cfg.RunHeimdall = ctx.Bool(RunHeimdallFlag.Name)

View file

@ -2314,6 +2314,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
configs := &ethconfig.Config{ configs := &ethconfig.Config{
Genesis: gspec, Genesis: gspec,
HeimdallURL: ctx.String(HeimdallURLFlag.Name), HeimdallURL: ctx.String(HeimdallURLFlag.Name),
HeimdallTimeout: ctx.Duration(HeimdallTimeoutFlag.Name),
WithoutHeimdall: ctx.Bool(WithoutHeimdallFlag.Name), WithoutHeimdall: ctx.Bool(WithoutHeimdallFlag.Name),
HeimdallgRPCAddress: ctx.String(HeimdallgRPCAddressFlag.Name), HeimdallgRPCAddress: ctx.String(HeimdallgRPCAddressFlag.Name),
RunHeimdall: ctx.Bool(RunHeimdallArgsFlag.Name), RunHeimdall: ctx.Bool(RunHeimdallArgsFlag.Name),

View file

@ -33,7 +33,6 @@ var (
const ( const (
heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB
stateFetchLimit = 50 stateFetchLimit = 50
apiHeimdallTimeout = 5 * time.Second
retryCall = 5 * time.Second retryCall = 5 * time.Second
) )
@ -59,11 +58,13 @@ type Request struct {
start time.Time 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{ return &HeimdallClient{
urlString: urlString, urlString: urlString,
client: http.Client{ client: http.Client{
Timeout: apiHeimdallTimeout, Timeout: timeout,
}, },
closeCh: make(chan struct{}), 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) { 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() defer cancel()
// request data once // request data once

View file

@ -143,7 +143,7 @@ func TestFetchCheckpointFromMockHeimdall(t *testing.T) {
require.NoError(t, err, "expect no error in starting mock heimdall server") require.NoError(t, err, "expect no error in starting mock heimdall server")
// Create a new heimdall client and use same port for connection // 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) _, err = client.FetchCheckpoint(context.Background(), -1)
require.NoError(t, err, "expect no error in fetching checkpoint") 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") require.NoError(t, err, "expect no error in starting mock heimdall server")
// Create a new heimdall client and use same port for connection // 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()) _, err = client.FetchMilestone(context.Background())
require.NoError(t, err, "expect no error in fetching milestone") 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") require.NoError(t, err, "expect no error in starting mock heimdall server")
// Create a new heimdall client and use same port for connection // 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) ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)

View file

@ -8,6 +8,8 @@ The ```bor server``` command runs the Bor client.
- ```bor.heimdall```: URL of Heimdall service (default: http://localhost:1317) - ```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.heimdallgRPC```: Address of Heimdall gRPC service
- ```bor.logs```: Enables bor log retrieval (default: false) - ```bor.logs```: Enables bor log retrieval (default: false)

View file

@ -186,6 +186,9 @@ type Config struct {
// URL to connect to Heimdall node // URL to connect to Heimdall node
HeimdallURL string HeimdallURL string
// timeout in heimdall requests
HeimdallTimeout time.Duration
// No heimdall service // No heimdall service
WithoutHeimdall bool WithoutHeimdall bool
@ -242,7 +245,7 @@ func CreateConsensusEngine(chainConfig *params.ChainConfig, ethConfig *Config, d
} else if ethConfig.HeimdallgRPCAddress != "" { } else if ethConfig.HeimdallgRPCAddress != "" {
heimdallClient = heimdallgrpc.NewHeimdallGRPCClient(ethConfig.HeimdallgRPCAddress) heimdallClient = heimdallgrpc.NewHeimdallGRPCClient(ethConfig.HeimdallgRPCAddress)
} else { } else {
heimdallClient = heimdall.NewHeimdallClient(ethConfig.HeimdallURL) heimdallClient = heimdall.NewHeimdallClient(ethConfig.HeimdallURL, ethConfig.HeimdallTimeout)
} }
return bor.New(chainConfig, db, blockchainAPI, spanner, heimdallClient, genesisContractsClient, false), nil return bor.New(chainConfig, db, blockchainAPI, spanner, heimdallClient, genesisContractsClient, false), nil

View file

@ -26,6 +26,9 @@ func (c Config) MarshalTOML() (interface{}, error) {
NoPruning bool NoPruning bool
NoPrefetch bool NoPrefetch bool
TxLookupLimit uint64 `toml:",omitempty"` TxLookupLimit uint64 `toml:",omitempty"`
TransactionHistory uint64 `toml:",omitempty"`
StateHistory uint64 `toml:",omitempty"`
StateScheme string `toml:",omitempty"`
RequiredBlocks map[uint64]common.Hash `toml:"-"` RequiredBlocks map[uint64]common.Hash `toml:"-"`
LightServ int `toml:",omitempty"` LightServ int `toml:",omitempty"`
LightIngress int `toml:",omitempty"` LightIngress int `toml:",omitempty"`
@ -63,6 +66,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
RPCTxFeeCap float64 RPCTxFeeCap float64
OverrideCancun *big.Int `toml:",omitempty"` OverrideCancun *big.Int `toml:",omitempty"`
HeimdallURL string HeimdallURL string
HeimdallTimeout time.Duration
WithoutHeimdall bool WithoutHeimdall bool
HeimdallgRPCAddress string HeimdallgRPCAddress string
RunHeimdall bool RunHeimdall bool
@ -72,6 +76,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
ParallelEVM core.ParallelEVMConfig `toml:",omitempty"` ParallelEVM core.ParallelEVMConfig `toml:",omitempty"`
DevFakeAuthor bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"` DevFakeAuthor bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"`
OverrideVerkle *big.Int `toml:",omitempty"` OverrideVerkle *big.Int `toml:",omitempty"`
EnableBlockTracking bool
} }
var enc Config var enc Config
enc.Genesis = c.Genesis enc.Genesis = c.Genesis
@ -82,6 +87,9 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.NoPruning = c.NoPruning enc.NoPruning = c.NoPruning
enc.NoPrefetch = c.NoPrefetch enc.NoPrefetch = c.NoPrefetch
enc.TxLookupLimit = c.TxLookupLimit enc.TxLookupLimit = c.TxLookupLimit
enc.TransactionHistory = c.TransactionHistory
enc.StateHistory = c.StateHistory
enc.StateScheme = c.StateScheme
enc.RequiredBlocks = c.RequiredBlocks enc.RequiredBlocks = c.RequiredBlocks
enc.LightServ = c.LightServ enc.LightServ = c.LightServ
enc.LightIngress = c.LightIngress enc.LightIngress = c.LightIngress
@ -119,6 +127,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.RPCTxFeeCap = c.RPCTxFeeCap enc.RPCTxFeeCap = c.RPCTxFeeCap
enc.OverrideCancun = c.OverrideCancun enc.OverrideCancun = c.OverrideCancun
enc.HeimdallURL = c.HeimdallURL enc.HeimdallURL = c.HeimdallURL
enc.HeimdallTimeout = c.HeimdallTimeout
enc.WithoutHeimdall = c.WithoutHeimdall enc.WithoutHeimdall = c.WithoutHeimdall
enc.HeimdallgRPCAddress = c.HeimdallgRPCAddress enc.HeimdallgRPCAddress = c.HeimdallgRPCAddress
enc.RunHeimdall = c.RunHeimdall enc.RunHeimdall = c.RunHeimdall
@ -128,6 +137,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.ParallelEVM = c.ParallelEVM enc.ParallelEVM = c.ParallelEVM
enc.DevFakeAuthor = c.DevFakeAuthor enc.DevFakeAuthor = c.DevFakeAuthor
enc.OverrideVerkle = c.OverrideVerkle enc.OverrideVerkle = c.OverrideVerkle
enc.EnableBlockTracking = c.EnableBlockTracking
return &enc, nil return &enc, nil
} }
@ -142,6 +152,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
NoPruning *bool NoPruning *bool
NoPrefetch *bool NoPrefetch *bool
TxLookupLimit *uint64 `toml:",omitempty"` TxLookupLimit *uint64 `toml:",omitempty"`
TransactionHistory *uint64 `toml:",omitempty"`
StateHistory *uint64 `toml:",omitempty"`
StateScheme *string `toml:",omitempty"`
RequiredBlocks map[uint64]common.Hash `toml:"-"` RequiredBlocks map[uint64]common.Hash `toml:"-"`
LightServ *int `toml:",omitempty"` LightServ *int `toml:",omitempty"`
LightIngress *int `toml:",omitempty"` LightIngress *int `toml:",omitempty"`
@ -179,6 +192,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
RPCTxFeeCap *float64 RPCTxFeeCap *float64
OverrideCancun *big.Int `toml:",omitempty"` OverrideCancun *big.Int `toml:",omitempty"`
HeimdallURL *string HeimdallURL *string
HeimdallTimeout *time.Duration
WithoutHeimdall *bool WithoutHeimdall *bool
HeimdallgRPCAddress *string HeimdallgRPCAddress *string
RunHeimdall *bool RunHeimdall *bool
@ -188,6 +202,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
ParallelEVM *core.ParallelEVMConfig `toml:",omitempty"` ParallelEVM *core.ParallelEVMConfig `toml:",omitempty"`
DevFakeAuthor *bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"` DevFakeAuthor *bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"`
OverrideVerkle *big.Int `toml:",omitempty"` OverrideVerkle *big.Int `toml:",omitempty"`
EnableBlockTracking *bool
} }
var dec Config var dec Config
if err := unmarshal(&dec); err != nil { if err := unmarshal(&dec); err != nil {
@ -217,6 +232,15 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.TxLookupLimit != nil { if dec.TxLookupLimit != nil {
c.TxLookupLimit = *dec.TxLookupLimit 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 { if dec.RequiredBlocks != nil {
c.RequiredBlocks = dec.RequiredBlocks c.RequiredBlocks = dec.RequiredBlocks
} }
@ -328,6 +352,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.HeimdallURL != nil { if dec.HeimdallURL != nil {
c.HeimdallURL = *dec.HeimdallURL c.HeimdallURL = *dec.HeimdallURL
} }
if dec.HeimdallTimeout != nil {
c.HeimdallTimeout = *dec.HeimdallTimeout
}
if dec.WithoutHeimdall != nil { if dec.WithoutHeimdall != nil {
c.WithoutHeimdall = *dec.WithoutHeimdall c.WithoutHeimdall = *dec.WithoutHeimdall
} }
@ -355,5 +382,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.OverrideVerkle != nil { if dec.OverrideVerkle != nil {
c.OverrideVerkle = dec.OverrideVerkle c.OverrideVerkle = dec.OverrideVerkle
} }
if dec.EnableBlockTracking != nil {
c.EnableBlockTracking = *dec.EnableBlockTracking
}
return nil return nil
} }

View file

@ -254,6 +254,8 @@ type HeimdallConfig struct {
// URL is the url of the heimdall server // URL is the url of the heimdall server
URL string `hcl:"url,optional" toml:"url,optional"` 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 is used to disable remote heimdall during testing
Without bool `hcl:"bor.without,optional" toml:"bor.without,optional"` 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.HeimdallURL = c.Heimdall.URL
n.HeimdallTimeout = c.Heimdall.Timeout
n.WithoutHeimdall = c.Heimdall.Without n.WithoutHeimdall = c.Heimdall.Without
n.HeimdallgRPCAddress = c.Heimdall.GRPCAddress n.HeimdallgRPCAddress = c.Heimdall.GRPCAddress
n.RunHeimdall = c.Heimdall.RunHeimdall n.RunHeimdall = c.Heimdall.RunHeimdall

View file

@ -167,6 +167,12 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
Value: &c.cliConfig.Heimdall.URL, Value: &c.cliConfig.Heimdall.URL,
Default: 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{ f.BoolFlag(&flagset.BoolFlag{
Name: "bor.withoutheimdall", Name: "bor.withoutheimdall",
Usage: "Run without Heimdall service (for testing purpose)", Usage: "Run without Heimdall service (for testing purpose)",

View file

@ -110,6 +110,7 @@ var nameTagMap = map[string]string{
"0-snapshot": "snapshot", "0-snapshot": "snapshot",
"\"bor.logs\"": "bor.logs", "\"bor.logs\"": "bor.logs",
"url": "bor.heimdall", "url": "bor.heimdall",
"timeout": "bor.heimdalltimeout",
"\"bor.without\"": "bor.withoutheimdall", "\"bor.without\"": "bor.withoutheimdall",
"grpc-address": "bor.heimdallgRPC", "grpc-address": "bor.heimdallgRPC",
"\"bor.runheimdall\"": "bor.runheimdall", "\"bor.runheimdall\"": "bor.runheimdall",