-
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
coin select: add coin selection strategy option to all on-chain RPCs #8515
coin select: add coin selection strategy option to all on-chain RPCs #8515
Conversation
Important Auto Review SkippedAuto reviews are limited to the following labels: llm-review. Please add one of these labels to enable auto reviews. Please check the settings in the CodeRabbit UI or the To trigger a single review, invoke 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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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 PR, needs release doc. I think your changes to the protobuf go files can be in the same commit where you made corresponding change to the proto file. Might help fix lint.
c27de4b
to
c819f7e
Compare
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.
Thanks for the PR! There's a lot of duplicated code in the CLI, see my inline comments on how that can be optimized.
c819f7e
to
e0c07c5
Compare
lnrpc/marshall_utils.go
Outdated
) | ||
|
||
case CoinSelectionStrategy_STRATEGY_LARGEST: | ||
coinSelectionStrategy = wallet.CoinSelectionLargest |
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: can return directly in the case
statements, then no final return
at the end of the function is needed (since there's a default
case).
cd85404
to
5eb6b28
Compare
5eb6b28
to
142aa25
Compare
@mohamedawnallah can you please apply the fixup commits and rebase? |
@guggero: review reminder |
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.
Looking good @mohamedawnallah !
Left some comments :)
lnrpc/marshall_utils.go
Outdated
|
||
// MapCoinSelectionStrategy maps a coin selection strategy string to | ||
// a wallet.CoinSelectionStrategy. | ||
func MapCoinSelectionStrategy(strategy string) (wallet.CoinSelectionStrategy, |
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 dont think we need this helper since we should only ever do this once.
lnrpc/lightning.proto
Outdated
// (lnd.conf). | ||
STRATEGY_USE_GLOBAL_CONFIG = 0; | ||
|
||
// Select the largest available coins first for spending. |
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.
suggest: "Select the largest available coins first during coin selection."
same below
config_builder.go
Outdated
switch d.cfg.CoinSelectionStrategy { | ||
case "largest": | ||
walletConfig.CoinSelectionStrategy = wallet.CoinSelectionLargest | ||
|
||
case "random": | ||
walletConfig.CoinSelectionStrategy = wallet.CoinSelectionRandom | ||
|
||
default: | ||
return nil, nil, nil, fmt.Errorf("unknown coin selection "+ | ||
"strategy %v", d.cfg.CoinSelectionStrategy) | ||
coinSelectionStrategy, err := lnrpc.MapCoinSelectionStrategy( | ||
d.cfg.CoinSelectionStrategy, | ||
) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
walletConfig.CoinSelectionStrategy = coinSelectionStrategy |
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 as is. We only want to do this conversion from config string to wallet.CoinSelectionStrategy
once. It won't ever change. Then everywhere else where we need to know the global config, we can use this already parsed wallet.CoinSelectionStrategy
value instead of re-parsing the string.
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.
sp perhaps all that is needed here is to make the wallet.CoinSelectionStrategy
strategy more easily accessible from the rpcserver level
lnrpc/lightning.proto
Outdated
@@ -1145,6 +1162,10 @@ message SendManyRequest { | |||
|
|||
// Whether unconfirmed outputs should be used as inputs for the transaction. | |||
bool spend_unconfirmed = 8; | |||
|
|||
// CoinSelectionStrategy is the strategy to use for selecting coins |
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 pattern of starting a comment with the name of the variable only applies to golang code btw. See the other examples here.
So this can just start with "The coin selection strategy to use ...."
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.
same for other places here.
cmd/lncli/walletrpc_active.go
Outdated
Usage: "(optional) the strategy to use for selecting " + | ||
"coins to fund the PSBT from a template. " + | ||
"If provided it will override the globally " + | ||
"configured strategy in lnd.conf", |
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.
should mention which options are available.
Also, since this same flag is used in many places, might be worth extracting into a re-usable variable?
rpcserver.go
Outdated
strategy, err := lnrpc.MapCoinSelectionStrategy( | ||
r.cfg.CoinSelectionStrategy, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} |
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.
should not need to parse it again here
rpcserver.go
Outdated
feeRate chainfee.SatPerKWeight, minConfs int32, | ||
label string) (*chainhash.Hash, error) { | ||
label string, | ||
strategy wallet.CoinSelectionStrategy) (*chainhash.Hash, error) { |
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: things can still fit on 3 lines instead of 4:
func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
feeRate chainfee.SatPerKWeight, minConfs int32, label string,
strategy wallet.CoinSelectionStrategy) (*chainhash.Hash, error) {
lnwallet/btcwallet/btcwallet.go
Outdated
feeRate chainfee.SatPerKWeight, minConfs int32, | ||
label string) (*wire.MsgTx, error) { | ||
label string, | ||
strategy base.CoinSelectionStrategy) (*wire.MsgTx, error) { |
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.
func (b *BtcWallet) SendOutputs(outputs []*wire.TxOut,
feeRate chainfee.SatPerKWeight, minConfs int32, label string,
strategy base.CoinSelectionStrategy) (*wire.MsgTx, error) {
* Add coin selection strategy option to the following on-chain RPC calls | ||
`EstimateFee`, `SendMany`, `SendCoins`, `BatchOpenChannel`, `SendOutputs`, and `FundPsbt`. [coin select: add coin selection strategy option to all on-chain RPCs](https://github.com/lightningnetwork/lnd/pull/8515). |
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.
notice that the other entries are wrapped at 80 chars :)
a923f7e
to
d0e74d9
Compare
Thank you very much, @ellemouton, for your feedback! The idea of converting the |
d0e74d9
to
3de1be9
Compare
The latest change after asking for a review is related to the lining error solved by adding
|
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.
tACK (tested via the FundPSBT flow) 🚀
Great work! A few more suggestions 🙏
cmd/lncli/commands.go
Outdated
Name: "coin_selection_strategy", | ||
Usage: "(optional) the strategy to use for selecting " + | ||
"coins. If provided, it will override the " + | ||
"globally configured strategy in lnd.conf", |
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 should contain a list of the available options
3de1be9
to
62eb3f7
Compare
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.
LGTM! 🚀 Great work!
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.
Looks very good now! Just a couple of small requests, then we're good to go.
8a71b33
to
8bc8f27
Compare
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.
One last change required.
8bc8f27
to
9148022
Compare
In this commit, we add the coin selection strategy option to all on-chain RPCs `FundPsbt`, `BatchOpenChannel`, `EstimateFee`, `SendMany`, `SendCoins`, `SendOutputs`.
In this commit we add coin selection strategy option to the following on-chain rpc commands `fundpsbt`, `fundtemplatepsbt`, `batchopenchannel`, `estimatefee`, `sendcoins`, and `sendmany`.
In this commit, we add the coin selection strategy option to the following on-chain RPCs `fundpsbt`, `batchopenchannel`, `estimatefee`, `sendcoins`, `sendmany`, and `sendoutputs`.
9148022
to
31526a0
Compare
The latest push after asking for a review is just rebasing! |
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, LGTM 🎉
Change Description
This PR adds coin selection strategy option to the following on-chain RPCs
FundPsbt
,SendOutputs
,BatchOpenChannel
,SendCoins
,SendMany
,EstimateFee
and addcoin_selection_strategy
optional parameter tolncli
equivalent commands (if any).Fixes #8498
Steps to Test
Steps for reviewers to follow to test the change.
Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.