From 000a83bc041e9f1c49efd5e3c5db89f80ba6b371 Mon Sep 17 00:00:00 2001 From: Brian KimJohnson Date: Fri, 5 Jan 2018 23:37:31 -0500 Subject: [PATCH] server: add bootstrap peers to persistent peers for conn retry Peers are treated as transient by default. When a peer is disconnected, no attempt is made to reconnect. However, if we have a channel open with a peer that peer will be added as persistent. If a persistent peer becomes disconnected then we will attempt to reconnect. This behavior implies that a fresh node - those without any channels - will fall off the network over time as remote nodes restart or due to connectivity changes. This change marks bootstrap peers as persistent and ensures that the node remains connected to those specific peers over time. This does not keep the node connected in the case that all bootstrap peers are down. Fixes #451. --- server.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server.go b/server.go index 1239a4b9..8179264b 100644 --- a/server.go +++ b/server.go @@ -570,6 +570,13 @@ func (s *server) peerBootstrapper(numTargetPeers uint32, return } + // Add bootstrapped peer as persistent to maintain + // connectivity even if we have no open channels. + targetPub := string(conn.RemotePub().SerializeCompressed()) + s.mu.Lock() + s.persistentPeers[targetPub] = struct{}{} + s.mu.Unlock() + s.OutboundPeerConnected(nil, conn) }(addr) } @@ -673,6 +680,14 @@ func (s *server) peerBootstrapper(numTargetPeers uint32, atomic.AddUint32(&epochErrors, 1) return } + + // Add bootstrapped peer as persistent to maintain + // connectivity even if we have no open channels. + targetPub := string(conn.RemotePub().SerializeCompressed()) + s.mu.Lock() + s.persistentPeers[targetPub] = struct{}{} + s.mu.Unlock() + s.OutboundPeerConnected(nil, conn) }(addr) }