Skip to content

Simplify coin selection for sendcoins#8516

Closed
Chinwendu20 wants to merge 10 commits into
lightningnetwork:masterfrom
Chinwendu20:sendcoins
Closed

Simplify coin selection for sendcoins#8516
Chinwendu20 wants to merge 10 commits into
lightningnetwork:masterfrom
Chinwendu20:sendcoins

Conversation

@Chinwendu20
Copy link
Copy Markdown
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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 4, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Labels to auto review (1)
  • llm-review

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 do a full 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
Copy Markdown
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
Comment thread sweep/walletsweep.go Outdated
@Chinwendu20 Chinwendu20 marked this pull request as draft March 4, 2024 11:05
@Chinwendu20
Copy link
Copy Markdown
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

Comment thread itest/lnd_channel_funding_fund_max_test.go Outdated
@Chinwendu20
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown

Is there an update on this @Chinwendu20 ?

@Chinwendu20
Copy link
Copy Markdown
Contributor Author

Is there an update on this @Chinwendu20 ?

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

@Chinwendu20
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

@hieblmi
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

fyi I ran this test locally and it was successful.

@Chinwendu20
Copy link
Copy Markdown
Contributor Author

@Heebs the CI has been ran the failed tests that has to do with sendcoins are the ones using postgres backend, other itests pass. I think it is unrelated. Maybe as a separate issue we need to figure out why the response seems to be coming slower than expected for that case.
Same things happened in this PR: https://github.com/lightningnetwork/lnd/actions/runs/9089660152/job/25069073966?pr=8759

Copy link
Copy Markdown
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.

There are three itests failing atm:

1.) The CI required one https://github.com/lightningnetwork/lnd/actions/runs/9270373663/job/25641223443?pr=8516#step:5:385. This might be related to sweeper changes that @yyforyongyu intends to get fixed in v0.18.1-beta iiuc. If that's the case would you @yyforyongyu sign off on this PR that we can ignore the failure here?

2.) https://github.com/lightningnetwork/lnd/actions/runs/9270373663/job/25641222998?pr=8516#step:5:920 This I can repro locally with make itest-parallel backend=bitcoind dbbackend=postgres, but it runs a long time.

3.) https://github.com/lightningnetwork/lnd/actions/runs/9270373663/job/25641222017?pr=8516#step:5:924 This I can't repro, but it should get resolved if 2.) is resolved since it is the same error.

@Chinwendu20
Copy link
Copy Markdown
Contributor Author

2.) https://github.com/lightningnetwork/lnd/actions/runs/9270373663/job/25641222998?pr=8516#step:5:920 This I can repro locally with make itest-parallel backend=bitcoind dbbackend=postgres, but it runs a long time.

3.) https://github.com/lightningnetwork/lnd/actions/runs/9270373663/job/25641222017?pr=8516#step:5:924 This I can't repro, but it should get resolved if 2.) is resolved since it is the same error.

Responded to this here: #8516 (comment)

@hieblmi
Copy link
Copy Markdown
Collaborator

hieblmi commented May 31, 2024

Ah right, I guess then it depends on if we can ignore the force-closure itest which is flaky and will be fixed in v0.18.1 according to @yyforyongyu

Could you confirm that this is the flake you are referring to?
https://github.com/lightningnetwork/lnd/actions/runs/9270373663/job/25641223443?pr=8516#step:5:385

Copy link
Copy Markdown
Member

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

This doesn't look like a flake to me, will investigate - meanwhile could you rebase and push so we can rerun the CI.

Comment thread cmd/lncli/commands.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"will be used as input for the transaction; " +
"will be used as an input for the transaction; " +

Comment thread itest/lnd_sendcoins_utxo_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: no need to shutdown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just that that is what is done in similar tests:

alice := ht.NewNode("Alice", args)
defer ht.Shutdown(alice)
bob := ht.NewNode("Bob", args)
defer ht.Shutdown(bob)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yea those places could also be updated - this is just a nit, so non-blocking

Comment thread itest/lnd_sendcoins_utxo_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In go we almost always use anonymous structs for table driven test.

Comment thread itest/lnd_sendcoins_utxo_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think there's a simpler one-line call you can use,

// Alice tries to send all funds to an external address, the reserved
// value must stay in her wallet.
minerAddr := ht.Miner.NewMinerAddress()

Comment thread itest/lnd_sendcoins_utxo_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

node Alice should be created here

Comment thread itest/lnd_sendcoins_utxo_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this test looks great, I'd suggest at least moving the tc.sendAll branch to a new test, either integrating it in testSweepAllCoins, or a new test testSendCoinSelectUtxoSendAll, so this test is easier to follow and maintain in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I can integrate it into the testSweepAllCoins. Looking at this again I think I can move this test to the lnd_misc_test.go file.

