murchandamus
commented at 7:58 PM on July 29, 2022:
contributor
This amends the sorting operator for SelectionResults to prefer
lower waste
higher input count
lower change amount (new)
The reasoning is that all other things equal, we want to send less funds into unconfirmed state and tell counter-parties less about the value in our wallet.
Builds on #25647. If you're interested in this change, please review that PR first.
wallet: accurate SelectionResult::m_target
SelectionResult::m_target should be equal to actual selection target.
Selection target is the sum of all recipient amounts plus non input fees.
So we need to remove change_fee from the m_target. It's safe because change
target is always greater than the change fee, so we can always cover fees
if change output is created.
adb9210958
wallet: add SelectionResult::Merge582199820e
wallet: account for preselected inputs in target
When we have preselected inputs the coin selection search target is reduced
by the sum of (effective) values. This causes incorrect m_target value.
Create separate instance of SelectionResult for all the preselected inputs and
set the target equal to the sum of (effective) values. Target for preselected
SelectionResult is equal to the delta for the search target. To get the final
SelectionResult with accurate m_target we merge both SelectionResult instances.
eff6e6392c
wallet: calculate and store min_changeef71f05749
wallet: add SelectionResult::GetChange83bf6ab231
wallet: use GetChange() in tx building64af431f32
wallet: use GetChange() when computing waste45ee9d3a73
wallet: Prefer smaller change amount in tiebreaker
Requires #25647
5738e926e6
Test sorting of SelectionResults567d8418cb
fanquake added the label Wallet on Jul 29, 2022
DrahtBot added the label Needs rebase on Jul 29, 2022
DrahtBot
commented at 10:02 PM on July 29, 2022:
contributor
<!--cf906140f33d8803c4a75a2196329ecb-->
🐙 This pull request conflicts with the target branch and needs rebase.
<sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>
luke-jr
commented at 11:25 PM on August 9, 2022:
member
Doesn't a change bias tell third-parties more about our wallet? There's a slightly higher probability the lowest output is change, right?
murchandamus
commented at 4:24 PM on August 10, 2022:
contributor
Thank you for your comment. While preparing a response, I realized that the order in which results are collected and compared already results in something even better than what I was trying to achieve.
The tiebreaker would only affect situations in which multiple SelectionResults were tied for best waste score and had the same input count. This should only occur when we have two solutions with change that spend the same output types, which probably is most likely on single-input solutions and might occur a bit more often after #24584.
My motivation was that if SRD e.g. proposed a change of ₿15 and Knapsack found a solution with ₿0.2, it would be preferable to not reveal the large amount to the recipient and to assign less rather than more funds to an unconfirmed output. My proposed change could have caused that the unnecessary input heuristic were accurate slightly more often if a tie occurred with multiple inputs when additionally the SRD change amount ended up being smaller than the min_change randomly picked for Knapsack (see #24494).
It turns out that due to the order in which SelectionResults are collected and compared, we always prefer the Knapsack solution on ties, which mitigates my concern regarding an unnecessary large change. I don't think your concern applies for the current behavior though, because we generate min_change that is up to 2× the recipient amount since #24494 with a maximum of 1,000,000 sats (which was the fixed min_change before). So at least it's not worse than the behavior we had for the prior decade.
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-04-21 15:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me