fundingmanager: send on resCtx.err in failFundingFlow

This commit moves the responsibility of sending a funding error on the
reservation error channel inside failFundingFlow, reducing the places we
need to keep track of sending it.
This commit is contained in:
Johan T. Halseth 2018-05-30 12:22:51 +02:00
parent 9090344329
commit d20cb8e2f6
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -793,6 +793,20 @@ func (f *fundingManager) CancelPeerReservations(nodePub [33]byte) {
func (f *fundingManager) failFundingFlow(peer *btcec.PublicKey, func (f *fundingManager) failFundingFlow(peer *btcec.PublicKey,
tempChanID [32]byte, fundingErr error) { tempChanID [32]byte, fundingErr error) {
fndgLog.Debugf("Failing funding flow for pendingID=%x: %v",
tempChanID, fundingErr)
ctx, err := f.cancelReservationCtx(peer, tempChanID)
if err != nil {
fndgLog.Errorf("unable to cancel reservation: %v", err)
}
// In case the case where the reservation existed, send the funding
// error on the error channel.
if ctx != nil {
ctx.err <- fundingErr
}
// We only send the exact error if it is part of out whitelisted set of // We only send the exact error if it is part of out whitelisted set of
// errors (lnwire.ErrorCode or lnwallet.ReservationError). // errors (lnwire.ErrorCode or lnwallet.ReservationError).
var msg lnwire.ErrorData var msg lnwire.ErrorData
@ -816,20 +830,11 @@ func (f *fundingManager) failFundingFlow(peer *btcec.PublicKey,
Data: msg, Data: msg,
} }
fndgLog.Errorf("Failing funding flow: %v (%v)", fundingErr, fndgLog.Debugf("Sending funding error to peer (%x): %v",
spew.Sdump(errMsg)) peer.SerializeCompressed(), spew.Sdump(errMsg))
if err := f.cfg.SendToPeer(peer, errMsg); err != nil {
if _, err := f.cancelReservationCtx(peer, tempChanID); err != nil {
fndgLog.Errorf("unable to cancel reservation: %v", err)
}
err := f.cfg.SendToPeer(peer, errMsg)
if err != nil {
fndgLog.Errorf("unable to send error message to peer %v", err) fndgLog.Errorf("unable to send error message to peer %v", err)
return
} }
return
} }
// reservationCoordinator is the primary goroutine tasked with progressing the // reservationCoordinator is the primary goroutine tasked with progressing the
@ -1220,7 +1225,6 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
fmsg.peerAddress.IdentityKey, err) fmsg.peerAddress.IdentityKey, err)
f.failFundingFlow(fmsg.peerAddress.IdentityKey, f.failFundingFlow(fmsg.peerAddress.IdentityKey,
msg.PendingChannelID, err) msg.PendingChannelID, err)
resCtx.err <- err
return return
} }
@ -1265,7 +1269,6 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
fndgLog.Errorf("Unable to parse signature: %v", err) fndgLog.Errorf("Unable to parse signature: %v", err)
f.failFundingFlow(fmsg.peerAddress.IdentityKey, f.failFundingFlow(fmsg.peerAddress.IdentityKey,
msg.PendingChannelID, err) msg.PendingChannelID, err)
resCtx.err <- err
return return
} }
err = f.cfg.SendToPeer(fmsg.peerAddress.IdentityKey, fundingCreated) err = f.cfg.SendToPeer(fmsg.peerAddress.IdentityKey, fundingCreated)
@ -1273,7 +1276,6 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) {
fndgLog.Errorf("Unable to send funding complete message: %v", err) fndgLog.Errorf("Unable to send funding complete message: %v", err)
f.failFundingFlow(fmsg.peerAddress.IdentityKey, f.failFundingFlow(fmsg.peerAddress.IdentityKey,
msg.PendingChannelID, err) msg.PendingChannelID, err)
resCtx.err <- err
return return
} }
} }
@ -1530,7 +1532,6 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
completeChan, err := resCtx.reservation.CompleteReservation(nil, commitSig) completeChan, err := resCtx.reservation.CompleteReservation(nil, commitSig)
if err != nil { if err != nil {
fndgLog.Errorf("Unable to complete reservation sign complete: %v", err) fndgLog.Errorf("Unable to complete reservation sign complete: %v", err)
resCtx.err <- err
f.failFundingFlow(fmsg.peerAddress.IdentityKey, f.failFundingFlow(fmsg.peerAddress.IdentityKey,
pendingChanID, err) pendingChanID, err)
return return