htlcswitch: create error obfuscator with wrapped type for blinded
Create our error encrypter with a wrapped type if we have a blinding point present. Doing this in the iterator allows us to track this information when we have both pieces of information available to us, compared to trying to handle this later down the line: - Downstream link on failure: we know that we've set a blinding point for out outgoing HTLC, but not whether we're introduction or not - Upstream link on failure: once the failure packet has been sent through the switch, we no longer know whether we were the introduction point (without looking it up / examining our payload again / propagating this information through the switch).
This commit is contained in:
3 files changed
+77
-25
No files matched your search
+50
-20
@@ -3262,7 +3262,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
||||
// DecodeHopIterator function which process the Sphinx packet.
|
||||
chanIterator, failureCode := decodeResps[i].Result()
|
||||
if failureCode != lnwire.CodeNone {
|
||||
// If we're unable to process the onion blob than we
|
||||
// If we're unable to process the onion blob then we
|
||||
// should send the malformed htlc error to payment
|
||||
// sender.
|
||||
l.sendMalformedHTLCError(pd.HtlcIndex, failureCode,
|
||||
@@ -3273,27 +3273,9 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
||||
continue
|
||||
}
|
||||
|
||||
// Retrieve onion obfuscator from onion blob in order to
|
||||
// produce initial obfuscation of the onion failureCode.
|
||||
obfuscator, failureCode := chanIterator.ExtractErrorEncrypter(
|
||||
l.cfg.ExtractErrorEncrypter,
|
||||
)
|
||||
if failureCode != lnwire.CodeNone {
|
||||
// If we're unable to process the onion blob than we
|
||||
// should send the malformed htlc error to payment
|
||||
// sender.
|
||||
l.sendMalformedHTLCError(
|
||||
pd.HtlcIndex, failureCode, onionBlob[:], pd.SourceRef,
|
||||
)
|
||||
|
||||
l.log.Errorf("unable to decode onion "+
|
||||
"obfuscator: %v", failureCode)
|
||||
continue
|
||||
}
|
||||
|
||||
heightNow := l.cfg.BestHeight()
|
||||
|
||||
pld, _, pldErr := chanIterator.HopPayload()
|
||||
pld, routeRole, pldErr := chanIterator.HopPayload()
|
||||
if pldErr != nil {
|
||||
// If we're unable to process the onion payload, or we
|
||||
// received invalid onion payload failure, then we
|
||||
@@ -3308,6 +3290,33 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
||||
failedType = uint64(e.Type)
|
||||
}
|
||||
|
||||
// If we couldn't parse the payload, make our best
|
||||
// effort at creating an error encrypter that knows
|
||||
// what blinding type we were, but if we couldn't
|
||||
// parse the payload we have no way of knowing whether
|
||||
// we were the introduction node or not.
|
||||
//
|
||||
//nolint:lll
|
||||
obfuscator, failCode := chanIterator.ExtractErrorEncrypter(
|
||||
l.cfg.ExtractErrorEncrypter,
|
||||
// We need our route role here because we
|
||||
// couldn't parse or validate the payload.
|
||||
routeRole == hop.RouteRoleIntroduction,
|
||||
)
|
||||
if failCode != lnwire.CodeNone {
|
||||
l.log.Errorf("could not extract error "+
|
||||
"encrypter: %v", pldErr)
|
||||
|
||||
// We can't process this htlc, send back
|
||||
// malformed.
|
||||
l.sendMalformedHTLCError(
|
||||
pd.HtlcIndex, failureCode,
|
||||
onionBlob[:], pd.SourceRef,
|
||||
)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO: currently none of the test unit infrastructure
|
||||
// is setup to handle TLV payloads, so testing this
|
||||
// would require implementing a separate mock iterator
|
||||
@@ -3325,6 +3334,27 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
||||
continue
|
||||
}
|
||||
|
||||
// Retrieve onion obfuscator from onion blob in order to
|
||||
// produce initial obfuscation of the onion failureCode.
|
||||
obfuscator, failureCode := chanIterator.ExtractErrorEncrypter(
|
||||
l.cfg.ExtractErrorEncrypter,
|
||||
routeRole == hop.RouteRoleIntroduction,
|
||||
)
|
||||
if failureCode != lnwire.CodeNone {
|
||||
// If we're unable to process the onion blob than we
|
||||
// should send the malformed htlc error to payment
|
||||
// sender.
|
||||
l.sendMalformedHTLCError(
|
||||
pd.HtlcIndex, failureCode, onionBlob[:],
|
||||
pd.SourceRef,
|
||||
)
|
||||
|
||||
l.log.Errorf("unable to decode onion "+
|
||||
"obfuscator: %v", failureCode)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
fwdInfo := pld.ForwardingInfo()
|
||||
|
||||
// Check whether the payload we've just processed uses our
|
||||
|
||||
Reference in new issue
Block a user