fundingmanager: simplify handleErrorMsg

This commit is contained in:
Johan T. Halseth 2018-05-30 12:16:37 +02:00
parent 7d38e35cdc
commit 9090344329
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -2679,13 +2679,13 @@ func (f *fundingManager) handleErrorMsg(fmsg *fundingErrorMsg) {
peerKey := fmsg.peerAddress.IdentityKey peerKey := fmsg.peerAddress.IdentityKey
chanID := fmsg.err.ChanID chanID := fmsg.err.ChanID
// First, we'll attempt to retrieve the funding workflow that this // First, we'll attempt to retrieve and cancel the funding workflow
// error was tied to. If we're unable to do so, then we'll exit early // that this error was tied to. If we're unable to do so, then we'll
// as this was an unwarranted error. // exit early as this was an unwarranted error.
resCtx, err := f.getReservationCtx(peerKey, chanID) resCtx, err := f.cancelReservationCtx(peerKey, chanID)
if err != nil { if err != nil {
fndgLog.Warnf("Received error for non-existent funding "+ fndgLog.Warnf("Received error for non-existent funding "+
"flow: %v", spew.Sdump(protocolErr)) "flow: %v (%v)", err, spew.Sdump(protocolErr))
return return
} }
@ -2699,21 +2699,17 @@ func (f *fundingManager) handleErrorMsg(fmsg *fundingErrorMsg) {
// If this isn't a simple error code, then we'll display the entire // If this isn't a simple error code, then we'll display the entire
// thing. // thing.
if len(protocolErr.Data) > 1 { if len(protocolErr.Data) > 1 {
resCtx.err <- grpc.Errorf( err = grpc.Errorf(
lnErr.ToGrpcCode(), string(protocolErr.Data), lnErr.ToGrpcCode(), string(protocolErr.Data),
) )
} else { } else {
// Otherwise, we'll attempt to display just the error code // Otherwise, we'll attempt to display just the error code
// itself. // itself.
resCtx.err <- grpc.Errorf( err = grpc.Errorf(
lnErr.ToGrpcCode(), lnErr.String(), lnErr.ToGrpcCode(), lnErr.String(),
) )
} }
resCtx.err <- err
if _, err := f.cancelReservationCtx(peerKey, chanID); err != nil {
fndgLog.Warnf("unable to delete reservation: %v", err)
return
}
} }
// pruneZombieReservations loops through all pending reservations and fails the // pruneZombieReservations loops through all pending reservations and fails the