But if I separate the test, I would have to change the test name, right? Do you have any naming suggestions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the name is descriptive enough tho

Comment thread itest/lnd_sendcoins_utxo_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmmm in this case we usually write := instead of var.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah it's a bit different, but again it's non-blocking.

Comment thread lnwallet/interface.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we use opts ...SendOutputOption instead of inputs []wire.OutPoint or even a map inputs map[wire.OutPoint]struct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure why we should consider using map[wire.OutPoint]struct. Also this way we can better extend the function in the future, also using this, inputs []wire.OutPoint would mean that we would have to change other existing callsite in the code.

If you want can still change it to, inputs []wire.OutPoint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer using explicit names and structs, so the caller can understand the params more easily. Re extensibility, yea that's also true, tho IMO a better way is to construct sth like SendOutputsRequest and use it as the param - future PRs tho.

Comment thread sweep/walletsweep.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is true as it depends on the conf targets we use when listing utxos from the wallet

Comment thread sweep/walletsweep.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would be nice to also return which utxo is not found - maybe add something like fmt.Errorf("outpoint not found: %w", err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the fn library would output that alreadY:

lnd/fn/map.go

Line 37 in f88f120

return nil, fmt.Errorf("NewSubMap: missing key %v", k)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Def - but it's pretty low-level and there's no context around this error. Imagine a second place also using this NewSubMap method, then we'd have a bit of trouble locating the place that generated the error.

@Chinwendu20
Copy link
Copy Markdown
Contributor Author

Chinwendu20 commented Jun 3, 2024

This doesn't look like a flake to me, will investigate - meanwhile could you rebase and push so we can rerun the CI.

I think it is unrelated to the PR, we can create a separate issue for that case so maybe we do not block this, same thing happens in another PR:
https://github.com/lightningnetwork/lnd/actions/runs/9089660152/job/25069074366?pr=8759#step:5:767

We can track it here: #8806

@yyforyongyu
Copy link
Copy Markdown
Member

Cool I think this is why the itests failed, so not related to this PR.

Copy link
Copy Markdown
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.

tACK, apart from the failing itest cases which seem to be unrelated to this PR I have nits left.

Great work again on this @Chinwendu20.

Comment thread lnwallet/btcwallet/btcwallet.go Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: remove n

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is not addressed

Comment thread cmd/lncli/commands.go Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: period instead of ;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

move to release notes for v0.18.1-beta.

Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
@Chinwendu20
Copy link
Copy Markdown
Contributor Author

@guggero we have two approvals now, I think we can merge?

@hieblmi
Copy link
Copy Markdown
Collaborator

hieblmi commented Jun 13, 2024

@guggero we have two approvals now, I think we can merge?

Wanted to make sure that @yyforyongyu's CRs were addressed, would be good to get his go too.

Copy link
Copy Markdown
Member

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

There's a missing check that we need to ensure provided utxos are known to the wallet.

Comment thread lnwallet/btcwallet/btcwallet.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is not addressed

Comment thread lnwallet/btcwallet/btcwallet.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok i see it now, this should be cherry-picked to where it's introduced.

Comment thread sweep/walletsweep.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we want to use a variadic param rather than a slice here? I think it's easier if it's selectUtxos []wire.OutPoint) and we can pass the selectOutpoints instead of selectOutpoints... in SendCoins?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really easier in my opinion as that would also mean we would have to make changes other places this function was called

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the diff is fairly simple,

