From 3455f7965dec4bfd83c150aca201d401d4f9596c Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 30 Oct 2019 21:19:53 -0700 Subject: [PATCH] htlcswitch/link: return InvalidOnionPayload failure This commit modifies the link return an InvalidOnionPayload failure when it cannot parse a TLV payload. The offset is left at zero, since its unclear how useful it will be in practice and would require some significant reworkings of the abstractions in the tlv package. TODO: add unit tests. currently none of the test unit infrastructure is setup to handle TLV payloads, so this would require implementing a separate mock iterator for TLV payloads that also supports injecting invalid payloads. Deferring this non-trival effor till a later date --- htlcswitch/link.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index c0b62633c..dd40ce704 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -2646,12 +2646,23 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, fwdInfo, err := chanIterator.ForwardingInstructions() if err != nil { // If we're unable to process the onion payload, or we - // we received malformed TLV stream, then we should - // send an error back to the caller so the HTLC can be - // canceled. + // received invalid onion payload failure, then we + // should send an error back to the caller so the HTLC + // can be canceled. + var failedType uint64 + if e, ok := err.(hop.ErrInvalidPayload); ok { + failedType = uint64(e.Type) + } + + // TODO: currently none of the test unit infrastructure + // is setup to handle TLV payloads, so testing this + // would require implementing a separate mock iterator + // for TLV payloads that also supports injecting invalid + // payloads. Deferring this non-trival effort till a + // later date l.sendHTLCError( pd.HtlcIndex, - lnwire.NewInvalidOnionVersion(onionBlob[:]), + lnwire.NewInvalidOnionPayload(failedType, 0), obfuscator, pd.SourceRef, ) needUpdate = true