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

Simplify coin selection for sendcoins #8516

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Chinwendu20
Copy link
Contributor

@Chinwendu20 Chinwendu20 commented Mar 4, 2024

Change Description

This PR fixes this issue: #6949 (comment)
Depends on: btcsuite/btcwallet#912 and #8729

In this well detailed issue comment, the process of sending funds using utxos selected by the sender currently has over five steps in which one has to call various psbt APIs.

The goal of this PR is to improve user experience by including utxos to the sendcoins command and corresponding rpc structs (SendCoinsRequest and SendCoinsResponse ) which would enable the sender described to achieve the same aim with one command.

This is done by adding a new field to rpc structs SendCoinsRequest and SendCoinsResponse to enable users request for that functionality and enable the driving function (in which we modify its functionality as well) use these utxos when crafting the transaction for this functionality.

Additionally, the sweepall field in the above mentioned request and response rpc structs when true now not only sweeps ALL funds in the wallet but also ALL funds in the selected utxos when used in conjunction with the new select utxos field.

The lncli sendcoins command was updated to include the flag, utxo to enable this functionality on that end.

There were also slight internal logic change, where a slice of utxos are now accepted by relevant functions as variadic argument, functional options to enable this functionality.

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Copy link

coderabbitai bot commented Mar 4, 2024

Important

Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Chinwendu20
Copy link
Contributor Author

Hello @hieblmi here is the PR

@guggero guggero requested review from guggero and removed request for Roasbeef, yyforyongyu and ziggie1984 March 4, 2024 08:44
sweep/walletsweep.go Outdated Show resolved Hide resolved
@Chinwendu20 Chinwendu20 marked this pull request as draft March 4, 2024 11:05
@Chinwendu20
Copy link
Contributor Author

Chinwendu20 commented Mar 4, 2024

I would be using the psbt API instead as this approach would not craft a transaction with all inputs selected by the user as pointed out here:
btcsuite/btcwallet#912 (comment)

Modified it, no need for this

@Chinwendu20
Copy link
Contributor Author

Hello @sputn1ck, do you think I should create a different function instead of adding an arg to an exported one as per your comment here: btcsuite/btcwallet#912 (comment)

@ellemouton ellemouton requested review from sputn1ck and removed request for Crypt-iQ and ellemouton March 11, 2024 13:42
@bennyhodl
Copy link

tACK.

Tested locally and worked as expected with one utxo, sweep, and multiple utxos. Would like to see this merged as I am signing PSBTs manually because my application requires 1 input --> 1 output transactions.

@guggero guggero removed their request for review March 13, 2024 16:30
@bennyhodl
Copy link

Is there an update on this @Chinwendu20 ?

@Chinwendu20
Copy link
Contributor Author

Is there an update on this @Chinwendu20 ?

Thanks I should push an update by the end of this week..

@Chinwendu20 Chinwendu20 force-pushed the sendcoins branch 4 times, most recently from 7b3d4ac to 6659a2e Compare May 13, 2024 07:37
Copy link
Collaborator

@hieblmi hieblmi left a comment

Choose a reason for hiding this comment

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

Great work once again, got a small Q regarding the added itest and a UX issue I found.

