htlcswitch: split parsing and validation of TLV payloads
When handling blinded errors, we need to know whether there was a blinding key in our payload when we successfully parsed our payload but then found an invalid set of fields. The combination of parsing and validation in NewPayloadFromReader means that we don't know whether a blinding point was available to us by the time the error is returned. This commit splits parsing and validation into two functions so that we can take a look at what we actually pulled of the payload in between parsing and TLV validation.
This commit is contained in:
4 files changed
+63
-42
No files matched your search
@@ -135,19 +135,23 @@ func fuzzPayload(f *testing.F, finalPayload, updateAddBlinded bool) {
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
|
||||
payload1, _, err := NewPayloadFromReader(
|
||||
r, finalPayload, updateAddBlinded,
|
||||
)
|
||||
payload1, parsed, err := ParseTLVPayload(r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = ValidateParsedPayloadTypes(
|
||||
parsed, finalPayload, updateAddBlinded,
|
||||
); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
hop, nextChanID := hopFromPayload(payload1)
|
||||
err = hop.PackHopPayload(&b, nextChanID, finalPayload)
|
||||
switch {
|
||||
// PackHopPayload refuses to encode an AMP record
|
||||
// without an MPP record. However, NewPayloadFromReader
|
||||
// without an MPP record. However, ValidateParsedPayloadTypes
|
||||
// does allow decoding an AMP record without an MPP
|
||||
// record, since validation is done at a later stage. Do
|
||||
// not report a bug for this case.
|
||||
@@ -156,9 +160,9 @@ func fuzzPayload(f *testing.F, finalPayload, updateAddBlinded bool) {
|
||||
|
||||
// PackHopPayload will not encode regular payloads or final
|
||||
// hops in blinded routes that do not have an amount or expiry
|
||||
// TLV set. However, NewPayloadFromReader will allow creation
|
||||
// of payloads where these TLVs are present, but they have
|
||||
// zero values because validation is done at a later stage.
|
||||
// TLV set. However, ValidateParsedPayloadTypes will allow
|
||||
// creation of payloads where these TLVs are present, but they
|
||||
// have zero values because validation is done at a later stage.
|
||||
case errors.Is(err, route.ErrMissingField):
|
||||
return
|
||||
|
||||
@@ -166,8 +170,11 @@ func fuzzPayload(f *testing.F, finalPayload, updateAddBlinded bool) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
payload2, _, err := NewPayloadFromReader(
|
||||
&b, finalPayload, updateAddBlinded,
|
||||
payload2, parsed, err := ParseTLVPayload(&b)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ValidateParsedPayloadTypes(
|
||||
parsed, finalPayload, updateAddBlinded,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Reference in new issue
Block a user