Skip to content

Commit ad38ed7

Browse files
committed
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.
1 parent 8b413e8 commit ad38ed7

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

channeldb/migration/lnwire21/msat.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ func (m MilliSatoshi) String() string {
5555
// Record returns a TLV record that can be used to encode/decode a MilliSatoshi
5656
// to/from a TLV stream.
5757
func (m *MilliSatoshi) Record() tlv.Record {
58+
msat := uint64(*m)
59+
5860
return tlv.MakeDynamicRecord(
59-
0, m, tlv.SizeBigSize(m), encodeMilliSatoshis,
61+
0, m, tlv.SizeBigSize(&msat), encodeMilliSatoshis,
6062
decodeMilliSatoshis,
6163
)
6264
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
github.com/lightningnetwork/lnd/queue v1.1.1
4545
github.com/lightningnetwork/lnd/sqldb v1.0.9
4646
github.com/lightningnetwork/lnd/ticker v1.1.1
47-
github.com/lightningnetwork/lnd/tlv v1.3.0
47+
github.com/lightningnetwork/lnd/tlv v1.3.1
4848
github.com/lightningnetwork/lnd/tor v1.1.6
4949
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796
5050
github.com/miekg/dns v1.1.43

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ github.com/lightningnetwork/lnd/sqldb v1.0.9 h1:7OHi+Hui823mB/U9NzCdlZTAGSVdDCbj
379379
github.com/lightningnetwork/lnd/sqldb v1.0.9/go.mod h1:OG09zL/PHPaBJefp4HsPz2YLUJ+zIQHbpgCtLnOx8I4=
380380
github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM=
381381
github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA=
382-
github.com/lightningnetwork/lnd/tlv v1.3.0 h1:exS/KCPEgpOgviIttfiXAPaUqw2rHQrnUOpP7HPBPiY=
383-
github.com/lightningnetwork/lnd/tlv v1.3.0/go.mod h1:pJuiBj1ecr1WWLOtcZ+2+hu9Ey25aJWFIsjmAoPPnmc=
382+
github.com/lightningnetwork/lnd/tlv v1.3.1 h1:o7CZg06y+rJZfUMAo0WzBLr0pgBWCzrt0f9gpujYUzk=
383+
github.com/lightningnetwork/lnd/tlv v1.3.1/go.mod h1:pJuiBj1ecr1WWLOtcZ+2+hu9Ey25aJWFIsjmAoPPnmc=
384384
github.com/lightningnetwork/lnd/tor v1.1.6 h1:WHUumk7WgU6BUFsqHuqszI9P6nfhMeIG+rjJBlVE6OE=
385385
github.com/lightningnetwork/lnd/tor v1.1.6/go.mod h1:qSRB8llhAK+a6kaTPWOLLXSZc6Hg8ZC0mq1sUQ/8JfI=
386386
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=

lnwire/msat.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ func (m MilliSatoshi) String() string {
5555
// Record returns a TLV record that can be used to encode/decode a MilliSatoshi
5656
// to/from a TLV stream.
5757
func (m *MilliSatoshi) Record() tlv.Record {
58+
msat := uint64(*m)
59+
5860
return tlv.MakeDynamicRecord(
59-
0, m, tlv.SizeBigSize(m), encodeMilliSatoshis,
61+
0, m, tlv.SizeBigSize(&msat), encodeMilliSatoshis,
6062
decodeMilliSatoshis,
6163
)
6264
}

0 commit comments

Comments
 (0)