Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
18f03ec
sqldb: add index and comment to payment tables
ziggie1984 Oct 15, 2025
c908b52
multi: add relevant queries for QueryPayments implemenation
ziggie1984 Oct 12, 2025
52d466f
paymentsdb: add new internal error
ziggie1984 Oct 12, 2025
353160c
paymentsdb: implement QueryPayments for sql backend
ziggie1984 Oct 12, 2025
fc4ce67
paymentsdb: implement FetchPayment for sql backend
ziggie1984 Oct 15, 2025
0849296
docs: add release-notes
ziggie1984 Oct 12, 2025
ed5622c
sqldb: add queries for deleting a payment and attempts
ziggie1984 Oct 15, 2025
215490c
paymentsdb: implement DeletePayment for sql backend
ziggie1984 Oct 15, 2025
3a39bdc
paymentsdb: implement DeleteFailedAttempts for sql backend
ziggie1984 Oct 15, 2025
1aae195
sqldb+paymentsdb: add queries to insert all relavant data
ziggie1984 Oct 15, 2025
f6f2ee3
paymentsdb: implement InitPayment for sql backend
ziggie1984 Oct 15, 2025
53b47ea
paymentsdb: implement RegisterAttempt for sql backend
ziggie1984 Oct 15, 2025
b3f3627
paymentsdb: implement SettleAttempt for sql backend
ziggie1984 Oct 15, 2025
6145682
docs: add release-notes
ziggie1984 Oct 15, 2025
1005816
paymentsdb: add harness to run payment db agnostic tests
ziggie1984 Oct 15, 2025
3b1dd2a
paymentsdb: refactor test helpers
ziggie1984 Oct 15, 2025
3362dce
paymentsdb: make QueryPayments test db agnostic
ziggie1984 Oct 15, 2025
b43f2c8
multi: implement Fail method for sql backend
ziggie1984 Oct 15, 2025
39a9aaa
paymentsdb: implement DeletePayments for sql backend
ziggie1984 Oct 15, 2025
4e0c0fe
paymentsdb: implement FailAttempt for sql backend
ziggie1984 Oct 15, 2025
2c806ea
paymentsdb: implement FetchInFlightPayments for sql backend
ziggie1984 Oct 15, 2025
d245664
paymentsdb: fix test case before testing sql backend
ziggie1984 Oct 15, 2025
492a34f
paymentsdb: remove kvstore from sql db implementation
ziggie1984 Oct 15, 2025
4f7c9bd
paymentsdb: test all db agnostic tests for all backends
ziggie1984 Oct 15, 2025
9bb4fef
itest: fix list_payments accuracy edge case
ziggie1984 Oct 15, 2025
a8d7e85
docs: add release-notes
ziggie1984 Oct 16, 2025
cfc8277
mulit: fix linter
ziggie1984 Oct 16, 2025
192302e
paymentsdb: add firstcustom records to unit tests
ziggie1984 Oct 17, 2025
bdbcc54
paymentsdb: add more comments
ziggie1984 Oct 17, 2025
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
6 changes: 6 additions & 0 deletions docs/release-notes/release-notes-0.21.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
refacotor the payment related LND code to make it more modular.
* Implement the SQL backend for the [payments
database](https://github.com/lightningnetwork/lnd/pull/9147)
* Implement query methods for the [payments db
SQL Backend](https://github.com/lightningnetwork/lnd/pull/10287)
* Implement insert methods for the [payments db
SQL Backend](https://github.com/lightningnetwork/lnd/pull/10291)
* 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
2 changes: 2 additions & 0 deletions lnrpc/routerrpc/router_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,8 @@ 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 depict the last htlc preimage.
preimage = htlc.Settle.Preimage
fee += htlc.Route.TotalFees()
}
Expand Down
4 changes: 4 additions & 0 deletions payments/db/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ var (
// NOTE: Only used for the kv backend.
ErrNoSequenceNrIndex = errors.New("payment sequence number index " +
"does not exist")

// errMaxPaymentsReached is used internally to signal that the maximum
// number of payments has been reached during a paginated query.
errMaxPaymentsReached = errors.New("max payments reached")
)
Loading
Loading