Skip to content

Commit

Permalink
p2p/pex: consult seeds in crawlPeersRoutine (tendermint#3647)
Browse files Browse the repository at this point in the history
* p2p/pex: consult seeds in crawlPeersRoutine

This changeset alters the startup behavior for crawlPeersRoutine. Previously
the routine would crawl a random selection of peers on startup. For a
new seed node, there are no peers. As a result, new seed nodes are unable
to bootstrap themselves with a list of peers until another node with a list
of peers connects to the seed. If this node relies on the seed node for peers,
then the two will not discover more peers.

This changeset makes the startup behavior for crawlPeersRoutine connect to
any seed nodes. Upon connecting, a request for peers will be sent to the seed node
thus helping bootstrap our seed node.

* p2p/pex: Adjust error message for no peers

Co-Authored-By: Ethan Buchman <ethan@coinculture.info>
  • Loading branch information
2 people authored and brapse committed Jun 5, 2019
1 parent d48b6ce commit 1f054ee
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions p2p/pex/pex_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (r *PEXReactor) OnStart() error {
if err != nil {
return err
} else if numOnline == 0 && r.book.Empty() {
return errors.New("Address book is empty, and could not connect to any seed nodes")
return errors.New("Address book is empty and couldn't resolve any seed nodes")
}

r.seedAddrs = seedAddrs
Expand Down Expand Up @@ -573,7 +573,7 @@ func (r *PEXReactor) checkSeeds() (numOnline int, netAddrs []*p2p.NetAddress, er
return 0, nil, errors.Wrap(e, "seed node configuration has error")
}
}
return
return numOnline, netAddrs, nil
}

// randomly dial seeds until we connect to one or exhaust them
Expand Down Expand Up @@ -608,8 +608,13 @@ func (r *PEXReactor) AttemptsToDial(addr *p2p.NetAddress) int {
// Seed/Crawler Mode causes this node to quickly disconnect
// from peers, except other seed nodes.
func (r *PEXReactor) crawlPeersRoutine() {
// Do an initial crawl
r.crawlPeers(r.book.GetSelection())
// If we have any seed nodes, consult them first
if len(r.seedAddrs) > 0 {
r.dialSeeds()
} else {
// Do an initial crawl
r.crawlPeers(r.book.GetSelection())
}

// Fire periodically
ticker := time.NewTicker(crawlPeerPeriod)
Expand Down

0 comments on commit 1f054ee

Please sign in to comment.