@@ -155,19 +155,17 @@ type HTLCEntry struct {
155155
156156 // Incoming denotes whether we're the receiver or the sender of this
157157 // HTLC.
158- //
159- // NOTE: this field is the memory representation of the field
160- // incomingUint.
161158 Incoming tlv.RecordT [tlv.TlvType3 , bool ]
162159
163160 // Amt is the amount of satoshis this HTLC escrows.
164- //
165- // NOTE: this field is the memory representation of the field amtUint.
166161 Amt tlv.RecordT [tlv.TlvType4 , tlv.BigSizeT [btcutil.Amount ]]
167162
168163 // CustomBlob is an optional blob that can be used to store information
169164 // specific to revocation handling for a custom channel type.
170165 CustomBlob tlv.OptionalRecordT [tlv.TlvType5 , tlv.Blob ]
166+
167+ // HtlcIndex is the index of the HTLC in the channel.
168+ HtlcIndex tlv.OptionalRecordT [tlv.TlvType6 , uint16 ]
171169}
172170
173171// toTlvStream converts an HTLCEntry record into a tlv representation.
@@ -184,6 +182,12 @@ func (h *HTLCEntry) toTlvStream() (*tlv.Stream, error) {
184182 records = append (records , r .Record ())
185183 })
186184
185+ h .HtlcIndex .WhenSome (func (r tlv.RecordT [tlv.TlvType6 , uint16 ]) {
186+ records = append (records , r .Record ())
187+ })
188+
189+ tlv .SortRecords (records )
190+
187191 return tlv .NewStream (records ... )
188192}
189193
@@ -203,6 +207,9 @@ func NewHTLCEntryFromHTLC(htlc HTLC) (*HTLCEntry, error) {
203207 Amt : tlv.NewRecordT [tlv.TlvType4 ](
204208 tlv .NewBigSizeT (htlc .Amt .ToSatoshis ()),
205209 ),
210+ HtlcIndex : tlv .SomeRecordT (tlv.NewPrimitiveRecord [tlv.TlvType6 ](
211+ uint16 (htlc .HtlcIndex ),
212+ )),
206213 }
207214
208215 if len (htlc .CustomRecords ) != 0 {
@@ -509,6 +516,7 @@ func deserializeHTLCEntries(r io.Reader) ([]*HTLCEntry, error) {
509516 var htlc HTLCEntry
510517
511518 customBlob := htlc .CustomBlob .Zero ()
519+ htlcIndex := htlc .HtlcIndex .Zero ()
512520
513521 // Create the tlv stream.
514522 records := []tlv.Record {
@@ -518,6 +526,7 @@ func deserializeHTLCEntries(r io.Reader) ([]*HTLCEntry, error) {
518526 htlc .Incoming .Record (),
519527 htlc .Amt .Record (),
520528 customBlob .Record (),
529+ htlcIndex .Record (),
521530 }
522531
523532 tlvStream , err := tlv .NewStream (records ... )
@@ -539,6 +548,10 @@ func deserializeHTLCEntries(r io.Reader) ([]*HTLCEntry, error) {
539548 htlc .CustomBlob = tlv .SomeRecordT (customBlob )
540549 }
541550
551+ if t , ok := parsedTypes [htlcIndex .TlvType ()]; ok && t == nil {
552+ htlc .HtlcIndex = tlv .SomeRecordT (htlcIndex )
553+ }
554+
542555 // Append the entry.
543556 htlcs = append (htlcs , & htlc )
544557 }
0 commit comments