From 7cd78afd1a08424038c1436059e7d392e5a79f66 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 4 Mar 2021 10:00:45 -0800 Subject: [PATCH 1/2] tlv/bench_test: check for errors in benchmarks --- tlv/bench_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tlv/bench_test.go b/tlv/bench_test.go index 132ef784..6233c62a 100644 --- a/tlv/bench_test.go +++ b/tlv/bench_test.go @@ -10,6 +10,7 @@ import ( "github.com/lightningnetwork/lnd/tlv" "github.com/lightningnetwork/lnd/watchtower/blob" "github.com/lightningnetwork/lnd/watchtower/wtwire" + "github.com/stretchr/testify/require" ) // CreateSessionTLV mirrors the wtwire.CreateSession message, but uses TLV for @@ -104,7 +105,7 @@ func BenchmarkEncodeCreateSession(t *testing.B) { for i := 0; i < t.N; i++ { err = m.Encode(ioutil.Discard, 0) } - _ = err + require.NoError(t, err) } // BenchmarkEncodeCreateSessionTLV benchmarks encoding of the TLV CreateSession. @@ -118,7 +119,7 @@ func BenchmarkEncodeCreateSessionTLV(t *testing.B) { for i := 0; i < t.N; i++ { err = m.Encode(ioutil.Discard) } - _ = err + require.NoError(t, err) } // BenchmarkDecodeCreateSession benchmarks encoding of the non-TLV @@ -127,18 +128,19 @@ func BenchmarkDecodeCreateSession(t *testing.B) { m := &wtwire.CreateSession{} var b bytes.Buffer - m.Encode(&b, 0) + err := m.Encode(&b, 0) + require.NoError(t, err) + r := bytes.NewReader(b.Bytes()) t.ReportAllocs() t.ResetTimer() - var err error for i := 0; i < t.N; i++ { r.Seek(0, 0) err = m.Decode(r, 0) } - _ = err + require.NoError(t, err) } // BenchmarkDecodeCreateSessionTLV benchmarks decoding of the TLV CreateSession. @@ -146,8 +148,9 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) { m := NewCreateSessionTLV() var b bytes.Buffer - var err error - m.Encode(&b) + err := m.Encode(&b) + require.NoError(t, err) + r := bytes.NewReader(b.Bytes()) t.ReportAllocs() @@ -157,5 +160,5 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) { r.Seek(0, 0) err = m.Decode(r) } - _ = err + require.NoError(t, err) } From ffddb85e9c75ce41f165fc3d6b79ac760ff06411 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 4 Mar 2021 10:01:14 -0800 Subject: [PATCH 2/2] tlv/bench_test: fix ESatPerKw, pass reference to uint64 --- tlv/bench_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tlv/bench_test.go b/tlv/bench_test.go index 6233c62a..132032b0 100644 --- a/tlv/bench_test.go +++ b/tlv/bench_test.go @@ -50,7 +50,8 @@ func DBlobType(r io.Reader, val interface{}, buf *[8]byte, l uint64) error { // ESatPerKW is an encoder for lnwallet.SatPerKWeight. func ESatPerKW(w io.Writer, val interface{}, buf *[8]byte) error { if v, ok := val.(*chainfee.SatPerKWeight); ok { - return tlv.EUint64(w, uint64(*v), buf) + v64 := uint64(*v) + return tlv.EUint64(w, &v64, buf) } return tlv.NewTypeForEncodingErr(val, "chainfee.SatPerKWeight") }