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 parsing BootstrapNodes from BootnodesFlag #28095

Merged
merged 3 commits into from Sep 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions cmd/utils/flags.go
Expand Up @@ -1042,11 +1042,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
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
case cfg.BootstrapNodesV5 != nil:
return // already set, don't apply defaults.
Copy link
Member

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)
		}
	}
}

Copy link
Contributor Author

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.

}

cfg.BootstrapNodes = make([]*enode.Node, 0, len(urls))
Expand Down