func fetchUtxosFromOutpoints(utxos []*lnwallet.Utxo,
outpoints []wire.OutPoint) ([]*lnwallet.Utxo, error) {

lookup := fn.SliceToMap(utxos, func(utxo *lnwallet.Utxo) wire.OutPoint {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

name: "sendCoins, amount specified, " +
"no select outpoints",
amt: 200_000,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you referring to this test "sendCoins with selected utxos, expect change"?

I was thinking of something like

{
			selectedCoins: []btcutil.Amount{
				50_000,
                                 20_000,
				1_000,
			},
			amt:        70_100,
			...............,
		},

@@ -330,16 +331,28 @@ var sendCoinsCommand = cli.Command{
"scripts",
},
coinSelectionStrategyFlag,
cli.StringSliceFlag{
Name: "utxo",
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we pass in the same utxo twice the command isn't failing which I think should happen from a UX perspective. I tested(last utxo is a dupe): reg_zane sendcoins --addr bcrt1pztmhas8h2vg8xfvj4kr4s3kgx69d4usq6uxxmyh6lhslrgllwpns87snxq --utxo 8c787614dc1adfda9d09f5a908853d8e91cc5579bc00e43c3958c5cb7dcfaf46:0 --utxo a2a9f76c008f4fecdcfe34fc93da1a5f4f7e63a1f896dec9869272b101ac89a9:1 --utxo a2a9f76c008f4fecdcfe34fc93da1a5f4f7e63a1f896dec9869272b101ac89a9:1 --sweepall

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! I would fix it

@Chinwendu20
Copy link
Contributor Author

This PR is now dependent on #8750 and btcsuite/btcwallet#928

@lightninglabs-deploy
Copy link

@sputn1ck: review reminder
@hieblmi: review reminder

@Chinwendu20 Chinwendu20 force-pushed the sendcoins branch 3 times, most recently from 607c321 to 27d8cdf Compare May 22, 2024 12:06
@hieblmi
Copy link
Collaborator

hieblmi commented May 24, 2024

There are still itests failing.

@Chinwendu20
Copy link
Contributor Author

Chinwendu20 commented May 24, 2024

I think the taproot test needs to create a new node and not use the general Alice node. Two tests can request sendCoins to sweep all coins at the same time, creating the same transaction same txid, the other test can get the txid first into the mempool making the sweepall sendcoins operation fail in the other. I do not know if that makes sense. If it does I can open a new PR for a fix.

In the meantime, this needs rebasing but I need to know where this stands in approval so I make changes at once.

@Chinwendu20
Copy link
Contributor Author

Maybe all tests should create their own node to prevent cases like this?

@hieblmi
Copy link
Collaborator

hieblmi commented May 27, 2024

I think the taproot test needs to create a new node and not use the general Alice node. Two tests can request sendCoins to sweep all coins at the same time, creating the same transaction same txid, the other test can get the txid first into the mempool making the sweepall sendcoins operation fail in the other. I do not know if that makes sense.

Not sure how this applies to the tests, in here lnd_taproot_test.go:128 sendcoins is called sequentially, why is the last call exceeding its deadline?

I think we should fix the itests in a separate commit in this PR.

@Chinwendu20
Copy link
Contributor Author

Chinwendu20 commented May 27, 2024

When I checked the logs for Alice related to this test, I saw this

2024-05-24 09:38:40.442 [WRN] BTWL: Transaction 8b7ab6dc1ace16e59491caed739a599756967cc23ea799f2f48bdd3d61116f8d not accepted by mempool: txn-already-in-mempool
2024-05-24 09:38:40.592 [INF] LNWL: Inserting unconfirmed transaction 8b7ab6dc1ace16e59491caed739a599756967cc23ea799f2f48bdd3d61116f8d
2024-05-24 09:38:40.943 [DBG] LNWL: Marked address bcrt1pn388y03pjsedvrl2n0dxgyz7yup9q6snhyrqj67qh2aj8dq88udq6wfs78 used
2024-05-24 09:38:41.462 [INF] RPCS: [sendcoins] spend generated txid: 8b7ab6dc1ace16e59491caed739a599756967cc23ea799f2f48bdd3d61116f8d

sendcoins is called sequentially in that test but other tests using the Alice node would call sendcoins in parallel, right?
So my initial thinking is that because the tx failed the TestMempool check and also that it would return an error while publishing the transaction it would time out with that error but the last log line shows that infact the the sendcoins rpc function exits successfully in spite of that and following the code it makes sense because ErrTxAlreadyInMempool is usually ignored.

Maybe if we rerun this it would pass, seems like a case of unprecedented slow server response

@Chinwendu20
Copy link
Contributor Author

fyi I ran this test locally and it was successful.

Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants