Use change amount as tiebreaker for SelectionResults #25742

pull murchandamus wants to merge 9 commits into bitcoin:master from murchandamus:2022-07-use-change-as-tiebreaker changing 5 files +207 −84
  1. murchandamus commented at 7:58 PM on July 29, 2022: contributor

    This amends the sorting operator for SelectionResults to prefer

    1. lower waste
    2. higher input count
    3. 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.

  2. 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
  3. wallet: add SelectionResult::Merge 582199820e
  4. 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
  5. wallet: calculate and store min_change ef71f05749
  6. wallet: add SelectionResult::GetChange 83bf6ab231
  7. wallet: use GetChange() in tx building 64af431f32
  8. wallet: use GetChange() when computing waste 45ee9d3a73
  9. wallet: Prefer smaller change amount in tiebreaker
    Requires #25647
    5738e926e6
  10. Test sorting of SelectionResults 567d8418cb
  11. fanquake added the label Wallet on Jul 29, 2022
  12. DrahtBot added the label Needs rebase on Jul 29, 2022
  13. 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>

  14. 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?

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

  16. murchandamus closed this on Aug 10, 2022

  17. bitcoin locked this on Aug 10, 2023

github-metadata-mirror

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