From 2a3b52535e7b46350ccf7b29fc0ef87e43641469 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 17 Aug 2018 09:26:54 +0200 Subject: [PATCH] autopilot: check if already connected before returning error This commit fixes a small bug that could cause us to disconnect an already connected peer if no addresses where provided to the ConnectPeer method. Now we instead first check if we are already connected, and return early. --- pilot.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pilot.go b/pilot.go index 86093a6f..c77237a8 100644 --- a/pilot.go +++ b/pilot.go @@ -109,12 +109,6 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error) Graph: autopilot.ChannelGraphFromDatabase(svr.chanDB.ChannelGraph()), MaxPendingOpens: 10, ConnectToPeer: func(target *btcec.PublicKey, addrs []net.Addr) (bool, error) { - // We can't establish a channel if no addresses were - // provided for the peer. - if len(addrs) == 0 { - return false, errors.New("no addresses specified") - } - // First, we'll check if we're already connected to the // target peer. If we are, we can exit early. Otherwise, // we'll need to establish a connection. @@ -122,6 +116,12 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error) return true, nil } + // We can't establish a channel if no addresses were + // provided for the peer. + if len(addrs) == 0 { + return false, errors.New("no addresses specified") + } + atplLog.Tracef("Attempting to connect to %x", target.SerializeCompressed())