lnd
lnd copied to clipboard
Payment filtering by creation date
Fixes #6532
Add fields min_creation_time_ns and max_creation_time_ns to ListInvoiceRequest proto and add underlying support for them in the rpc server.
Worth noting, the implementation filters in linear time with respect to the total number of payments. This is because the bbolt backend stores payments by key order, and we use the payment hash as the key, so the order is effectively random. I looked into using the paymentsIndexBucket to do a binary search, but after digging around the code in channeldb, I don't think I can confidently say whether payment indices will always be in the same order as creation time. If anyone with more familiarity knows that a binary search could work, let me know and I'll implement that instead.
I looked into using the paymentsIndexBucket to do a binary search, but after digging around the code in channeldb, I don't think I can confidently say whether payment indices will always be in the same order as creation time. If anyone with more familiarity knows that a binary search could work, let me know and I'll implement that instead.
The paymentsIndexBucket is used effectively as a primary key, it gets incremented each time a new payment is added: https://github.com/lightningnetwork/lnd/blob/28ea2736a04566b06c38533e5e48e1b8d185a49b/channeldb/payment_control.go#L114-L121. However there may be some gaps in the sequence when we need to delete or retry a payment after a restart: https://github.com/lightningnetwork/lnd/blob/28ea2736a04566b06c38533e5e48e1b8d185a49b/channeldb/payment_control.go#L172-L183.
Ultimately you can expect the sequence number and also the timestamp to both be monotonically increasing (as new items are added).
What's the status here? Still ongoing? cc @tvolk131
@tvolk131, remember to re-request review from reviewers when ready
!lightninglabs-deploy mute 2022-Nov-01
@tvolk131, remember to re-request review from reviewers when ready
Replaced by #7159