lnwire: fix encoding of MilliSatoshi

`MilliSatoshi` itself is already a `BigSize`, we just need to change the
decoding and encoding types to use that.
This commit is contained in:
yyforyongyu
2025-07-02 02:47:48 +08:00
parent 5e9365552c
commit e94ca84449
2 changed files with 10 additions and 16 deletions

View File

@@ -76,8 +76,8 @@ func (dc *DynCommit) Decode(r io.Reader, _ uint32) error {
// Prepare receiving buffers to be filled by TLV extraction. // Prepare receiving buffers to be filled by TLV extraction.
var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
var maxValue tlv.RecordT[tlv.TlvType2, uint64] var maxValue tlv.RecordT[tlv.TlvType2, MilliSatoshi]
var htlcMin tlv.RecordT[tlv.TlvType4, uint64] var htlcMin tlv.RecordT[tlv.TlvType4, MilliSatoshi]
var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
csvDelay := dc.CsvDelay.Zero() csvDelay := dc.CsvDelay.Zero()
maxHtlcs := dc.MaxAcceptedHTLCs.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 { if val, ok := typeMap[dc.MaxValueInFlight.TlvType()]; ok && val == nil {
var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
rec.Val = MilliSatoshi(maxValue.Val) rec.Val = maxValue.Val
dc.MaxValueInFlight = tlv.SomeRecordT(rec) dc.MaxValueInFlight = tlv.SomeRecordT(rec)
} }
if val, ok := typeMap[dc.HtlcMinimum.TlvType()]; ok && val == nil { if val, ok := typeMap[dc.HtlcMinimum.TlvType()]; ok && val == nil {
var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi]
rec.Val = MilliSatoshi(htlcMin.Val) rec.Val = htlcMin.Val
dc.HtlcMinimum = tlv.SomeRecordT(rec) dc.HtlcMinimum = tlv.SomeRecordT(rec)
} }
if val, ok := typeMap[dc.ChannelReserve.TlvType()]; ok && val == nil { if val, ok := typeMap[dc.ChannelReserve.TlvType()]; ok && val == nil {

View File

@@ -112,8 +112,8 @@ func (dp *DynPropose) Decode(r io.Reader, _ uint32) error {
// Prepare receiving buffers to be filled by TLV extraction. // Prepare receiving buffers to be filled by TLV extraction.
var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]] var dustLimit tlv.RecordT[tlv.TlvType0, tlv.BigSizeT[btcutil.Amount]]
var maxValue tlv.RecordT[tlv.TlvType2, uint64] var maxValue tlv.RecordT[tlv.TlvType2, MilliSatoshi]
var htlcMin tlv.RecordT[tlv.TlvType4, uint64] var htlcMin tlv.RecordT[tlv.TlvType4, MilliSatoshi]
var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]] var reserve tlv.RecordT[tlv.TlvType6, tlv.BigSizeT[btcutil.Amount]]
csvDelay := dp.CsvDelay.Zero() csvDelay := dp.CsvDelay.Zero()
maxHtlcs := dp.MaxAcceptedHTLCs.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 { if val, ok := typeMap[dp.MaxValueInFlight.TlvType()]; ok && val == nil {
var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi]
rec.Val = MilliSatoshi(maxValue.Val) rec.Val = maxValue.Val
dp.MaxValueInFlight = tlv.SomeRecordT(rec) dp.MaxValueInFlight = tlv.SomeRecordT(rec)
delete(typeMap, dp.MaxValueInFlight.TlvType()) delete(typeMap, dp.MaxValueInFlight.TlvType())
} }
if val, ok := typeMap[dp.HtlcMinimum.TlvType()]; ok && val == nil { if val, ok := typeMap[dp.HtlcMinimum.TlvType()]; ok && val == nil {
var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi]
rec.Val = MilliSatoshi(htlcMin.Val) rec.Val = htlcMin.Val
dp.HtlcMinimum = tlv.SomeRecordT(rec) dp.HtlcMinimum = tlv.SomeRecordT(rec)
delete(typeMap, dp.HtlcMinimum.TlvType()) delete(typeMap, dp.HtlcMinimum.TlvType())
@@ -226,18 +226,12 @@ func dynProposeRecords(dp *DynPropose) []tlv.RecordProducer {
) )
dp.MaxValueInFlight.WhenSome( dp.MaxValueInFlight.WhenSome(
func(mvif tlv.RecordT[tlv.TlvType2, MilliSatoshi]) { func(mvif tlv.RecordT[tlv.TlvType2, MilliSatoshi]) {
rec := tlv.NewPrimitiveRecord[tlv.TlvType2]( recordProducers = append(recordProducers, &mvif)
uint64(mvif.Val),
)
recordProducers = append(recordProducers, &rec)
}, },
) )
dp.HtlcMinimum.WhenSome( dp.HtlcMinimum.WhenSome(
func(hm tlv.RecordT[tlv.TlvType4, MilliSatoshi]) { func(hm tlv.RecordT[tlv.TlvType4, MilliSatoshi]) {
rec := tlv.NewPrimitiveRecord[tlv.TlvType4]( recordProducers = append(recordProducers, &hm)
uint64(hm.Val),
)
recordProducers = append(recordProducers, &rec)
}, },
) )
dp.ChannelReserve.WhenSome( dp.ChannelReserve.WhenSome(