@@ -44,6 +44,10 @@ type HopPayload struct {
44
44
// HMAC is an HMAC computed over the entire per-hop payload that also
45
45
// includes the higher-level (optional) associated data bytes.
46
46
HMAC [HMACSize ]byte
47
+
48
+ // TLVPayloadGuaranteed is set to true if the payload is guaranteed to
49
+ // be a TLVPayload. E.g. in the case of an onion message.
50
+ TLVPayloadGuaranteed bool
47
51
}
48
52
49
53
// NewTLVHopPayload creates a new TLV encoded HopPayload. The payload will be
@@ -87,13 +91,8 @@ func (hp *HopPayload) Encode(w io.Writer) error {
87
91
}
88
92
89
93
// Decode unpacks an encoded HopPayload from the passed reader into the target
90
- // HopPayload. The isMessage boolean should be set to true if we're parsing a
91
- // payload that is known to be for an onion message.
92
- func (hp * HopPayload ) Decode (r io.Reader , isMessage ... bool ) error {
93
- // To preserve backwards compatibility, we'll default to isMessage being
94
- // false if it is not provided.
95
- isMsg := len (isMessage ) > 0 && isMessage [0 ]
96
-
94
+ // HopPayload.
95
+ func (hp * HopPayload ) Decode (r io.Reader ) error {
97
96
bufReader := bufio .NewReader (r )
98
97
99
98
// In order to properly parse the payload, we'll need to check the
@@ -104,12 +103,9 @@ func (hp *HopPayload) Decode(r io.Reader, isMessage ...bool) error {
104
103
return err
105
104
}
106
105
107
- // Per BOLT 7, onion messages MUST use the TLV format.
108
- if isMsg {
109
- return decodeTLVHopPayload (hp , bufReader )
110
- }
111
-
112
- if isLegacyPayloadByte (peekByte [0 ]) {
106
+ // If the HopPayload is guaranteed to be a TLV payload, we can skip the
107
+ // check for the legacy payload byte.
108
+ if ! hp .TLVPayloadGuaranteed && isLegacyPayloadByte (peekByte [0 ]) {
113
109
return decodeLegacyHopPayload (hp , bufReader )
114
110
}
115
111
0 commit comments