-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: add coin selection parameter add_excess_to_recipient_position
for changeless txs with excess that would be added to fees
#30080
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/30080. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
add_excess_to_recipient_position
for changeless txs with excess that would be added to fees add_excess_to_recipient_position
for changeless txs with excess that would be added to fees
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
From CI:
|
Here are my initial thoughts on each of the options individually
It seems like what you really want is to search for a changeless solution in a given target range. And then if failed to fallback to a solution with change. |
Thanks for the feedback! I agree that it is worth considering how to make these parameters more useful for general users.
Always having a change output would be a problem because we always prefer a changeless tx if the excess is not too large. But when that is not possible the change should be large enough to potentially spend later as a changeless tx. A possible alternative would be to add a setting for CHANGE_LOWER rather than always use the hard coded value of 50,000 sats. It is probably not necessary for my use case to set the
I agree that generally it's too in the weeds for most users. I'll move it to settings.
Good point. The maximum excess currently built into BnB is
Exactly! I believe that is how CS works now. If no set of inputs are found with excess in the range from zero to From the perspective of not over complicating the coin selection options, do you think it would be better to have two new options: |
8734434
to
6f594a7
Compare
I changed |
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
fc9c153
to
1307d1f
Compare
May want to first do a PR to fix the related issue 26466 or resolve that issue if it has been fixed. ht @willcl-ark |
1307d1f
to
96a395f
Compare
21ee356
to
7d009b0
Compare
If this coin selection RPC option is set, then the excess value for a changeless BnB tx will be added to the selected recipient output position instead of added to fees. The BnB algorithm with this option set will primarily select the input set with the least fee waste and excess value less than the cost of adding change. When comparing input sets with the same fee waste, the input set with the least excess value will be selected.
If set, excess from changeless spends can not exceed the lesser of this amount and the current cost_of_change, otherwise just use cost_of_change by default
7d009b0
to
17bc70f
Compare
Use min_viable_change instead of cost_of_change as the upper limit of excess allowed when computing a changeless BnB solution. This prevents a corner case where dust threshold > change_fee results in some changeless BnB solutions not being considered, despite change being dropped during tx building. h/t @S3RK for identifying this issue in bitcoin#26466 .
It's not entirely clear to me why BnB should care about whether the excess is going to the recipient or not. I don't think that should change the algorithm at all, so the changes to Additionally, this implementation modifies the target, and I think that's rather dangerous to do. I think the obvious way to implement this feature is to just detect when the fee paid is greater than the fee needed, and send the excess to the recipient specified, just as we already do when there are change outputs. That would also really shrink the diff. |
Thanks for the feedback. I agree and think for our use we can even do that diff outside of bitcoind. I'll update the PR. |
Imagine this scenario:
Input set A: [20,20,20,20,20] Current BnB computes waste as: This PR with max_excess = 30 computes waste as: In both cases, CG would select input set B and compute waste as something like 8 (1 input, 1 output). Current CS would choose the Knapsack solution(waste = 8 < 20). After this PR CS should select the BnB solution (waste = 4 < 8). A sender that retains excess would prefer the less costly BnB solution using input set A. This PR allows a sender to find an optimal solution using CS when excess value is retained by the sender. Another approach would be to not change BnB at all, but instead modify CS to detect that the best solution has a change output amount (and fee) that is less than our specified max_excess and modify the final tx to add the change output amount (and fee) to the target output. |
Needs rebase, if still relevant. |
This PR looks interesting from the idea that throw away change can go to a different party instead of just throwing away to fees. At first glance though, it seems like the implementation is confusing. For example, I don't understand what From the commit message:
This doesn't explain why this parameter is needed. I'm not saying it's not, just that more explanation would be helpful. |
You would want to set For example, in the case of a Lightning node that is selling liquidity, you might know the smallest utxo you might sell is 10,000 sats + spend fees, so you could set |
I now believe we can achieve equivalent behavior without changing the wallet by just using it to find the best funding utxo, and if there is change we can (when appropriate) build the actual tx with the change amount added to the recipient output position before submitting the transaction. I'll close this PR for now because this doesn't seem generally useful outside of Lightning liquidity providers that want to optimizing their UTXO set management, and a good alternative way of doing it exists. |
Yes, that's a good idea.
I don't know that this idea applies only to Lightning, I can envision some other creative use cases other than just increasing the transaction priority by adding to fees. However, for it to be useful you'd need to be in position to take advantage some large number of aggregate transaction for the change amounts to be worthwhile and there's also the issue of aggregating amounts greater than the dust limit. |
This PR replaces draft PR 29442 as a simpler alternative that only adds two new coin selection parameters:
add_excess_to_recipient_position
andmax_excess
.motivation
A changeless transaction may select inputs with excess value over what is needed to reach the desired fee rate and output targets. Currently that excess value is considered waste and burned as fees. In some situations you may prefer to add any excess value to an output you control. When fees are high the cost of adding a change output increases and so does the amount of potential excess value spent as fees. One example of a situation where excess value should be added to the output amount is when splicing in value to a Lightning channel because the excess value is retained off-chain.