@@ -335,6 +335,10 @@ type PaymentDescriptor struct {
335335 // NOTE: Populated only on add payment descriptor entry types.
336336 OnionBlob []byte
337337
338+ // CustomRecrods also stores the set of optional custom records that
339+ // may have been attached to a sent HTLC.
340+ CustomRecords fn.Option [tlv.Blob ]
341+
338342 // ShaOnionBlob is a sha of the onion blob.
339343 //
340344 // NOTE: Populated only in payment descriptor with MalformedFail type.
@@ -752,6 +756,12 @@ func (c *commitment) toDiskCommit(ourCommit bool) *channeldb.ChannelCommitment {
752756 }
753757 copy (h .OnionBlob [:], htlc .OnionBlob )
754758
759+ // If the HTLC had custom records, then we'll copy that over so
760+ // we restore with the same information.
761+ htlc .CustomRecords .WhenSome (func (b tlv.Blob ) {
762+ copy (h .ExtraData , b )
763+ })
764+
755765 if ourCommit && htlc .sig != nil {
756766 h .Signature = htlc .sig .Serialize ()
757767 }
@@ -776,6 +786,13 @@ func (c *commitment) toDiskCommit(ourCommit bool) *channeldb.ChannelCommitment {
776786 BlindingPoint : htlc .BlindingPoint ,
777787 }
778788 copy (h .OnionBlob [:], htlc .OnionBlob )
789+
790+ // If the HTLC had custom records, then we'll copy that over so
791+ // we restore with the same information.
792+ htlc .CustomRecords .WhenSome (func (b tlv.Blob ) {
793+ copy (h .ExtraData , b )
794+ })
795+
779796 if ourCommit && htlc .sig != nil {
780797 h .Signature = htlc .sig .Serialize ()
781798 }
@@ -858,7 +875,7 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
858875 // With the scripts reconstructed (depending on if this is our commit
859876 // vs theirs or a pending commit for the remote party), we can now
860877 // re-create the original payment descriptor.
861- return PaymentDescriptor {
878+ pd = PaymentDescriptor {
862879 RHash : htlc .RHash ,
863880 Timeout : htlc .RefundTimeout ,
864881 Amount : htlc .Amt ,
@@ -873,7 +890,15 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
873890 theirPkScript : theirP2WSH ,
874891 theirWitnessScript : theirWitnessScript ,
875892 BlindingPoint : htlc .BlindingPoint ,
876- }, nil
893+ }
894+
895+ // Ensure that we'll restore any custom records which were stored as
896+ // extra data on disk.
897+ if len (htlc .ExtraData ) != 0 {
898+ pd .CustomRecords = fn.Some [tlv.Blob ](htlc .ExtraData )
899+ }
900+
901+ return pd , nil
877902}
878903
879904// extractPayDescs will convert all HTLC's present within a disk commit state
@@ -6159,7 +6184,7 @@ func (lc *LightningChannel) MayAddOutgoingHtlc(amt lnwire.MilliSatoshi) error {
61596184func (lc * LightningChannel ) htlcAddDescriptor (htlc * lnwire.UpdateAddHTLC ,
61606185 openKey * models.CircuitKey ) * PaymentDescriptor {
61616186
6162- return & PaymentDescriptor {
6187+ pd := & PaymentDescriptor {
61636188 EntryType : Add ,
61646189 RHash : PaymentHash (htlc .PaymentHash ),
61656190 Timeout : htlc .Expiry ,
@@ -6170,6 +6195,14 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
61706195 OpenCircuitKey : openKey ,
61716196 BlindingPoint : htlc .BlindingPoint ,
61726197 }
6198+
6199+ // Copy over any extra data included to ensure we can forward and
6200+ // process this HTLC properly.
6201+ if len (htlc .ExtraData ) != 0 {
6202+ pd .CustomRecords = fn.Some [tlv.Blob ](htlc .ExtraData [:])
6203+ }
6204+
6205+ return pd
61736206}
61746207
61756208// validateAddHtlc validates the addition of an outgoing htlc to our local and
@@ -6229,6 +6262,12 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
62296262 BlindingPoint : htlc .BlindingPoint ,
62306263 }
62316264
6265+ // Copy over any extra data included to ensure we can forward and
6266+ // process this HTLC properly.
6267+ if htlc .ExtraData != nil {
6268+ pd .CustomRecords = fn .Some (tlv .Blob (htlc .ExtraData [:]))
6269+ }
6270+
62326271 localACKedIndex := lc .remoteCommitChain .tail ().ourMessageIndex
62336272
62346273 // Clamp down on the number of HTLC's we can receive by checking the
0 commit comments