pilot: if unable to establish channel, disconnect peer

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.
This commit is contained in:
Olaoluwa Osuntokun 2018-03-10 16:50:20 -08:00
parent 00ab66469d
commit 602048ae5c
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -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