From e94ca8444931ef66fb9d06b05c6eefd4b0c02bca Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 2 Jul 2025 02:47:48 +0800 Subject: [PATCH] lnwire: fix encoding of `MilliSatoshi` `MilliSatoshi` itself is already a `BigSize`, we just need to change the decoding and encoding types to use that. --- lnwire/dyn_commit.go | 8 ++++---- lnwire/dyn_propose.go | 18 ++++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lnwire/dyn_commit.go b/lnwire/dyn_commit.go index 8191b8867..1599ab320 100644 --- a/lnwire/dyn_commit.go +++ b/lnwire/dyn_commit.go @@ -76,8 +76,8 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error { // Prepare receiving buffers to be filled by TLV extraction. var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] - var maxValue tlv.RecordT[tlv.TlvType2, uint64] - var htlcMin tlv.RecordT[tlv.TlvType4, uint64] + var maxValue tlv.RecordT[tlv.TlvType2, MilliSatoshi] + var htlcMin tlv.RecordT[tlv.TlvType4, MilliSatoshi] var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] csvDelay := dc.CsvDelay.Zero() maxHtlcs := dc.MaxAcceptedHTLCs.Zero() @@ -100,12 +100,12 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error { } if val, ok := typeMap[dc.MaxValueInFlight.TlvType()]; ok && val == nil { var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] - rec.Val = MilliSatoshi(maxValue.Val) + rec.Val = maxValue.Val dc.MaxValueInFlight = tlv.SomeRecordT(rec) } if val, ok := typeMap[dc.HtlcMinimum.TlvType()]; ok && val == nil { var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] - rec.Val = MilliSatoshi(htlcMin.Val) + rec.Val = htlcMin.Val dc.HtlcMinimum = tlv.SomeRecordT(rec) } if val, ok := typeMap[dc.ChannelReserve.TlvType()]; ok && val == nil { diff --git a/lnwire/dyn_propose.go b/lnwire/dyn_propose.go index a1c3b4ba0..4d7459cf2 100644 --- a/lnwire/dyn_propose.go +++ b/lnwire/dyn_propose.go @@ -112,8 +112,8 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error { // Prepare receiving buffers to be filled by TLV extraction. var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] - var maxValue tlv.RecordT[tlv.TlvType2, uint64] - var htlcMin tlv.RecordT[tlv.TlvType4, uint64] + var maxValue tlv.RecordT[tlv.TlvType2, MilliSatoshi] + var htlcMin tlv.RecordT[tlv.TlvType4, MilliSatoshi] var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] csvDelay := dp.CsvDelay.Zero() maxHtlcs := dp.MaxAcceptedHTLCs.Zero() @@ -137,14 +137,14 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error { } if val, ok := typeMap[dp.MaxValueInFlight.TlvType()]; ok && val == nil { var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] - rec.Val = MilliSatoshi(maxValue.Val) + rec.Val = maxValue.Val dp.MaxValueInFlight = tlv.SomeRecordT(rec) delete(typeMap, dp.MaxValueInFlight.TlvType()) } if val, ok := typeMap[dp.HtlcMinimum.TlvType()]; ok && val == nil { var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] - rec.Val = MilliSatoshi(htlcMin.Val) + rec.Val = htlcMin.Val dp.HtlcMinimum = tlv.SomeRecordT(rec) delete(typeMap, dp.HtlcMinimum.TlvType()) @@ -226,18 +226,12 @@ func dynProposeRecords(dp *DynPropose) []tlv.RecordProducer { ) dp.MaxValueInFlight.WhenSome( func(mvif tlv.RecordT[tlv.TlvType2, MilliSatoshi]) { - rec := tlv.NewPrimitiveRecord[tlv.TlvType2]( - uint64(mvif.Val), - ) - recordProducers = append(recordProducers, &rec) + recordProducers = append(recordProducers, &mvif) }, ) dp.HtlcMinimum.WhenSome( func(hm tlv.RecordT[tlv.TlvType4, MilliSatoshi]) { - rec := tlv.NewPrimitiveRecord[tlv.TlvType4]( - uint64(hm.Val), - ) - recordProducers = append(recordProducers, &rec) + recordProducers = append(recordProducers, &hm) }, ) dp.ChannelReserve.WhenSome(