Adds a new flag commitmax to the command openchannel of lncli#4024
Adds a new flag commitmax to the command openchannel of lncli#4024bjarnemagnussen wants to merge 1 commit intolightningnetwork:masterfrom
commitmax to the command openchannel of lncli#4024Conversation
|
A better way to do this is to use functionality added along side As implemented in this PR, it isn't concurrent safe, as the balance may shift when it's obtained on the CLI compared to when we actually go to fund the transaction. If the above function is used, then this isn't an issue as it locks all coin selection (and funding). Also a better name for this feature imo is something along the lines of |
|
Thanks for your input @Roasbeef ! Those are some great insights you gave me. I will take another look at it and try to update this PR. |
When enabling this flag all the available wallet balance up to the allowed maximum funding limit will be used with a channel commitment.
2d88bcf to
7f14faa
Compare
|
Will reopen PR as this has undergone major changes. |
| // the amount to be pushed to the remote or | ||
| // the allowed minimum funding size. | ||
| if remoteInitialBalance >= minChanFundingSize { | ||
| localFundingAmt = remoteInitialBalance + 1 |
There was a problem hiding this comment.
would be cool to add the information in the comment which was discussed below why the +1 is needed here
Description
This PR introduces a new flag
commitmaxforopenchannelthat for the channel capacity will use the whole available wallet balance up to the allowed maximum funding limit (currently ~0.16 btc) when opening a new channel.Motivation
The command
sendcoinshas a flagsweepallthat will spend all the coins from the wallet. However no such flag exists when opening new channels usingopenchannel.Wanting to use the total available wallet balance in the local amount when opening a channel requires calculating the needed fee and subtracting it from the balance manually.
Further, it seems that this possibility has at least come up as most of the functionality to make this possible already exists, e.g.:
lnd/lnwallet/chanfunding/assembler.go
Lines 67 to 72 in 80af295
Edge Case
The
commitmaxflag makes use of theCoinSelectSubtractFeesfunction to select funds. This implies that if the wallet balance is greater than the sum of the maximum allowed funding limit (~0.16 btc) and the fee, then for the new channel the capacity will be the maximum allowed (~0.16 btc) subtracted by the fee, instead of exactly the maximum allowed (~0.16 btc). This is a slightly wrong behaviour, as in this case it would have been possible to exactly max out the channel capacity and additionally have enough available funds to pay the fee.I think a solution to this would require adding a field e.g.
CommitMaxto thechanfunding.Requestand adding logic to theProvisionChannelfunction insidelnd/lnwallet/chanfunding/wallet_assembler.goto distinguish between opening channels withCommitMaxand without. But I think this is too much to specifically change for such an edge case.Disclaimer
I added this feature because I felt that such a flag was missing and could be useful. But I also implemented it just to get a better understanding of the
lndcodebase. Let me know if this feature is useful or not for others.Testing
I am unsure if this change requires to add tests. But since this change does only use functionality that already existed, I don't see where tests should be added.
Pull Request Checklist
Contribution Guidelines
the positive and negative (error paths) conditions (if applicable)
go fmt(the tab character should be counted as 8 characters, not 4, as some IDEs do
per default)
make checkdoes not fail any testsgo vetdoes not report any issuesmake lintdoes not report any new issues that did notalready exist
cases it can be justifiable to violate this condition. In that case, the
reason should be stated in the commit message.