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

Fix Bootnode Again #5473

Merged
merged 10 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions tools/bootnode/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/iputils:go_default_library",
"//shared/logutil:go_default_library",
"//shared/params:go_default_library",
"//shared/version:go_default_library",
Expand Down
22 changes: 12 additions & 10 deletions tools/bootnode/bootnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/iputils"
"github.com/prysmaticlabs/prysm/shared/logutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/version"
Expand Down Expand Up @@ -155,9 +156,13 @@ func startKademliaDHT(privKey crypto.PrivKey) {
}

func createListener(ipAddr string, port int, cfg discover.Config) *discover.UDPv5 {
ipAddr, err := iputils.ExternalIPv4()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are overwriting the input value of the func. maybe it doesnt need an input ipAddr?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it

if err != nil {
log.Fatal(err)
}
ip := net.ParseIP(ipAddr)
if ip.To4() == nil {
log.Fatalf("IPV4 address not provided instead %s was provided", defaultIP)
log.Fatalf("IPV4 address not provided instead %s was provided", ipAddr)
}
udpAddr := &net.UDPAddr{
IP: ip,
Expand All @@ -167,9 +172,6 @@ func createListener(ipAddr string, port int, cfg discover.Config) *discover.UDPv
if err != nil {
log.Fatal(err)
}
if *externalIP != "" {
ip = net.ParseIP(*externalIP)
}
localNode, err := createLocalNode(cfg.PrivateKey, ip, port)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -206,6 +208,10 @@ func createLocalNode(privKey *ecdsa.PrivateKey, ipAddr net.IP, port int) (*enode
if err != nil {
return nil, errors.Wrap(err, "Could not open node's peer database")
}
external := net.ParseIP(*externalIP)
if *externalIP == "" {
external = ipAddr
}

forkID := &pb.ENRForkID{
CurrentForkDigest: []byte{0, 0, 0, 0},
Expand All @@ -218,14 +224,10 @@ func createLocalNode(privKey *ecdsa.PrivateKey, ipAddr net.IP, port int) (*enode
}

localNode := enode.NewLocalNode(db, privKey)
ipEntry := enr.IP(ipAddr)
udpEntry := enr.UDP(port)
localNode.SetFallbackIP(ipAddr)
localNode.SetFallbackUDP(port)
localNode.Set(ipEntry)
localNode.Set(udpEntry)
localNode.Set(enr.WithEntry("eth2", forkEntry))
localNode.Set(enr.WithEntry("attnets", bitfield.NewBitvector64()))
localNode.SetFallbackIP(external)
localNode.SetFallbackUDP(port)

return localNode, nil
}
Expand Down