@@ -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
@@ -6150,7 +6175,7 @@ func (lc *LightningChannel) MayAddOutgoingHtlc(amt lnwire.MilliSatoshi) error {
61506175func (lc * LightningChannel ) htlcAddDescriptor (htlc * lnwire.UpdateAddHTLC ,
61516176 openKey * models.CircuitKey ) * PaymentDescriptor {
61526177
6153- return & PaymentDescriptor {
6178+ pd := & PaymentDescriptor {
61546179 EntryType : Add ,
61556180 RHash : PaymentHash (htlc .PaymentHash ),
61566181 Timeout : htlc .Expiry ,
@@ -6161,6 +6186,14 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
61616186 OpenCircuitKey : openKey ,
61626187 BlindingPoint : htlc .BlindingPoint ,
61636188 }
6189+
6190+ // Copy over any extra data included to ensure we can forward and
6191+ // process this HTLC properly.
6192+ if len (htlc .ExtraData ) != 0 {
6193+ pd .CustomRecords = fn.Some [tlv.Blob ](htlc .ExtraData [:])
6194+ }
6195+
6196+ return pd
61646197}
61656198
61666199// validateAddHtlc validates the addition of an outgoing htlc to our local and
@@ -6220,6 +6253,12 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
62206253 BlindingPoint : htlc .BlindingPoint ,
62216254 }
62226255
6256+ // Copy over any extra data included to ensure we can forward and
6257+ // process this HTLC properly.
6258+ if htlc .ExtraData != nil {
6259+ pd .CustomRecords = fn .Some (tlv .Blob (htlc .ExtraData [:]))
6260+ }
6261+
62236262 localACKedIndex := lc .remoteCommitChain .tail ().ourMessageIndex
62246263
62256264 // Clamp down on the number of HTLC's we can receive by checking the
0 commit comments