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

Discovery Fixes #5050

Merged
merged 16 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
28 changes: 9 additions & 19 deletions beacon-chain/p2p/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (

var _ = shared.Service(&Service{})

var pollingPeriod = 1 * time.Second
// check local table every 30 seconds for newly added peers.
var pollingPeriod = 30 * time.Second
Copy link
Member

Choose a reason for hiding this comment

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

is this formal enough to be defined in beacon's config.go?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, most of these params are only useful in the p2p package. This is just a baseline on how often to poll our local table for new peers. I think they are fine living here in this package.


const prysmProtocolPrefix = "/prysm/0.0.0"

Expand Down Expand Up @@ -158,7 +159,7 @@ func (s *Service) Start() {
s.startupErr = err
return
}
err = s.addBootNodesToExclusionList()
err = s.connectToBootnodes()
if err != nil {
log.WithError(err).Error("Could not add bootnode to the exclusion list")
s.startupErr = err
Expand Down Expand Up @@ -293,12 +294,8 @@ func (s *Service) Peers() *peers.Status {

// listen for new nodes watches for new nodes in the network and adds them to the peerstore.
func (s *Service) listenForNewNodes() {
bootNode, err := enode.Parse(enode.ValidSchemes, s.cfg.Discv5BootStrapAddr[0])
if err != nil {
log.Fatal(err)
}
runutil.RunEvery(s.ctx, pollingPeriod, func() {
nodes := s.dv5Listener.Lookup(bootNode.ID())
nodes := s.dv5Listener.LookupRandom()
multiAddresses := convertToMultiAddr(nodes)
s.connectWithAllPeers(multiAddresses)
})
Expand Down Expand Up @@ -327,24 +324,17 @@ func (s *Service) connectWithAllPeers(multiAddrs []ma.Multiaddr) {
}
}

func (s *Service) addBootNodesToExclusionList() error {
func (s *Service) connectToBootnodes() error {
nodes := make([]*enode.Node, 0, len(s.cfg.Discv5BootStrapAddr))
for _, addr := range s.cfg.Discv5BootStrapAddr {
bootNode, err := enode.Parse(enode.ValidSchemes, addr)
if err != nil {
return err
}
multAddr, err := convertToSingleMultiAddr(bootNode)
if err != nil {
return err
}
addrInfo, err := peer.AddrInfoFromP2pAddr(multAddr)
if err != nil {
return err
}
// bootnode is never dialled, so ttl is tentatively 1 year
s.exclusionList.Set(addrInfo.ID.String(), true, 1)
nodes = append(nodes, bootNode)
}

multiAddresses := convertToMultiAddr(nodes)
s.connectWithAllPeers(multiAddresses)
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions beacon-chain/p2p/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ func TestListenForNewNodes(t *testing.T) {
bootListener := createListener(ipAddr, pkey, cfg)
defer bootListener.Close()

// use shorter period for testing
terencechain marked this conversation as resolved.
Show resolved Hide resolved
currentPeriod := pollingPeriod
pollingPeriod = 2 * time.Second
defer func() {
pollingPeriod = currentPeriod
}()

bootNode := bootListener.Self()

cfg = &Config{
Expand Down