Skip to content
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

rpc: add gettx command to walletrpc #7654

Merged
merged 3 commits into from Dec 11, 2023

Conversation

ErikEk
Copy link
Contributor

@ErikEk ErikEk commented May 1, 2023

Adds a new endpoint 'gettx' to the wallet sub-server.
Fixes #7323.
The btcwallet package has been updated for this endpoint.
This will only fetch transactions from the wallet db and not from a btc node in accordance with the issue description.(https://github.com/lightningnetwork/lnd/blob/04314d3254a9380d51935125869b23ee37240dfe/lnrpc/lightning.proto#L41-L44).
A test is added to lnwallet.

@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch from 94bbc0a to 020621b Compare May 1, 2023 08:08
@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 4 times, most recently from bed1939 to eb972b5 Compare May 4, 2023 08:52
@ErikEk ErikEk marked this pull request as ready for review May 4, 2023 08:53
@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 7 times, most recently from c07edec to 8e3f1f1 Compare May 13, 2023 07:59
@ErikEk ErikEk changed the title [WIP] rpc: add txhash parameter to listchaintxns rpc: add txhash parameter to listchaintxns May 18, 2023
@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 2 times, most recently from b6a54fe to 09b9a51 Compare May 22, 2023 06:45
@guggero guggero self-requested a review May 22, 2023 08:18
Copy link
Collaborator

@guggero guggero left a 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. This will be very useful!

I think this can be simplified quite a bit by just using a filter function. If the reason for the duplicated code is to improve performance by not reading everything from disk an then filtering in memory, I think we should instead implement the filter in btcwallet itself. Such an (optional/nilable) filter function could also be used for other stuff in the future.

cmd/lncli/commands.go Outdated Show resolved Hide resolved
cmd/lncli/commands.go Outdated Show resolved Hide resolved
lnrpc/lightning.proto Outdated Show resolved Hide resolved
lnrpc/lightning.proto Outdated Show resolved Hide resolved
lnrpc/walletrpc/walletkit_server.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
lnwallet/test/test_interface.go Outdated Show resolved Hide resolved
lnwallet/test/test_interface.go Outdated Show resolved Hide resolved
lnwallet/test/test_interface.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour rpc Related to the RPC interface labels May 23, 2023
@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 4 times, most recently from 71d585a to 674e85c Compare June 6, 2023 02:58
@ErikEk
Copy link
Contributor Author

ErikEk commented Jun 6, 2023

@guggero Everything you asked for should be implemented now. Unfortunately we do have a dual array struct for "mined" and "unmined" transactions in the btcwallet package, so I did implement the filter in lnd instead. The lnwallet test commit is removed since this now uses a filter instead of fetching specific transactions.

@guggero guggero self-requested a review June 6, 2023 07:03
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good, thanks a lot for the update!
Just a bunch of nits, will run a couple of manual tests when addressed.

cmd/lncli/commands.go Outdated Show resolved Hide resolved
lnrpc/lightning.proto Outdated Show resolved Hide resolved
lnwallet/btcwallet/btcwallet.go Outdated Show resolved Hide resolved
lntest/mock/walletcontroller.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/btcwallet.go Outdated Show resolved Hide resolved
@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 2 times, most recently from 213629b to 4ae1e14 Compare October 31, 2023 10:44
@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 3 times, most recently from 2ffd56a to b6842d3 Compare October 31, 2023 20:33
cmd/lncli/walletrpc_active.go Outdated Show resolved Hide resolved
cmd/lncli/walletrpc_active.go Outdated Show resolved Hide resolved
docs/release-notes/release-notes-0.18.0.md Outdated Show resolved Hide resolved
lnwallet/test/test_interface.go Show resolved Hide resolved
cmd/lncli/walletrpc_active.go Outdated Show resolved Hide resolved
@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 2 times, most recently from 4265a45 to b21c6e6 Compare November 6, 2023 21:23
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit and needs a rebase, otherwise LGTM🙏

cmd/lncli/walletrpc_active.go Show resolved Hide resolved
&walletrpc.GetTransactionRequest{
TxHash: targetTx,
})
require.NotNil(ht, txResp, "target tx %v not found", targetTx)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to use require.NotNilf to format the string properly.

itest/lnd_misc_test.go Show resolved Hide resolved
lnwallet/test/test_interface.go Show resolved Hide resolved
@ErikEk
Copy link
Contributor Author

ErikEk commented Nov 15, 2023

@yyforyongyu Added require.NotNilf and rebased. Thanks for the review.

Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM🙏

@lightninglabs-deploy
Copy link

@guggero: review reminder
@ErikEk, remember to re-request review from reviewers when ready

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice and super close, just some last small requests.

@@ -538,6 +543,11 @@ message ListAddressesResponse {
repeated AccountWithAddresses account_with_addresses = 1;
}

message GetTransactionRequest {
// Transaction hash.
string tx_hash = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since technically this is the TXID (which is the by-reversed hash of the transaction), this should either be called txid if it's a string, or be turned into a bytes field which then expects the non-reversed bytes of the transaction hash.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for renaming to txid and leaving the string type, since that makes the REST call easier as well, since bytes are a bit harder to handle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


txDetail, err := unminedTransactionsToDetail(tx.Summary, b.netParams)
if err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could either add some additional error context here with fmt.Errorf(). If not, then I guess we can directly do return unminedTransactionsToDetail(...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will just return it then.

txResp := ainz.RPC.GetTransaction(
&walletrpc.GetTransactionRequest{
TxHash: targetTx,
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: closing parenthesis on new line.


txDetails, err := bob.GetTransactionDetails(&txHash)
require.NoError(t, err, "unable to receive transaction details")
require.Equal(t, txDetails.Value, amountSats, "expected transaction "+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are formatting placeholders in the last argument, but Equalf() wasn't used. IMO this can just be require.Equal(t, txDetails.Value, amountSats, "tx value") since the required library will produce a nice error message already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guggero thanks for the review. Will finish it soon.

@ErikEk ErikEk force-pushed the listchaintxns-add-txhash branch 2 times, most recently from cb48f3d to f9376f6 Compare December 10, 2023 21:08
@ErikEk
Copy link
Contributor Author

ErikEk commented Dec 10, 2023

Code has been updated and rebased. @guggero: Ready for another review.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM 🎉

@guggero guggero requested review from Roasbeef and removed request for Roasbeef December 11, 2023 09:06
@guggero guggero merged commit 0ec9ac7 into lightningnetwork:master Dec 11, 2023
24 of 25 checks passed
@guggero guggero mentioned this pull request Dec 12, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour P1 MUST be fixed or reviewed rpc Related to the RPC interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: add get transaction rpc
7 participants