Allow overwriting of default bootstrap node (#3616)

* Allow overwriting of default bootstrap node

* Update shared/cmd/flags.go

Co-Authored-By: Nishant Das <nish1993@hotmail.com>

* Provide warning at more suitable time
This commit is contained in:
Jim McDonald 2019-09-27 13:05:16 +01:00 committed by Nishant Das
parent f681bc6867
commit b089cdd216
3 changed files with 12 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import (
"os/signal"
"path"
"path/filepath"
"strings"
"sync"
"syscall"
@ -215,7 +216,7 @@ func (b *BeaconNode) startDB(ctx *cli.Context) error {
func (b *BeaconNode) registerP2P(ctx *cli.Context) error {
// Bootnode ENR may be a filepath to an ENR file.
bootnodeAddrs := sliceutil.SplitCommaSeparated(ctx.GlobalStringSlice(cmd.BootstrapNode.Name))
bootnodeAddrs := strings.Split(ctx.GlobalString(cmd.BootstrapNode.Name), ",")
for i, addr := range bootnodeAddrs {
if filepath.Ext(addr) == ".enr" {
b, err := ioutil.ReadFile(addr)

View File

@ -100,6 +100,10 @@ func startDHTDiscovery(host core.Host, bootstrapAddr string) error {
func parseBootStrapAddrs(addrs []string) (discv5Nodes []string, kadDHTNodes []string) {
for _, addr := range addrs {
if addr == "" {
// Ignore empty entries
continue
}
_, err := enode.Parse(enode.ValidSchemes, addr)
if err == nil {
discv5Nodes = append(discv5Nodes, addr)
@ -112,6 +116,9 @@ func parseBootStrapAddrs(addrs []string) (discv5Nodes []string, kadDHTNodes []st
}
log.Errorf("Invalid bootstrap address of %s provided", addr)
}
if len(discv5Nodes) == 0 && len(kadDHTNodes) == 0 {
log.Warn("No bootstrap addresses supplied")
}
return discv5Nodes, kadDHTNodes
}

View File

@ -64,10 +64,10 @@ var (
Usage: "Connect with this peer. This flag may be used multiple times.",
}
// BootstrapNode tells the beacon node which bootstrap node to connect to
BootstrapNode = cli.StringSliceFlag{
BootstrapNode = cli.StringFlag{
Name: "bootstrap-node",
Usage: "The address of bootstrap node. Beacon node will connect for peer discovery via DHT",
Value: &cli.StringSlice{"/dns4/prylabs.net/tcp/30001/p2p/16Uiu2HAm7Qwe19vz9WzD2Mxn7fXd1vgHHp4iccuyq7TxwRXoAGfc"},
Usage: "The address of bootstrap node. Beacon node will connect for peer discovery via DHT. Multiple nodes can be separated with a comma",
Value: "/dns4/prylabs.net/tcp/30001/p2p/16Uiu2HAm7Qwe19vz9WzD2Mxn7fXd1vgHHp4iccuyq7TxwRXoAGfc",
}
// RelayNode tells the beacon node which relay node to connect to.
RelayNode = cli.StringFlag{