diff --git a/rpcserver.go b/rpcserver.go
index 80cff0763..619c635a8 100644
--- a/rpcserver.go
+++ b/rpcserver.go
@@ -1389,7 +1389,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
 		sweepTxPkg, err := sweep.CraftSweepAllTx(
 			feePerKw, maxFeeRate, uint32(bestHeight), nil,
 			targetAddr, wallet, wallet, wallet.WalletController,
-			r.server.cc.Signer, minConfs, selectOutpoints...,
+			r.server.cc.Signer, minConfs, selectOutpoints,
 		)
 		if err != nil {
 			return nil, err
@@ -1444,7 +1444,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
 				outputs, targetAddr, wallet, wallet,
 				wallet.WalletController,
 				r.server.cc.Signer, minConfs,
-				selectOutpoints...,
+				selectOutpoints,
 			)
 			if err != nil {
 				return nil, err
diff --git a/sweep/walletsweep.go b/sweep/walletsweep.go
index f0ec70e7c..1fa2068ea 100644
--- a/sweep/walletsweep.go
+++ b/sweep/walletsweep.go
@@ -220,7 +220,7 @@ func CraftSweepAllTx(feeRate, maxFeeRate chainfee.SatPerKWeight,
 	changeAddr btcutil.Address, coinSelectLocker CoinSelectionLocker,
 	utxoSource UtxoSource, outputLeaser OutputLeaser,
 	signer input.Signer, minConfs int32,
-	selectUtxos ...wire.OutPoint) (*WalletSweepPackage, error) {
+	selectUtxos []wire.OutPoint) (*WalletSweepPackage, error) {
 
 	// TODO(roasbeef): turn off ATPL as well when available?
 
diff --git a/sweep/walletsweep_test.go b/sweep/walletsweep_test.go
index 8cc93c941..724b9d85d 100644
--- a/sweep/walletsweep_test.go
+++ b/sweep/walletsweep_test.go
@@ -346,7 +346,7 @@ func TestCraftSweepAllTxCoinSelectFail(t *testing.T) {
 
 	_, err := CraftSweepAllTx(
 		0, 0, 10, nil, nil, coinSelectLocker, utxoSource, utxoLeaser,
-		nil, 0,
+		nil, 0, nil,
 	)
 
 	// Since we instructed the coin select locker to fail above, we should
@@ -372,7 +372,7 @@ func TestCraftSweepAllTxUnknownWitnessType(t *testing.T) {
 
 	_, err := CraftSweepAllTx(
 		0, 0, 10, nil, nil, coinSelectLocker, utxoSource, utxoLeaser,
-		nil, 0,
+		nil, 0, nil,
 	)
 
 	// Since passed in a p2wsh output, which is unknown, we should fail to
@@ -461,7 +461,7 @@ func TestCraftSweepAllTx(t *testing.T) {
 			sweepPkg, err := CraftSweepAllTx(
 				0, 0, 10, nil, deliveryAddr, coinSelectLocker,
 				utxoSource, utxoLeaser, signer, 0,
-				tc.selectUtxos...,
+				tc.selectUtxos,
 			)
 			if tc.errString != "" {
 				require.ErrorContains(t, err, tc.errString)

Comment thread sweep/walletsweep.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This check has been repeated multiple times - if it's already done in SendCoins so there's no need to check it here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CraftSweepAllTx is an independent function it is not bound to be used in sendcoins only, so I think it makes sense that it carries out this check as well

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In that case, all other places should remove this check, there's no need to duplicate this logic and we should implement it once - easier to test and maintain.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A better option is to use set (map) - that way we don't even need to worry about duplicates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or maybe the Set structure in the fn package? What do you think?

Comment thread sweep/walletsweep_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: select -> selected, same below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

select can actually be used as an adjective

Comment thread cmd/lncli/commands.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is checked again - we should enforce the single responsibility principle and have only one place to implement this logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

prelim checks. I think I have seen this done a couple of places for lncli

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In that case, we should also fix them in future PRs.

Comment thread lntest/rpc/lnd.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we stick to the XXXAssertErr pattern? That's the pattern used in all other assertions, OpenChannelAssertErr, ConnectPeerAssertErr, etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is acctually a logic change in this function. Hence AssertErr might not be really descriptive

Comment thread lntest/rpc/lnd.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can keep this assertion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread go.mod Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmmm how did you create this commit? Like what was the command used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make tidy-module

Comment thread itest/lnd_misc_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've laid out my view on table-driven test here and I think we should avoid it in itest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In general, are you saying that if a function has more than two args we should not use TDD for it?

I like using table-driven tests when the outputs of a function are only determined by one or two inputs in a test setup,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It depends - but we should discourage using it in itest because it's difficult to maintain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am sorry I am having difficulty refactoring this to not use TDD. I am not sure what the non TDD version should look like. Would it be something like this?

similarfunction := func(t *testing.T, req *sendcoinsRequest, someconditionalsthatwecheck){
----
}

// With select utxos
ht.Run(){
similarfunction()
}

// With no select utxos
ht.Run(){
similarfunction()
}

Would I need to refactor testsendcoinsselectutxos as well?

@Chinwendu20
Copy link
Copy Markdown
Contributor Author

@yyforyongyu I think we do that already? I responded to that in the specific code piece you wrote the review in. Let me know if that works.

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>
This commit changes `SendCoinsAssertErr` to `SendCoinsReturnErr`. The
function now returns the resulting error from calling `sendCoins`.

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>
@lightninglabs-deploy
Copy link
Copy Markdown
Collaborator

@yyforyongyu: review reminder
@Chinwendu20, remember to re-request review from reviewers when ready

@guggero
Copy link
Copy Markdown
Collaborator

guggero commented Aug 5, 2024

Replaced by #8955.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 might get fixed, nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants