From ad38ed73c70f4d6d8086b37b184f47c98d7abeae Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 7 May 2025 15:57:41 +0200 Subject: [PATCH] go.mod+lnwire: bump TLV dep and fix MilliSatoshi Record In this commit, we update the `tlv` package version which includes type constraints on the `tlv.SizeBigSize` method parameter. This exposes a bug in the MilliSatoshi Record method which is fixed here. This was not caught in tests before since currently only our TLV encoding code makes use of this SizeFunc (so we would write 0 size to disk) but then when we read the bytes from disk and decode, we dont use the SizeFunc and our MilliSatoshi decode method makes direct use of the `tlv.DBigSize` function which _currently does not make use of the `l` length variable passed to it_. So it currently does correctly read the data. --- channeldb/migration/lnwire21/msat.go | 4 +++- go.mod | 2 +- go.sum | 4 ++-- lnwire/msat.go | 4 +++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/channeldb/migration/lnwire21/msat.go b/channeldb/migration/lnwire21/msat.go index 47c676285..3c3d85c33 100644 --- a/channeldb/migration/lnwire21/msat.go +++ b/channeldb/migration/lnwire21/msat.go @@ -55,8 +55,10 @@ func (m MilliSatoshi) String() string { // Record returns a TLV record that can be used to encode/decode a MilliSatoshi // to/from a TLV stream. func (m *MilliSatoshi) Record() tlv.Record { + msat := uint64(*m) + return tlv.MakeDynamicRecord( - 0, m, tlv.SizeBigSize(m), encodeMilliSatoshis, + 0, m, tlv.SizeBigSize(&msat), encodeMilliSatoshis, decodeMilliSatoshis, ) } diff --git a/go.mod b/go.mod index b1d4c9bfe..1dd775257 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/lightningnetwork/lnd/queue v1.1.1 github.com/lightningnetwork/lnd/sqldb v1.0.9 github.com/lightningnetwork/lnd/ticker v1.1.1 - github.com/lightningnetwork/lnd/tlv v1.3.0 + github.com/lightningnetwork/lnd/tlv v1.3.1 github.com/lightningnetwork/lnd/tor v1.1.6 github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 github.com/miekg/dns v1.1.43 diff --git a/go.sum b/go.sum index 5f195fa6e..cc17829d6 100644 --- a/go.sum +++ b/go.sum @@ -379,8 +379,8 @@ github.com/lightningnetwork/lnd/sqldb v1.0.9 h1:7OHi+Hui823mB/U9NzCdlZTAGSVdDCbj github.com/lightningnetwork/lnd/sqldb v1.0.9/go.mod h1:OG09zL/PHPaBJefp4HsPz2YLUJ+zIQHbpgCtLnOx8I4= github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM= github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA= -github.com/lightningnetwork/lnd/tlv v1.3.0 h1:exS/KCPEgpOgviIttfiXAPaUqw2rHQrnUOpP7HPBPiY= -github.com/lightningnetwork/lnd/tlv v1.3.0/go.mod h1:pJuiBj1ecr1WWLOtcZ+2+hu9Ey25aJWFIsjmAoPPnmc= +github.com/lightningnetwork/lnd/tlv v1.3.1 h1:o7CZg06y+rJZfUMAo0WzBLr0pgBWCzrt0f9gpujYUzk= +github.com/lightningnetwork/lnd/tlv v1.3.1/go.mod h1:pJuiBj1ecr1WWLOtcZ+2+hu9Ey25aJWFIsjmAoPPnmc= github.com/lightningnetwork/lnd/tor v1.1.6 h1:WHUumk7WgU6BUFsqHuqszI9P6nfhMeIG+rjJBlVE6OE= github.com/lightningnetwork/lnd/tor v1.1.6/go.mod h1:qSRB8llhAK+a6kaTPWOLLXSZc6Hg8ZC0mq1sUQ/8JfI= github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw= diff --git a/lnwire/msat.go b/lnwire/msat.go index 2966e5ddb..7d6d581e1 100644 --- a/lnwire/msat.go +++ b/lnwire/msat.go @@ -55,8 +55,10 @@ func (m MilliSatoshi) String() string { // Record returns a TLV record that can be used to encode/decode a MilliSatoshi // to/from a TLV stream. func (m *MilliSatoshi) Record() tlv.Record { + msat := uint64(*m) + return tlv.MakeDynamicRecord( - 0, m, tlv.SizeBigSize(m), encodeMilliSatoshis, + 0, m, tlv.SizeBigSize(&msat), encodeMilliSatoshis, decodeMilliSatoshis, ) }