@@ -318,3 +318,87 @@ func (dp *DynPropose) MsgType() MessageType {
318
318
func (dp * DynPropose ) SerializedSize () (uint32 , error ) {
319
319
return MessageSerializedSize (dp )
320
320
}
321
+
322
+ // SerializeTlvData takes just the TLV data of DynPropose (which covers all of
323
+ // the parameters on deck for changing) and serializes just this component. The
324
+ // main purpose of this is to make it easier to validate the DynAck signature.
325
+ func (dp * DynPropose ) SerializeTlvData () ([]byte , error ) {
326
+ var tlvRecords []tlv.Record
327
+ dp .DustLimit .WhenSome (func (dl btcutil.Amount ) {
328
+ protoSats := uint64 (dl )
329
+ tlvRecords = append (
330
+ tlvRecords , tlv .MakePrimitiveRecord (
331
+ DPDustLimitSatoshis , & protoSats ,
332
+ ),
333
+ )
334
+ })
335
+ dp .MaxValueInFlight .WhenSome (func (max MilliSatoshi ) {
336
+ protoSats := uint64 (max )
337
+ tlvRecords = append (
338
+ tlvRecords , tlv .MakePrimitiveRecord (
339
+ DPMaxHtlcValueInFlightMsat , & protoSats ,
340
+ ),
341
+ )
342
+ })
343
+ dp .ChannelReserve .WhenSome (func (min btcutil.Amount ) {
344
+ channelReserve := uint64 (min )
345
+ tlvRecords = append (
346
+ tlvRecords , tlv .MakePrimitiveRecord (
347
+ DPChannelReserveSatoshis , & channelReserve ,
348
+ ),
349
+ )
350
+ })
351
+ dp .CsvDelay .WhenSome (func (wait uint16 ) {
352
+ tlvRecords = append (
353
+ tlvRecords , tlv .MakePrimitiveRecord (
354
+ DPToSelfDelay , & wait ,
355
+ ),
356
+ )
357
+ })
358
+ dp .MaxAcceptedHTLCs .WhenSome (func (max uint16 ) {
359
+ tlvRecords = append (
360
+ tlvRecords , tlv .MakePrimitiveRecord (
361
+ DPMaxAcceptedHtlcs , & max ,
362
+ ),
363
+ )
364
+ })
365
+ dp .FundingKey .WhenSome (func (key btcec.PublicKey ) {
366
+ keyScratch := & key
367
+ tlvRecords = append (
368
+ tlvRecords , tlv .MakePrimitiveRecord (
369
+ DPFundingPubkey , & keyScratch ,
370
+ ),
371
+ )
372
+ })
373
+ dp .ChannelType .WhenSome (func (ty ChannelType ) {
374
+ tlvRecords = append (
375
+ tlvRecords , tlv .MakeDynamicRecord (
376
+ DPChannelType , & ty ,
377
+ ty .featureBitLen ,
378
+ channelTypeEncoder , channelTypeDecoder ,
379
+ ),
380
+ )
381
+ })
382
+ dp .KickoffFeerate .WhenSome (func (kickoffFeerate chainfee.SatPerKWeight ) {
383
+ protoSats := uint32 (kickoffFeerate )
384
+ tlvRecords = append (
385
+ tlvRecords , tlv .MakePrimitiveRecord (
386
+ DPKickoffFeerate , & protoSats ,
387
+ ),
388
+ )
389
+ })
390
+ tlv .SortRecords (tlvRecords )
391
+
392
+ tlvStream , err := tlv .NewStream (tlvRecords ... )
393
+ if err != nil {
394
+ return nil , err
395
+ }
396
+
397
+ var outBuf bytes.Buffer
398
+ err = tlvStream .Encode (& outBuf )
399
+ if err != nil {
400
+ return nil , err
401
+ }
402
+
403
+ return outBuf .Bytes (), nil
404
+ }
0 commit comments