Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/utils: fix bootnodes config priority (#28095) #670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,36 +1176,51 @@ func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {

// setBootstrapNodes creates a list of bootstrap nodes from the command line
// 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) {
urls := params.RoninMainnetBootnodes
switch {
case ctx.IsSet(BootnodesFlag.Name):
if ctx.IsSet(BootnodesFlag.Name) {
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
case ctx.Bool(MainnetFlag.Name):
urls = params.EtherumMainnetBootnodes
case ctx.Bool(RopstenFlag.Name):
urls = params.RopstenBootnodes
case ctx.Bool(SepoliaFlag.Name):
urls = params.SepoliaBootnodes
case ctx.Bool(RinkebyFlag.Name):
urls = params.RinkebyBootnodes
case ctx.Bool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
} else {
if cfg.BootstrapNodes != nil {
return // Already set by config file, don't apply defaults.
}

switch {
case ctx.IsSet(BootnodesFlag.Name):
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
case ctx.Bool(SepoliaFlag.Name):
urls = params.SepoliaBootnodes
case ctx.Bool(GoerliFlag.Name):
urls = params.GoerliBootnodes
}

// don't apply defaults if BootstrapNodes is already set
if cfg.BootstrapNodes != nil {
return
}
cfg.BootstrapNodes = mustParseBootnodes(urls)
}
}

cfg.BootstrapNodes = make([]*enode.Node, 0, len(urls))
func mustParseBootnodes(urls []string) []*enode.Node {
nodes := make([]*enode.Node, 0, len(urls))
for _, url := range urls {
if url != "" {
node, err := enode.Parse(enode.ValidSchemes, url)
if err != nil {
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
Expand Down
Loading