From 240318befe936a2f5cfd99875923bb69baa0b9b4 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 26 Sep 2018 11:12:57 +0200 Subject: [PATCH] peer: return error on newChanReq Previously the errors weren't returned back to the sender of the new channel, making it impossible to tell whether it suceeded or not. --- peer.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/peer.go b/peer.go index d438a470..3dfa639f 100644 --- a/peer.go +++ b/peer.go @@ -64,7 +64,7 @@ type outgoingMsg struct { // has been confirmed and the channel creation process completed. type newChannelMsg struct { channel *lnwallet.LightningChannel - done chan struct{} + err chan error } // closeMsgs is a wrapper struct around any wire messages that deal with the @@ -1533,7 +1533,7 @@ out: "ignoring.", chanPoint) p.activeChanMtx.Unlock() - close(newChanReq.done) + close(newChanReq.err) newChanReq.channel.Stop() // If we're being sent a new channel, and our @@ -1574,15 +1574,22 @@ out: // TODO(roasbeef): panic on below? _, currentHeight, err := p.server.cc.chainIO.GetBestBlock() if err != nil { - peerLog.Errorf("unable to get best block: %v", err) + err := fmt.Errorf("unable to get best "+ + "block: %v", err) + peerLog.Errorf(err.Error()) + + newChanReq.err <- err continue } chainEvents, err := p.server.chainArb.SubscribeChannelEvents( *chanPoint, ) if err != nil { - peerLog.Errorf("unable to subscribe to chain "+ - "events: %v", err) + err := fmt.Errorf("unable to subscribe to "+ + "chain events: %v", err) + peerLog.Errorf(err.Error()) + + newChanReq.err <- err continue } @@ -1606,12 +1613,16 @@ out: chainEvents, currentHeight, false, ) if err != nil { - peerLog.Errorf("can't register new channel "+ + err := fmt.Errorf("can't register new channel "+ "link(%v) with NodeKey(%x)", chanPoint, p.PubKey()) + peerLog.Errorf(err.Error()) + + newChanReq.err <- err + continue } - close(newChanReq.done) + close(newChanReq.err) // We've just received a local request to close an active // channel. If will either kick of a cooperative channel @@ -2174,10 +2185,10 @@ func (p *peer) Address() net.Addr { func (p *peer) AddNewChannel(channel *lnwallet.LightningChannel, cancel <-chan struct{}) error { - newChanDone := make(chan struct{}) + errChan := make(chan error, 1) newChanMsg := &newChannelMsg{ channel: channel, - done: newChanDone, + err: errChan, } select { @@ -2191,12 +2202,11 @@ func (p *peer) AddNewChannel(channel *lnwallet.LightningChannel, // We pause here to wait for the peer to recognize the new channel // before we close the channel barrier corresponding to the channel. select { - case <-newChanDone: + case err := <-errChan: + return err case <-p.quit: return ErrPeerExiting } - - return nil } // StartTime returns the time at which the connection was established if the