-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pagination: add pagination to wallet transactions #8998
base: master
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Looks pretty good already, have a bit of early feedback.
lnwallet/interface.go
Outdated
@@ -393,7 +393,7 @@ type WalletController interface { | |||
// retrieve the transactions relevant to a specific account. When | |||
// empty, transactions of all wallet accounts are returned. | |||
ListTransactionDetails(startHeight, endHeight int32, | |||
accountFilter string) ([]*TransactionDetail, error) | |||
accountFilter string, indexOffset int, maxTnxs int) ([]*TransactionDetail, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: break before maxTnxs
to avoid too long line. Also, should be spelled maxTxns
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoiding a long line was why I named it maxTnx, but after breaking the line, I now renamed it to maxTransactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is still unaddressed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, I unintentionally addressed this in another commit
Thanks for taking a look. I will address the feedback you left. |
21fb0a8
to
a6609f5
Compare
I've addressed the feedback you left, added a few changes too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the extra parameters. Still needs a few updates before I'll start manual testing. But getting there 👍
@@ -6098,8 +6098,15 @@ func (r *rpcServer) GetTransactions(ctx context.Context, | |||
endHeight = req.EndHeight | |||
} | |||
|
|||
// To remain backward compatible, If the number of transactions was not | |||
// specified, then we'll default to returning the entire transactions | |||
if req.MaxTransactions == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be replaced by the use of a default value. See comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the default value of -1 when max_transactions is not specified from the CLI. However, for RPC, the default appears to be 0, so I am checking and replacing it with -1. I used this as a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, RPC users will have a default value of 0, makes sense then.
lnwallet/interface.go
Outdated
@@ -393,7 +393,7 @@ type WalletController interface { | |||
// retrieve the transactions relevant to a specific account. When | |||
// empty, transactions of all wallet accounts are returned. | |||
ListTransactionDetails(startHeight, endHeight int32, | |||
accountFilter string) ([]*TransactionDetail, error) | |||
accountFilter string, indexOffset int, maxTnxs int) ([]*TransactionDetail, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is still unaddressed?
31aed37
to
594f3f1
Compare
594f3f1
to
e4c47bb
Compare
@Abdulkbk, remember to re-request review from reviewers when ready |
e4c47bb
to
e5458b9
Compare
Approved CI run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! Did another pass, we're definitely getting closer.
return txDetails[indexOffset:end], nil | ||
txDetails = txDetails[indexOffset:end] | ||
|
||
return txDetails, uint64(firstIdx), uint64(lastIdx), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these two extra variables at all? Shouldn't firstIdx = indexOffset
and lastIdx = end-1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If my previous comment is correct, then this wouldn't be the case. However, I can replace the end
variable with lastIdx
, since they are the same.
lnwallet/btcwallet/btcwallet.go
Outdated
// If maxTransactions is set to -1, then we'll return all transactions | ||
// starting from the offset. | ||
if maxTransactions == -1 { | ||
lastIdx = len(txDetails) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. The last index is len(txDetails)-1
. But for the slice access ([a:b]
) it's correct, since b
is exclusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that first_index_offset
and last_index_offset
are 1-based indices. I am using the implementation found here as a reference, and it states here that the AddIndex starts from 1.
Also since the last_index_offset
will be used as the new index_offset
for the next call, wouldn't returning len(txDetails)-1
result in repeating the last transaction from the previous call as the first transaction in the new call? This is because the slice access [indexOffset: ...]
is inclusive.
rpcserver.go
Outdated
req.StartHeight, endHeight, req.Account, int(req.IndexOffset), | ||
int(req.MaxTransactions), | ||
) | ||
transactions, firstIdx, lastIdx, err := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same here re transactions -> txns
to optimize formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced "transactions" with "txns," but the line is still too long.
|
||
return nil, nil | ||
return nil, 0, 0, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes need to be in the previous commit to make that commit compile on its own.
A nice helper for making sure every commit compiles is:
git rebase -i origin/master --exec "make unit pkg=... case=_NONE_"
Which basically goes through each commit and compiles all unit tests (but doesn't run them), which causes all code to be compiled as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I squashed the last 2 commits and now they all compile successfully.
Nice helper 👍
This commit adds index_offset and max_transactions to the list of parameters passed during gettransactions call. index_offset specify transactions to skip and max_transactions the total transactions returned
e5458b9
to
c5dea0e
Compare
This commit modifies listtransactiondetails method definition to take in additional params: index_offset and maxTxn
Here we handle the offset and max_transactions parameters passed through lncli and RPC call.
81f9f33
to
36a59ed
Compare
Addition of first_index_offset and last_index_offset that can be used to seek further transactions from where you stopped in a previous call. We also add unit test to cover getting exactly how many transactions we requested for, and first and last index offsets are returned correctly.
36a59ed
to
650de87
Compare
fixes #4719
Change Description
This PR adds pagination to getting transactions RPC calls by introducing index_offset and max_transactions
to specify the number of transactions to skip and the maximum number of transactions to return respectively.
Steps to Test
Steps for reviewers to follow to test the change.
lncli listchaintxns -index_offset=n -max_transactions=m
where n and m are any numbersn
numbers of transactions and withm
transactionsPull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.