From 1ce6c4668e43ef009bbbd76fca710cf6f0484151 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 30 Aug 2017 20:31:33 -0700 Subject: [PATCH] funding: unconditionally forward all received errors to client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, our old lnwire.Error message used a special code to indicate different types of errors. With the recent push for spec compatibility, we removed this field and instead stuffed the error into the first byte of the error data. This works between lnd nodes, but with other implementations they may send different errors which use a different error scheme. To fix this, we’ll now unconditionally return the error to the end caller (if one exists). --- fundingmanager.go | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index d3a540f7..6751402e 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1894,33 +1894,32 @@ func (f *fundingManager) processFundingError(err *lnwire.Error, // depending on the type of error we should do different clean up steps and // inform the user about it. func (f *fundingManager) handleErrorMsg(fmsg *fundingErrorMsg) { - e := fmsg.err + protocolErr := fmsg.err - lnErr := lnwire.ErrorCode(e.Data[0]) - switch lnErr { - case lnwire.ErrChanTooLarge: - fallthrough - case lnwire.ErrMaxPendingChannels: - fallthrough - case lnwire.ErrSynchronizingChain: - peerKey := fmsg.peerAddress.IdentityKey - chanID := fmsg.err.ChanID - ctx, err := f.cancelReservationCtx(peerKey, chanID) - if err != nil { - fndgLog.Warnf("unable to delete reservation: %v", err) - ctx.err <- err - return - } + peerKey := fmsg.peerAddress.IdentityKey + chanID := fmsg.err.ChanID - fndgLog.Errorf("Received funding error from %x: %v", - peerKey.SerializeCompressed(), lnErr, - ) - - ctx.err <- grpc.Errorf(lnErr.ToGrpcCode(), lnErr.String()) + // First, we'll attempt to retrieve the funding workflow that this + // error was tied to. If we're unable to do so, then we'll exit early + // as this was an unwarranted error. + resCtx, err := f.getReservationCtx(peerKey, chanID) + if err != nil { + fndgLog.Warnf("Received error for non-existent funding "+ + "flow: %v", protocolErr) return + } - default: - fndgLog.Warnf("unknown funding error: %v", spew.Sdump(e.Data)) + // If we did indeed find the funding workflow, then we'll return the + // error back to the caller (if any), and cancel the workflow itself. + lnErr := lnwire.ErrorCode(protocolErr.Data[0]) + fndgLog.Errorf("Received funding error from %x: %v", + peerKey.SerializeCompressed(), lnErr, + ) + resCtx.err <- grpc.Errorf(lnErr.ToGrpcCode(), lnErr.String()) + + if _, err := f.cancelReservationCtx(peerKey, chanID); err != nil { + fndgLog.Warnf("unable to delete reservation: %v", err) + return } }