lnd icon indicating copy to clipboard operation
lnd copied to clipboard

Payment filtering by creation date

Open tvolk131 opened this issue 3 years ago • 4 comments

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.

tvolk131 avatar May 15 '22 19:05 tvolk131

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).

Roasbeef avatar Jun 06 '22 18:06 Roasbeef

What's the status here? Still ongoing? cc @tvolk131

yyforyongyu avatar Aug 02 '22 10:08 yyforyongyu

@tvolk131, remember to re-request review from reviewers when ready

lightninglabs-deploy avatar Sep 13 '22 13:09 lightninglabs-deploy

!lightninglabs-deploy mute 2022-Nov-01

yyforyongyu avatar Oct 11 '22 16:10 yyforyongyu

@tvolk131, remember to re-request review from reviewers when ready

lightninglabs-deploy avatar Nov 15 '22 01:11 lightninglabs-deploy

Replaced by #7159

yyforyongyu avatar Nov 15 '22 18:11 yyforyongyu