-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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 parsing BootstrapNodes from BootnodesFlag #28095
Conversation
cmd/utils/flags.go
Outdated
if cfg.BootstrapNodes != nil { | ||
return | ||
case cfg.BootstrapNodesV5 != nil: | ||
return // already set, don't apply defaults. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was introduced in this PR #25174, I think this PR is wrong is the first place.
But your fix is also not correct, it will reset the bootstrap nodes in the config file. I will suggest this approach.
// resolveBootstrapNodes resolves the URLs for configuring the bootstrap
// nodes. If the bootstrap nodes are already configured in the configuration
// file, they will only be overridden if the command line flag is specified.
func resolveBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) []string {
if cfg.BootstrapNodes != nil {
return SplitAndTrim(ctx.String(BootnodesFlag.Name))
}
urls := params.MainnetBootnodes
switch {
case ctx.IsSet(BootnodesFlag.Name):
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
case ctx.Bool(HoleskyFlag.Name):
urls = params.HoleskyBootnodes
case ctx.Bool(SepoliaFlag.Name):
urls = params.SepoliaBootnodes
case ctx.Bool(GoerliFlag.Name):
urls = params.GoerliBootnodes
}
return urls
}
// setBootstrapNodes creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls := resolveBootstrapNodes(ctx, cfg)
if len(urls) == 0 {
return
}
cfg.BootstrapNodes = 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
}
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, I'm agree with your approach.
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 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 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 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 reverts commit 877c5be.
This reverts commit 877c5be.
bug description
conditions
geth
with flag BootnodesFlagresult
bootnode in BootnodesFlag is ignored
expected hehavior
reset the bootnode from BootnodesFlag