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.
This commit is contained in:
Johan T. Halseth 2018-09-26 11:12:57 +02:00
parent b341dea373
commit 240318befe
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

34
peer.go

@ -64,7 +64,7 @@ type outgoingMsg struct {
// has been confirmed and the channel creation process completed. // has been confirmed and the channel creation process completed.
type newChannelMsg struct { type newChannelMsg struct {
channel *lnwallet.LightningChannel channel *lnwallet.LightningChannel
done chan struct{} err chan error
} }
// closeMsgs is a wrapper struct around any wire messages that deal with the // closeMsgs is a wrapper struct around any wire messages that deal with the
@ -1533,7 +1533,7 @@ out:
"ignoring.", chanPoint) "ignoring.", chanPoint)
p.activeChanMtx.Unlock() p.activeChanMtx.Unlock()
close(newChanReq.done) close(newChanReq.err)
newChanReq.channel.Stop() newChanReq.channel.Stop()
// If we're being sent a new channel, and our // If we're being sent a new channel, and our
@ -1574,15 +1574,22 @@ out:
// TODO(roasbeef): panic on below? // TODO(roasbeef): panic on below?
_, currentHeight, err := p.server.cc.chainIO.GetBestBlock() _, currentHeight, err := p.server.cc.chainIO.GetBestBlock()
if err != nil { 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 continue
} }
chainEvents, err := p.server.chainArb.SubscribeChannelEvents( chainEvents, err := p.server.chainArb.SubscribeChannelEvents(
*chanPoint, *chanPoint,
) )
if err != nil { if err != nil {
peerLog.Errorf("unable to subscribe to chain "+ err := fmt.Errorf("unable to subscribe to "+
"events: %v", err) "chain events: %v", err)
peerLog.Errorf(err.Error())
newChanReq.err <- err
continue continue
} }
@ -1606,12 +1613,16 @@ out:
chainEvents, currentHeight, false, chainEvents, currentHeight, false,
) )
if err != nil { if err != nil {
peerLog.Errorf("can't register new channel "+ err := fmt.Errorf("can't register new channel "+
"link(%v) with NodeKey(%x)", chanPoint, "link(%v) with NodeKey(%x)", chanPoint,
p.PubKey()) 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 // We've just received a local request to close an active
// channel. If will either kick of a cooperative channel // 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, func (p *peer) AddNewChannel(channel *lnwallet.LightningChannel,
cancel <-chan struct{}) error { cancel <-chan struct{}) error {
newChanDone := make(chan struct{}) errChan := make(chan error, 1)
newChanMsg := &newChannelMsg{ newChanMsg := &newChannelMsg{
channel: channel, channel: channel,
done: newChanDone, err: errChan,
} }
select { 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 // We pause here to wait for the peer to recognize the new channel
// before we close the channel barrier corresponding to the channel. // before we close the channel barrier corresponding to the channel.
select { select {
case <-newChanDone: case err := <-errChan:
return err
case <-p.quit: case <-p.quit:
return ErrPeerExiting return ErrPeerExiting
} }
return nil
} }
// StartTime returns the time at which the connection was established if the // StartTime returns the time at which the connection was established if the