@@ -260,6 +260,10 @@ type openChannelTlvData struct {
260
260
// customBlob is an optional TLV encoded blob of data representing
261
261
// custom channel funding information.
262
262
customBlob tlv.OptionalRecordT [tlv.TlvType7 , tlv.Blob ]
263
+
264
+ // commitChainEpochHistory is the optional TLV encoded blob of data
265
+ // representing the commit chain epoch history for the channel.
266
+ commitChainEpochHistory tlv.OptionalRecordT [tlv.TlvType8 , CommitChainEpochHistory ] //nolint:lll
263
267
}
264
268
265
269
// encode serializes the openChannelTlvData to the given io.Writer.
@@ -281,6 +285,11 @@ func (c *openChannelTlvData) encode(w io.Writer) error {
281
285
c .customBlob .WhenSome (func (blob tlv.RecordT [tlv.TlvType7 , tlv.Blob ]) {
282
286
tlvRecords = append (tlvRecords , blob .Record ())
283
287
})
288
+ c .commitChainEpochHistory .WhenSome (
289
+ func (hist tlv.RecordT [tlv.TlvType8 , CommitChainEpochHistory ]) {
290
+ tlvRecords = append (tlvRecords , hist .Record ())
291
+ },
292
+ )
284
293
285
294
// Create the tlv stream.
286
295
tlvStream , err := tlv .NewStream (tlvRecords ... )
@@ -296,6 +305,7 @@ func (c *openChannelTlvData) decode(r io.Reader) error {
296
305
memo := c .memo .Zero ()
297
306
tapscriptRoot := c .tapscriptRoot .Zero ()
298
307
blob := c .customBlob .Zero ()
308
+ commitChainEpochHistory := c .commitChainEpochHistory .Zero ()
299
309
300
310
// Create the tlv stream.
301
311
tlvStream , err := tlv .NewStream (
@@ -306,6 +316,7 @@ func (c *openChannelTlvData) decode(r io.Reader) error {
306
316
memo .Record (),
307
317
tapscriptRoot .Record (),
308
318
blob .Record (),
319
+ commitChainEpochHistory .Record (),
309
320
)
310
321
if err != nil {
311
322
return err
@@ -325,6 +336,10 @@ func (c *openChannelTlvData) decode(r io.Reader) error {
325
336
if _ , ok := tlvs [c .customBlob .TlvType ()]; ok {
326
337
c .customBlob = tlv .SomeRecordT (blob )
327
338
}
339
+ if _ , ok := tlvs [c .commitChainEpochHistory .TlvType ()]; ok {
340
+ c .commitChainEpochHistory =
341
+ tlv .SomeRecordT (commitChainEpochHistory )
342
+ }
328
343
329
344
return nil
330
345
}
@@ -947,6 +962,10 @@ type OpenChannel struct {
947
962
// commitment.
948
963
Commitments lntypes.Dual [ChannelCommitment ]
949
964
965
+ // CommitChainEpochHistory is the history of the CommitmentParams for
966
+ // each side of the channel.
967
+ CommitChainEpochHistory CommitChainEpochHistory
968
+
950
969
// RemoteCurrentRevocation is the current revocation for their
951
970
// commitment transaction. However, since this the derived public key,
952
971
// we don't yet have the private key so we aren't yet able to verify
@@ -1207,6 +1226,11 @@ func (c *OpenChannel) amendTlvData(auxData openChannelTlvData) {
1207
1226
auxData .customBlob .WhenSomeV (func (blob tlv.Blob ) {
1208
1227
c .CustomBlob = fn .Some (blob )
1209
1228
})
1229
+ auxData .commitChainEpochHistory .WhenSomeV (
1230
+ func (history CommitChainEpochHistory ) {
1231
+ c .CommitChainEpochHistory = history
1232
+ },
1233
+ )
1210
1234
}
1211
1235
1212
1236
// extractTlvData creates a new openChannelTlvData from the given channel.
@@ -1224,6 +1248,11 @@ func (c *OpenChannel) extractTlvData() openChannelTlvData {
1224
1248
realScid : tlv.NewRecordT [tlv.TlvType4 ](
1225
1249
c .confirmedScid ,
1226
1250
),
1251
+ commitChainEpochHistory : tlv .SomeRecordT (
1252
+ tlv.NewRecordT [tlv.TlvType8 ](
1253
+ c .CommitChainEpochHistory ,
1254
+ ),
1255
+ ),
1227
1256
}
1228
1257
1229
1258
if len (c .Memo ) != 0 {
@@ -4508,6 +4537,22 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error {
4508
4537
// open channel.
4509
4538
channel .amendTlvData (auxData )
4510
4539
4540
+ // Now that we've extracted the aux data, we can initialize the
4541
+ // CommitChainEpochHistory. If we don't find it in the aux data,
4542
+ // then we initialize it with the original CommitmentParams from
4543
+ // the ChannelConfig.
4544
+ histVal := auxData .commitChainEpochHistory .ValOpt ()
4545
+ channel .CommitChainEpochHistory = histVal .UnwrapOr (
4546
+ BeginChainEpochHistory (
4547
+ lntypes .MapDual (
4548
+ channel .ChanCfgs ,
4549
+ func (cfg ChannelConfig ) CommitmentParams {
4550
+ return cfg .CommitmentParams
4551
+ },
4552
+ ),
4553
+ ),
4554
+ )
4555
+
4511
4556
channel .Packager = NewChannelPackager (channel .ShortChannelID )
4512
4557
4513
4558
// Finally, read the optional shutdown scripts.
0 commit comments