From 7b0a31217f5db2bcd5e33a30648a75b21b6a1040 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 10 Apr 2019 17:11:19 -0700 Subject: [PATCH] chanrestore: ensure we have no existing connections to recovery peer In this commit, we fix a slight bug in the existing implantation that would cause no channel recovery if the recovering node was already connected to their channel peer. As we need the link to be known at the time of connection, if we're already connected, then the chan sync message won't be sent again. By first disconnecting an existing peer, we ensure that during the next connection (after the recovered channel is added to the database), then the regular chan sync message exchange will take place as expected. # Please enter the commit message for your changes. --- chanrestore.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/chanrestore.go b/chanrestore.go index c1611395..bb1ba680 100644 --- a/chanrestore.go +++ b/chanrestore.go @@ -156,6 +156,14 @@ var _ chanbackup.ChannelRestorer = (*chanDBRestorer)(nil) // // NOTE: Part of the chanbackup.PeerConnector interface. func (s *server) ConnectPeer(nodePub *btcec.PublicKey, addrs []net.Addr) error { + // Before we connect to the remote peer, we'll remove any connections + // to ensure the new connection is created after this new link/channel + // is known. + if err := s.DisconnectPeer(nodePub); err != nil { + ltndLog.Infof("Peer(%v) is already connected, proceeding "+ + "with chan restore", nodePub.SerializeCompressed()) + } + // For each of the known addresses, we'll attempt to launch a // persistent connection to the (pub, addr) pair. In the event that any // of them connect, all the other stale requests will be cancelled. @@ -174,7 +182,7 @@ func (s *server) ConnectPeer(nodePub *btcec.PublicKey, addrs []net.Addr) error { err := s.ConnectToPeer(netAddr, true) // If we're already connected to this peer, then we don't - // consider this an erorr, so we'll exit here. + // consider this an error, so we'll exit here. if _, ok := err.(*errPeerAlreadyConnected); ok { return nil