From b089cdd2161a18f1fc127a7f3169bd1fd6f90e60 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Fri, 27 Sep 2019 13:05:16 +0100 Subject: [PATCH] Allow overwriting of default bootstrap node (#3616) * Allow overwriting of default bootstrap node * Update shared/cmd/flags.go Co-Authored-By: Nishant Das * Provide warning at more suitable time --- beacon-chain/node/node.go | 3 ++- beacon-chain/p2p/discovery.go | 7 +++++++ shared/cmd/flags.go | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index 52ea11803..51d279ea8 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -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) diff --git a/beacon-chain/p2p/discovery.go b/beacon-chain/p2p/discovery.go index 37f481afe..88265dd57 100644 --- a/beacon-chain/p2p/discovery.go +++ b/beacon-chain/p2p/discovery.go @@ -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 } diff --git a/shared/cmd/flags.go b/shared/cmd/flags.go index 86a9fce4a..961783e72 100644 --- a/shared/cmd/flags.go +++ b/shared/cmd/flags.go @@ -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{