htlcswitch/hop: always accept even custom tlv records

This commit prepares for sending and receiving of application-specific
custom tlv fields.
This commit is contained in:
Joost Jager 2019-11-11 10:37:24 +01:00
parent 048971b40b
commit 78ecc3d24b
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 16 additions and 1 deletions

View File

@ -29,6 +29,12 @@ const (
RequiredViolation
)
const (
// customTypeStart is the start of the custom tlv type range as defined
// in BOLT 01.
customTypeStart = 65536
)
// String returns a human-readable description of the violation as a verb.
func (v PayloadViolation) String() string {
switch v {
@ -240,7 +246,10 @@ func getMinRequiredViolation(set tlv.TypeSet) *tlv.Type {
// If a type is even but not known to us, we cannot process the
// payload. We are required to understand a field that we don't
// support.
if known || t%2 != 0 {
//
// We always accept custom fields, because a higher level
// application may understand them.
if known || t%2 != 0 || t >= customTypeStart {
continue
}

View File

@ -130,6 +130,12 @@ var decodePayloadTests = []decodePayloadTest{
FinalHop: false,
},
},
{
name: "required type in custom range",
payload: []byte{0x02, 0x00, 0x04, 0x00,
0xfe, 0x00, 0x01, 0x00, 0x00, 0x00,
},
},
{
name: "valid intermediate hop",
payload: []byte{0x02, 0x00, 0x04, 0x00, 0x06, 0x08, 0x01, 0x00,