From 0b33b396c84dca5038466d2b59f2fb61499ff5b1 Mon Sep 17 00:00:00 2001 From: Violet Guo Date: Mon, 18 Mar 2024 17:16:37 -0400 Subject: [PATCH 1/4] channeldb: add creation ts start end check in query all Check for uninit int with 0 instead of ! --- channeldb/payments.go | 3 ++- channeldb/payments_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/channeldb/payments.go b/channeldb/payments.go index 15bcd83424..49c64f698e 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -596,7 +596,8 @@ func (d *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { // Counting the total number of payments is expensive, since we // literally have to traverse the cursor linearly, which can // take quite a while. So it's an optional query parameter. - if query.CountTotal { + if query.CountTotal && query.CreationDateStart != 0 && + query.CreationDateEnd != 0 { var ( totalPayments uint64 err error diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index 769f4cc77f..fcadbeab57 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -472,6 +472,17 @@ func TestQueryPayments(t *testing.T) { lastIndex: 5, expectedSeqNrs: []uint64{3, 4, 5}, }, + { + name: "query max transcation with start and end creation time", + query: PaymentsQuery{ + CreationDateStart: 3, + CreationDateEnd: 5, + CountTotal: true, + }, + firstIndex: 3, + lastIndex: 5, + expectedSeqNrs: []uint64{3, 4, 5}, + }, } for _, tt := range tests { From a2b49675887bb1ee40692d12d3a8135d8205b2d9 Mon Sep 17 00:00:00 2001 From: Violet Guo Date: Wed, 20 Mar 2024 17:16:42 -0400 Subject: [PATCH 2/4] docs: Reformat w linter, add RELEASE note --- channeldb/payments_test.go | 2 +- docs/release-notes/release-notes-0.18.0.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index fcadbeab57..a2be6403e8 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -477,7 +477,7 @@ func TestQueryPayments(t *testing.T) { query: PaymentsQuery{ CreationDateStart: 3, CreationDateEnd: 5, - CountTotal: true, + CountTotal: true, }, firstIndex: 3, lastIndex: 5, diff --git a/docs/release-notes/release-notes-0.18.0.md b/docs/release-notes/release-notes-0.18.0.md index d7a4728139..f4926f6e5f 100644 --- a/docs/release-notes/release-notes-0.18.0.md +++ b/docs/release-notes/release-notes-0.18.0.md @@ -21,6 +21,11 @@ - [Contributors (Alphabetical Order)](#contributors-alphabetical-order) # Bug Fixes +* [Fix a bug](https://github.com/lightningnetwork/lnd/pull/8565) where + `listpayments --count_total_payments` flag disregarded `--creation_date_start` + and `--creation_date_end`. The payments between the dates would be queried + instead of the total payments if the dates were supplied. + * [Fix a bug](https://github.com/lightningnetwork/lnd/pull/8097) where `sendcoins` command with `--sweepall` flag would not show the correct amount. From 21832d4158f556774fd2cfacac77c13cac9fc366 Mon Sep 17 00:00:00 2001 From: Violet Guo Date: Wed, 20 Mar 2024 19:23:14 -0400 Subject: [PATCH 3/4] channeldb: Add CountTotal to all test cases - should be 0 for everyone except the query with count total set to true --- channeldb/payments.go | 6 +++-- channeldb/payments_test.go | 54 +++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/channeldb/payments.go b/channeldb/payments.go index 49c64f698e..80a2271949 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -596,8 +596,10 @@ func (d *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { // Counting the total number of payments is expensive, since we // literally have to traverse the cursor linearly, which can // take quite a while. So it's an optional query parameter. - if query.CountTotal && query.CreationDateStart != 0 && - query.CreationDateEnd != 0 { + // It will only take effect if CreationDateStart and + // CreationDateEnd are not specified. + if query.CountTotal && query.CreationDateStart == 0 && + query.CreationDateEnd == 0 { var ( totalPayments uint64 err error diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index a2be6403e8..869cc9fb4b 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -247,6 +247,10 @@ func TestQueryPayments(t *testing.T) { // expectedSeqNrs contains the set of sequence numbers we expect // our query to return. expectedSeqNrs []uint64 + // totalCount corresponds to the PaymentsResponse's TotalCount + // This will only be set if the + // CountTotal field in the query was set to true. + totalCount uint64 }{ { name: "IndexOffset at the end of the payments range", @@ -259,6 +263,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 0, lastIndex: 0, expectedSeqNrs: nil, + totalCount: 0, }, { name: "query in forwards order, start at beginning", @@ -271,6 +276,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 1, lastIndex: 3, expectedSeqNrs: []uint64{1, 3}, + totalCount: 0, }, { name: "query in forwards order, start at end, overflow", @@ -283,6 +289,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 7, lastIndex: 7, expectedSeqNrs: []uint64{7}, + totalCount: 0, }, { name: "start at offset index outside of payments", @@ -307,6 +314,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 5, lastIndex: 7, expectedSeqNrs: []uint64{5, 6, 7}, + totalCount: 0, }, { name: "start at offset index outside of payments, " + @@ -320,6 +328,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 6, lastIndex: 7, expectedSeqNrs: []uint64{6, 7}, + totalCount: 0, }, { name: "query in reverse order, start at end", @@ -332,6 +341,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 6, lastIndex: 7, expectedSeqNrs: []uint64{6, 7}, + totalCount: 0, }, { name: "query in reverse order, starting in middle", @@ -344,6 +354,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 1, lastIndex: 3, expectedSeqNrs: []uint64{1, 3}, + totalCount: 0, }, { name: "query in reverse order, starting in middle, " + @@ -357,6 +368,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 1, lastIndex: 3, expectedSeqNrs: []uint64{1, 3}, + totalCount: 0, }, { name: "all payments in reverse, order maintained", @@ -369,6 +381,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 1, lastIndex: 7, expectedSeqNrs: []uint64{1, 3, 4, 5, 6, 7}, + totalCount: 0, }, { name: "exclude incomplete payments", @@ -381,6 +394,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 7, lastIndex: 7, expectedSeqNrs: []uint64{7}, + totalCount: 0, }, { name: "query payments at index gap", @@ -405,6 +419,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 1, lastIndex: 1, expectedSeqNrs: []uint64{1}, + totalCount: 0, }, { name: "query payments reverse on index gap", @@ -417,6 +432,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 1, lastIndex: 1, expectedSeqNrs: []uint64{1}, + totalCount: 0, }, { name: "query payments forward on index gap", @@ -429,6 +445,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 3, lastIndex: 4, expectedSeqNrs: []uint64{3, 4}, + totalCount: 0, }, { name: "query in forwards order, with start creation " + @@ -443,6 +460,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 5, lastIndex: 6, expectedSeqNrs: []uint64{5, 6}, + totalCount: 0, }, { name: "query in forwards order, with start creation " + @@ -457,6 +475,7 @@ func TestQueryPayments(t *testing.T) { firstIndex: 7, lastIndex: 7, expectedSeqNrs: []uint64{7}, + totalCount: 0, }, { name: "query with start and end creation time", @@ -471,17 +490,33 @@ func TestQueryPayments(t *testing.T) { firstIndex: 3, lastIndex: 5, expectedSeqNrs: []uint64{3, 4, 5}, + totalCount: 0, }, { - name: "query max transcation with start and end creation time", + name: "query count total with start and end creation", query: PaymentsQuery{ - CreationDateStart: 3, - CreationDateEnd: 5, + IndexOffset: 0, + MaxPayments: 2, + Reversed: true, + IncludeIncomplete: true, + CreationDateStart: 5, + CreationDateEnd: 6, CountTotal: true, }, - firstIndex: 3, - lastIndex: 5, - expectedSeqNrs: []uint64{3, 4, 5}, + firstIndex: 5, + lastIndex: 6, + expectedSeqNrs: []uint64{5, 6}, + totalCount: 0, + }, + { + name: "query count total only", + query: PaymentsQuery{ + CountTotal: true, + }, + firstIndex: 0, + lastIndex: 0, + expectedSeqNrs: nil, + totalCount: 6, }, } @@ -591,6 +626,13 @@ func TestQueryPayments(t *testing.T) { len(tt.expectedSeqNrs), len(querySlice.Payments)) } + if tt.totalCount != querySlice.TotalCount { + t.Errorf("Total Count does not match "+ + "expected total count. Want %d, got %d", + tt.totalCount, + querySlice.TotalCount) + } + for i, seqNr := range tt.expectedSeqNrs { q := querySlice.Payments[i] if seqNr != q.SequenceNum { From 2c8d039bff30ccc9c1fee622e579e9ed9e13d98c Mon Sep 17 00:00:00 2001 From: Violet Guo Date: Thu, 21 Mar 2024 18:10:35 -0400 Subject: [PATCH 4/4] multi: Fix the linter whitespace for multi line --- channeldb/payments.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/channeldb/payments.go b/channeldb/payments.go index 80a2271949..2a7ef3c455 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -596,10 +596,10 @@ func (d *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { // Counting the total number of payments is expensive, since we // literally have to traverse the cursor linearly, which can // take quite a while. So it's an optional query parameter. - // It will only take effect if CreationDateStart and - // CreationDateEnd are not specified. if query.CountTotal && query.CreationDateStart == 0 && query.CreationDateEnd == 0 { + // It will only take effect if CreationDateStart and + // CreationDateEnd are not specified. var ( totalPayments uint64 err error