htlcswitch: notify incoming link failures

This commit adds link failure notifications for failures which occur
on our incoming link. These failures may be receives which we failed or
forwards which we could not parse.
This commit is contained in:
carla 2020-02-19 17:34:47 +02:00
parent 22d370aa51
commit 6bd0de257a
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -1224,8 +1224,7 @@ func (l *channelLink) processHtlcResolution(resolution invoices.HtlcResolution,
failure := getResolutionFailure(res, htlc.pd.Amount) failure := getResolutionFailure(res, htlc.pd.Amount)
l.sendHTLCError( l.sendHTLCError(
htlc.pd.HtlcIndex, failure, htlc.pd, failure, htlc.obfuscator, true,
htlc.obfuscator, htlc.pd.SourceRef,
) )
return nil return nil
@ -2696,9 +2695,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
// later date // later date
failure := lnwire.NewInvalidOnionPayload(failedType, 0) failure := lnwire.NewInvalidOnionPayload(failedType, 0)
l.sendHTLCError( l.sendHTLCError(
pd.HtlcIndex, pd, NewLinkError(failure), obfuscator, false,
NewLinkError(failure),
obfuscator, pd.SourceRef,
) )
l.log.Errorf("unable to decode forwarding "+ l.log.Errorf("unable to decode forwarding "+
@ -2811,10 +2808,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
) )
l.sendHTLCError( l.sendHTLCError(
pd.HtlcIndex, pd, NewLinkError(failure), obfuscator, false,
NewLinkError(failure),
obfuscator,
pd.SourceRef,
) )
continue continue
} }
@ -2900,7 +2894,7 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
failure := NewLinkError( failure := NewLinkError(
lnwire.NewFinalIncorrectHtlcAmount(pd.Amount), lnwire.NewFinalIncorrectHtlcAmount(pd.Amount),
) )
l.sendHTLCError(pd.HtlcIndex, failure, obfuscator, pd.SourceRef) l.sendHTLCError(pd, failure, obfuscator, true)
return nil return nil
} }
@ -2915,7 +2909,7 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
failure := NewLinkError( failure := NewLinkError(
lnwire.NewFinalIncorrectCltvExpiry(pd.Timeout), lnwire.NewFinalIncorrectCltvExpiry(pd.Timeout),
) )
l.sendHTLCError(pd.HtlcIndex, failure, obfuscator, pd.SourceRef) l.sendHTLCError(pd, failure, obfuscator, true)
return nil return nil
} }
@ -3031,8 +3025,8 @@ func (l *channelLink) handleBatchFwdErrs(errChan chan error) {
// sendHTLCError functions cancels HTLC and send cancel message back to the // sendHTLCError functions cancels HTLC and send cancel message back to the
// peer from which HTLC was received. // peer from which HTLC was received.
func (l *channelLink) sendHTLCError(htlcIndex uint64, failure *LinkError, func (l *channelLink) sendHTLCError(pd *lnwallet.PaymentDescriptor,
e hop.ErrorEncrypter, sourceRef *channeldb.AddRef) { failure *LinkError, e hop.ErrorEncrypter, isReceive bool) {
reason, err := e.EncryptFirstHop(failure.WireMessage()) reason, err := e.EncryptFirstHop(failure.WireMessage())
if err != nil { if err != nil {
@ -3040,7 +3034,7 @@ func (l *channelLink) sendHTLCError(htlcIndex uint64, failure *LinkError,
return return
} }
err = l.channel.FailHTLC(htlcIndex, reason, sourceRef, nil, nil) err = l.channel.FailHTLC(pd.HtlcIndex, reason, pd.SourceRef, nil, nil)
if err != nil { if err != nil {
l.log.Errorf("unable cancel htlc: %v", err) l.log.Errorf("unable cancel htlc: %v", err)
return return
@ -3048,9 +3042,35 @@ func (l *channelLink) sendHTLCError(htlcIndex uint64, failure *LinkError,
l.cfg.Peer.SendMessage(false, &lnwire.UpdateFailHTLC{ l.cfg.Peer.SendMessage(false, &lnwire.UpdateFailHTLC{
ChanID: l.ChanID(), ChanID: l.ChanID(),
ID: htlcIndex, ID: pd.HtlcIndex,
Reason: reason, Reason: reason,
}) })
// Notify a link failure on our incoming link. Outgoing htlc information
// is not available at this point, because we have not decrypted the
// onion, so it is excluded.
var eventType HtlcEventType
if isReceive {
eventType = HtlcEventTypeReceive
} else {
eventType = HtlcEventTypeForward
}
l.cfg.HtlcNotifier.NotifyLinkFailEvent(
HtlcKey{
IncomingCircuit: channeldb.CircuitKey{
ChanID: l.ShortChanID(),
HtlcID: pd.HtlcIndex,
},
},
HtlcInfo{
IncomingTimeLock: pd.Timeout,
IncomingAmt: pd.Amount,
},
eventType,
failure,
true,
)
} }
// sendMalformedHTLCError helper function which sends the malformed HTLC update // sendMalformedHTLCError helper function which sends the malformed HTLC update