-
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
Modified the listchanneltxn subcommand #7496
Modified the listchanneltxn subcommand #7496
Conversation
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.
Nice work @Chinwendu20 🎉
I left some comments, let me know what you think about them. One thing we should avoid is breaking changes in the API. Until now we were ordering by NumConfirmations
so from newest to oldest (non-confirmed being the newest ones). We should keep that behaivour and use the --reverse
to sort them from older to newer 👌
lnrpc/lightning.proto
Outdated
@@ -746,6 +746,11 @@ message GetTransactionsRequest { | |||
|
|||
// An optional filter to only include transactions relevant to an account. | |||
string account = 3; | |||
|
|||
// It modifies the way the transactions are listed, in reverse order i.e. |
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.
format: it fits in two lines
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.
Okay thank you. I will make it fit in two lines.
lnrpc/rpc_utils.go
Outdated
@@ -76,24 +76,25 @@ func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction { | |||
} | |||
|
|||
// RPCTransactionDetails returns a set of rpc transaction details. | |||
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail) *TransactionDetails { | |||
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail, reverse bool) *TransactionDetails { |
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.
what do you think about not adding the extra arg here so we do not have to hardcode the param in other calls and reversing the array, if needed, directly in the GetTransactions
grpc implementation?
end_height := ctx.Int64("end_height") | ||
|
||
if start_height > end_height { | ||
|
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.
formatt: extra line
cmd/lncli/commands.go
Outdated
less than the start_height, transactions will be queried in reverse. | ||
To get all transactions until the chain tip, including unconfirmed | ||
transactions (identifiable with BlockHeight=0), set end_height to -1. | ||
block range over which to query for transactions. The value of the start_height flag must |
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 we are giving too much information here. We can summarize it with something like
...
block range over which to query for transactions. By default the result is sorted by oldest first.
Use the reverse flag to invert the order. To get all transactions until the chain tip, including
unconfirmed transactions (identifiable with BlockHeight=0), set end_height to -1. Non-confirmed
transactions considered the newest.
cmd/lncli/commands.go
Outdated
start_height := ctx.Int64("start_height") | ||
end_height := ctx.Int64("end_height") | ||
|
||
if (start_height > end_height) && |
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 logic looks like a good candidate for a switch statement. What do you think?
switch {
case ctx.IsSet("start_height") && ctx.IsSet("end_height"):
start_height := ctx.Int64("start_height")
end_height := ctx.Int64("end_height")
if end_height == -1 && start_height != 0 {
return errors.New("...")
}
if end_height != -1 && start_height > end_height {
return errors.New("...")
}
req.StartHeight = int32(start_height)
req.EndHeight = int32(end_height)
case ctx.IsSet("start_height"):
req.StartHeight = int32(ctx.Int64("start_height"))
case ctx.IsSet("end_height"):
req.EndHeight = int32(ctx.Int64("end_height"))
}
It is really important that this check is replicated in the server side. If you follow the full flow the btcwallet library used for checking the range will return the result reversed if start_height > end_height
starting from end to start. Because this is something that we do not want to expose in the API (we have the --reverse
flag for that) we need to catch it before processing the range.
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 logic looks like a good candidate for a switch statement. What do you think?
switch { case ctx.IsSet("start_height") && ctx.IsSet("end_height"): start_height := ctx.Int64("start_height") end_height := ctx.Int64("end_height") if end_height == -1 && start_height != 0 { return errors.New("...") } if end_height != -1 && start_height > end_height { return errors.New("...") } req.StartHeight = int32(start_height) req.EndHeight = int32(end_height) case ctx.IsSet("start_height"): req.StartHeight = int32(ctx.Int64("start_height")) case ctx.IsSet("end_height"): req.EndHeight = int32(ctx.Int64("end_height")) }
It is really important that this check is replicated in the server side. If you follow the full flow the btcwallet library used for checking the range will return the result reversed if
start_height > end_height
starting from end to start. Because this is something that we do not want to expose in the API (we have the--reverse
flag for that) we need to catch it before processing the range.
Thank you so much. I would work with the switch statement but are you saying that I should make some changes in the btcwallet as well or write your statement below as comments
lnrpc/rpc_utils.go
Outdated
// follow the most recently set of confirmed transactions. If we sort | ||
// by height, unconfirmed transactions will follow our oldest | ||
// transactions, because they have lower block heights. | ||
sort.Slice(txDetails.Transactions, func(i, j int) bool { |
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 we can leave this here but modify it if needed by the caller.
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 okay thanks I will move it back there
rpcserver.go
Outdated
return lnrpc.RPCTransactionDetails(transactions), nil | ||
txDetails := lnrpc.RPCTransactionDetails(transactions) | ||
|
||
if !req.Reverse { |
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 we leave the previous logic in RPCTransactionDetails
, we can do the opposite sorting here only when we need it
txs := lnrpc.RPCTransactionDetails(transactions)
if !req.Reverse {
for i, j := 0, len(txs)-1; i < j; i, j = i+1, j-1 {
txs[i], txs[j] = txs[j], txs[i]
}
}
return txs, 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.
Okay thank you. I will use this.
cmd/lncli/commands.go
Outdated
@@ -1798,19 +1798,26 @@ var listChainTxnsCommand = cli.Command{ | |||
"until the chain tip, including unconfirmed, " + | |||
"set this value to -1", | |||
}, | |||
cli.BoolFlag{ | |||
Name: "reverse", | |||
Usage: "It modifies the way the transactions are listed, " + |
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: If true, returned transactions will be sorted from oldest to newest
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.
Perfect @Chinwendu20, I think we are getting close 🎉
There are some extra spaces, comments that do not end with .
, etc... You can check if the code follows the guidelines here
We also try to split the commit in individual logic units. In this case I think that what makes sense is 3 commits:
- Add rpc fields
- Handle
req.reverse
field in the rpcserver.go - Add
--reverse
flag to the cli
Thanks would this involve amending existing commit messages or would I have to take Git HEAD to the tip before I started making changes then make all the changes one after the other, to get the commit to look like that |
In this case I would take the second approach. You can reset your head while keeping the changes ( When the log is in good shape remember to add one last commit updating the release notes (you can check other PRs to see how it's done) |
ok working on it @positiveblue |
8390a5d
to
64e934c
Compare
I have made the change @positiveblue |
@Chinwendu20 - are you planning to continue work on this? if so, please click the "re-request" review button :) |
Yes, thank you. Just seeing that there is a conflict. I will fix it and re-request a review @ellemouton |
64e934c
to
688494e
Compare
@Chinwendu20 - it seems that not all the comments left in the previous review have been addressed? |
Thanks please do you know how I can reply to those reviews. Last time I did that it showed pending and @positiveblue could not see it. |
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.
https://github.com/lightningnetwork/lnd/pull/7496/files#r1134697179
Thanks you so much for the review. It is actually the other way around, if true, returned transactions are returned first
Okay thank you |
688494e
to
598dd2b
Compare
Hello @positiveblue please I have made changes to this PR do you mind reviewing it again? |
Reverting the lnrpc changes... hold on |
598dd2b
to
fe630db
Compare
All done. Ready for review. |
fe630db
to
1f8d4e9
Compare
Signed-off-by: Ononiwu Maureen <[email protected]>
1f8d4e9
to
dc32629
Compare
Hello, I have added the release note and fixed the lint error, do you mind rerunning the workflow? |
- Added reverse flag to listchaintxns command. - Listchaintxns command returns error when start_height is less than end_height if end_height is not -1. - Listchaintxns command returns error when start_height is not zero but end_height is -1. Signed-off-by: Ononiwu Maureen <[email protected]>
Signed-off-by: Ononiwu Maureen <[email protected]>
Signed-off-by: Ononiwu Maureen <[email protected]>
dc32629
to
8b98851
Compare
@Chinwendu20 Is there anything I could help with so that we could get this PR? The CI regards Linting the code seems passed. |
@Chinwendu20 I had a similar issue regards running the
|
Thanks @mohamedawnallah. I think I was waiting for review here? |
@positiveblue: review reminder |
Closing due to inactivity |
6 similar comments
Closing due to inactivity |
Closing due to inactivity |
Closing due to inactivity |
Closing due to inactivity |
Closing due to inactivity |
Closing due to inactivity |
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 (
|
Change Description
start_height must be <= end_height, error otherwise
transactions are returned in direct order (oldest first)
an additional flag --reverse is added to change the order (--reverse true, recent first)
Modified docs by modifying comments in the listchaintxn description command
Steps to Test
Carry out a debug installation using this command:
make && make install
Test command:
./lncli-debug --no-macaroons listchaintxns --start_height 200 --end_height 7000| grep block_height
Expected outcome: transactions are returned in the order, oldest first
./lncli-debug --no-macaroons listchaintxns --start_height 7000 --end_height 200| grep block_height
Expected outcome: Error
./lncli-debug --no-macaroons listchaintxns --start_height 200 --end_height 7000 --reverse| grep block_height
Expected outcome: transactions are returned in the reverse order, newest first
Change after review
Test command:
./lncli-debug --no-macaroons listchaintxns --start_height 200 --end_height 7000 --reverse| grep block_height
Expected outcome: transactions are returned in the order, oldest first
./lncli-debug --no-macaroons listchaintxns --start_height 7000 --end_height 200| grep block_height
Expected outcome: Error
./lncli-debug --no-macaroons listchaintxns --start_height 200 --end_height 7000| grep block_height
Expected outcome: transactions are returned in the order, newest first