cmd/utils: fix bootnodes config priority (#28095)
This fixes an issue where the --bootnodes flag was overridden by the config file. --------- Co-authored-by: NathanBSC <Nathan.l@nodereal.io> Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
3d297fc2d7
commit
f6f64cc43d
@ -1032,35 +1032,45 @@ func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
|
|||||||
|
|
||||||
// setBootstrapNodes creates a list of bootstrap nodes from the command line
|
// setBootstrapNodes creates a list of bootstrap nodes from the command line
|
||||||
// flags, reverting to pre-configured ones if none have been specified.
|
// flags, reverting to pre-configured ones if none have been specified.
|
||||||
|
// Priority order for bootnodes configuration:
|
||||||
|
//
|
||||||
|
// 1. --bootnodes flag
|
||||||
|
// 2. Config file
|
||||||
|
// 3. Network preset flags (e.g. --goerli)
|
||||||
|
// 4. default to mainnet nodes
|
||||||
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
|
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
urls := params.MainnetBootnodes
|
urls := params.MainnetBootnodes
|
||||||
switch {
|
if ctx.IsSet(BootnodesFlag.Name) {
|
||||||
case ctx.IsSet(BootnodesFlag.Name):
|
|
||||||
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
|
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
|
||||||
case ctx.Bool(HoleskyFlag.Name):
|
} else {
|
||||||
urls = params.HoleskyBootnodes
|
if cfg.BootstrapNodes != nil {
|
||||||
case ctx.Bool(SepoliaFlag.Name):
|
return // Already set by config file, don't apply defaults.
|
||||||
urls = params.SepoliaBootnodes
|
}
|
||||||
case ctx.Bool(GoerliFlag.Name):
|
switch {
|
||||||
urls = params.GoerliBootnodes
|
case ctx.Bool(HoleskyFlag.Name):
|
||||||
|
urls = params.HoleskyBootnodes
|
||||||
|
case ctx.Bool(SepoliaFlag.Name):
|
||||||
|
urls = params.SepoliaBootnodes
|
||||||
|
case ctx.Bool(GoerliFlag.Name):
|
||||||
|
urls = params.GoerliBootnodes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
cfg.BootstrapNodes = mustParseBootnodes(urls)
|
||||||
|
}
|
||||||
|
|
||||||
// don't apply defaults if BootstrapNodes is already set
|
func mustParseBootnodes(urls []string) []*enode.Node {
|
||||||
if cfg.BootstrapNodes != nil {
|
nodes := make([]*enode.Node, 0, len(urls))
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg.BootstrapNodes = make([]*enode.Node, 0, len(urls))
|
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
if url != "" {
|
if url != "" {
|
||||||
node, err := enode.Parse(enode.ValidSchemes, url)
|
node, err := enode.Parse(enode.ValidSchemes, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
|
log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
|
||||||
continue
|
return nil
|
||||||
}
|
}
|
||||||
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
|
nodes = append(nodes, node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
// setBootstrapNodesV5 creates a list of bootstrap nodes from the command line
|
// setBootstrapNodesV5 creates a list of bootstrap nodes from the command line
|
||||||
|
Loading…
Reference in New Issue
Block a user