From 602048ae5c009449d5aedd96cc5169308949adeb Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 10 Mar 2018 16:50:20 -0800 Subject: [PATCH] pilot: if unable to establish channel, disconnect peer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we fix a quick in the main autopilot handling. If we’re unable to establish a channel to a peer for w/e reason, then we’ll disconnect the peer. With this tactic, we avoid unnecessarily building up tens of peers for no reason at all. --- pilot.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pilot.go b/pilot.go index b6eb3a78..dd0b6ab6 100644 --- a/pilot.go +++ b/pilot.go @@ -98,6 +98,18 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey, select { case err := <-errChan: + // If we were not able to actually open a channel to the peer + // for whatever reason, then we'll disconnect from the peer to + // ensure we don't accumulate a bunch of unnecessary + // connections. + if err != nil { + dcErr := c.server.DisconnectPeer(target) + if dcErr != nil { + atplLog.Errorf("Unable to disconnect from peer %v", + target.SerializeCompressed()) + } + } + return err case <-updateStream: return nil @@ -148,7 +160,8 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error) WalletBalance: func() (btcutil.Amount, error) { return svr.cc.wallet.ConfirmedBalance(1) }, - Graph: autopilot.ChannelGraphFromDatabase(svr.chanDB.ChannelGraph()), + Graph: autopilot.ChannelGraphFromDatabase(svr.chanDB.ChannelGraph()), + MaxPendingOpens: 10, } // Next, we'll fetch the current state of open channels from the