From 40dbad9915561434dad539eb681834e8fd126d65 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Mon, 29 Apr 2019 23:17:57 -0700 Subject: [PATCH] pex: dial seeds when address book needs more addresses (#3603) If we are low on addresses for peering, we need to discover more peers. The previous behavior would query existing peers; however, if an existing peer does not participate in peer exchange, then our node will not discover more peers. This change consults both existing peers as well as seeds when there is a deficit in address book addresses. This allows for discovering peers though existing channels as well as via seeds if existing peers do not share addresses. --- CHANGELOG_PENDING.md | 1 + p2p/pex/pex_reactor.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index ff2ff69e3..c4441776a 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -27,3 +27,4 @@ - [p2p] \#3532 limit the number of attempts to connect to a peer in seed mode to 16 (as a result, the node will stop retrying after a 35 hours time window) - [consensus] \#2723, \#3451 and \#3317 Fix non-deterministic tests +- [pex] \#3603 Dial seeds when addrbook needs more addresses (@defunctzombie) \ No newline at end of file diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 38befe29a..b63c5f815 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -493,9 +493,10 @@ func (r *PEXReactor) ensurePeers() { } } - // If we are not connected to nor dialing anybody, fallback to dialing a seed. - if out+in+dial+len(toDial) == 0 { - r.Logger.Info("No addresses to dial nor connected peers. Falling back to seeds") + // If we are not dialing anyone and need more addresses - dial a seed + // This is done in addition to asking a peer for addresses to work-around peers not participating in PEX + if r.book.NeedMoreAddrs() && len(toDial) == 0 { + r.Logger.Info("No addresses to dial. Falling back to seeds") r.dialSeeds() } }