Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/release-notes/release-notes-0.21.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
SQL Backend](https://github.com/lightningnetwork/lnd/pull/10291)
* Implement third(final) Part of SQL backend [payment
functions](https://github.com/lightningnetwork/lnd/pull/10368)

* Finalize SQL payments implementation [enabling unit and itests
for SQL backend](https://github.com/lightningnetwork/lnd/pull/10292)

## Code Health

Expand Down
59 changes: 43 additions & 16 deletions itest/lnd_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,61 +504,86 @@ func testListPayments(ht *lntest.HarnessTest) {
expected bool
}

// Create test cases to check the timestamp filters.
createCases := func(createTimeSeconds uint64) []testCase {
// Create test cases with proper rounding for start and end dates.
createCases := func(startTimeSeconds,
endTimeSeconds uint64) []testCase {

return []testCase{
{
// Use a start date same as the creation date
// should return us the item.
// (truncated) should return us the item.
name: "exact start date",
startDate: createTimeSeconds,
startDate: startTimeSeconds,
expected: true,
},
{
// Use an earlier start date should return us
// the item.
name: "earlier start date",
startDate: createTimeSeconds - 1,
startDate: startTimeSeconds - 1,
expected: true,
},
{
// Use a future start date should return us
// nothing.
name: "future start date",
startDate: createTimeSeconds + 1,
startDate: startTimeSeconds + 1,
expected: false,
},
{
// Use an end date same as the creation date
// should return us the item.
// (ceiling) should return us the item.
name: "exact end date",
endDate: createTimeSeconds,
endDate: endTimeSeconds,
expected: true,
},
{
// Use an end date in the future should return
// us the item.
name: "future end date",
endDate: createTimeSeconds + 1,
endDate: endTimeSeconds + 1,
expected: true,
},
{
// Use an earlier end date should return us
// nothing.
name: "earlier end date",
endDate: createTimeSeconds - 1,
name: "earlier end date",
// The native sql backend has a higher
// precision than the kv backend, the native sql
// backend uses microseconds, the kv backend
// when filtering uses seconds so we need to
// subtract 2 seconds to ensure the payment is
// not included.
// We could also truncate before inserting
// into the sql db but I rather relax this test
// here.
endDate: endTimeSeconds - 2,
expected: false,
},
}
}

// Get the payment creation time in seconds.
paymentCreateSeconds := uint64(
p.CreationTimeNs / time.Second.Nanoseconds(),
// Get the payment creation time in seconds, using different approaches
// for start and end date comparisons to avoid rounding issues.
creationTime := time.Unix(0, p.CreationTimeNs)

// For start date comparisons: use truncation (floor) to include
// payments from the beginning of that second.
paymentCreateSecondsStart := uint64(
creationTime.Truncate(time.Second).Unix(),
)

// For end date comparisons: use ceiling to include payments up to the
// end of that second.
paymentCreateSecondsEnd := uint64(
(p.CreationTimeNs + time.Second.Nanoseconds() - 1) /
time.Second.Nanoseconds(),
)

// Create test cases from the payment creation time.
testCases := createCases(paymentCreateSeconds)
testCases := createCases(
paymentCreateSecondsStart, paymentCreateSecondsEnd,
)

// We now check the timestamp filters in `ListPayments`.
for _, tc := range testCases {
Expand All @@ -578,7 +603,9 @@ func testListPayments(ht *lntest.HarnessTest) {
}

// Create test cases from the invoice creation time.
testCases = createCases(uint64(invoice.CreationDate))
testCases = createCases(
uint64(invoice.CreationDate), uint64(invoice.CreationDate),
)

// We now do the same check for `ListInvoices`.
for _, tc := range testCases {
Expand Down
4 changes: 4 additions & 0 deletions lnrpc/routerrpc/router_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,10 @@ func (r *RouterBackend) MarshallPayment(payment *paymentsdb.MPPayment) (
// If any of the htlcs have settled, extract a valid
// preimage.
if htlc.Settle != nil {
// For AMP payments all hashes will be different so we
// will only show the last htlc preimage, this is a
// current limitation for AMP payments because for
// MPP payments all hashes are the same.
preimage = htlc.Settle.Preimage
fee += htlc.Route.TotalFees()
}
Expand Down
Loading
Loading