High level road map for coin selection changes #12605

issue morcos openend this issue on March 5, 2018
  1. morcos commented at 8:54 pm on March 5, 2018: member

    Here is my proposed path forward after some in-person discussion.

    • Merge #10637 which simply adds a preliminary attempt to find an exact match using Branch and Bound and then falls back to the existing Core algo.

    Then we’ll replace the fallback to an improved algo:

    • Remove Core’s exact match finding. (If BnB doesn’t find exact match, just resign yourself to creating change)
    • Use effective value for adding inputs.
    • Aim for a target which is actual target + some minimum reasonable change.
    • Consider inputs lower than the target value separately from inputs > than target value.
      • If we can achieve target with lower value inputs, randomly add them until we are above the target and return.
      • If we can’t achieve target with lower value inputs, randomly select one of the higher value inputs and return.
      • Handle edge cases where we can’t create a reasonable size change, but do have enough balance.

    The change from the existing Core fallback here will be that we are no longer spending uneconomic inputs, but we will still by default be highly consolidating as we are always combining lower value inputs to meet our target when possible. When fees are lower, more inputs will automatically be available for inclusion. Also when it’s not possible to find a solution from lower value inputs, we won’t always use the smallest high valued output.

    In the future we can reconsider this 100% bias towards always using lower value inputsand consider other factors such as current feerate and size of transaction required in deciding whether to consolidate or use just one higher value input. It may also be the case that Branch and Bound performance in finding exact matches improves when we more often use larger inputs and don’t always get rid of our small ones.

  2. fanquake added the label Wallet on Mar 5, 2018
  3. ryanofsky commented at 9:12 pm on March 5, 2018: contributor
    Any relation with #12257, which adds an -avoidpartialspends option to coin selection, or is that basically orthogonal?
  4. morcos commented at 9:31 pm on March 5, 2018: member
    Yeah that should be orthogonal I think.
  5. eklitzke commented at 8:25 am on March 11, 2018: contributor
    I’ve done some review on #10637 and one thing that made the diff confusing (to me at least) is that there was a fair amount of legacy code moved around, which isn’t obvious from a first glance. There’s a lot of weird stuff in the legacy code that I don’t think would pass code review today. After #10637 is approved, I think it’s a good idea to do an overall cleanup/refactor of what exists at the same time as (or maybe in a PR just prior to) the removal of the exact match algorithm, with the intent of making it easier to get later changes merged.
  6. Sjors commented at 3:13 pm on March 16, 2018: member
    @morcos should this issue replace #7664? See also #6569 on the related topic of change address privacy.
  7. RHavar commented at 3:41 pm on March 16, 2018: contributor

    I’m going to very much disagree with the high-level direction here. The thing about coin selection, is that you are just managing a bunch of trade-offs and without knowing future spending patterns (and their fee rates) you’re shooting in the dark.

    The idea of aggressively consolidating (by using small inputs) is generally not a good one for both privacy and fees (for example, it makes it harder to use exact-change later), and really is conflating two different problems (there should instead be a consolidate command, that cleans up your utxo with a super low fee transaction).

    I kind of believe that you can’t really get far in coin selection unless you add a “future spend cost” argument, that lets it know how much you’re expecting to pay in the future. For consumer wallets this could even just be the average fee (for the conf target they’re using) for the last month.

    But honestly, coin selection is a very hard problem. I really strongly think the sane way forward for core is by making coin-selection have a well defined interface and a sort of plugin architecture. One size will never fit all, and the best way to allow things to move forward would be to allow people to experiment and work with it easily.

    For anyone interested in coin selection, I’d like to shill https://www.coinsayer.com/ which uses a lot of techniques not very applicable to core ( like running several constraint solvers and models), but I think the API itself is quite interesting (as it’s quite general and powerful, supporting even generating conflicts for things like bip125) and better models the problem than previously done. Also there’s a demo server (freeapi) running, which everyone is free to hammer as hard as the want if you want to test specific scenarios or try measure the uplift.

  8. murchandamus commented at 6:12 pm on March 19, 2018: contributor

    @RHavar: Since the previous coin selection algorithm was highly consolidatory, we want to switch to a less strict rule set in a few steps that take a large leap in one go. That’s why we’ve decided to fallback to the old algorithm first, and to slacken its behavior in small steps.

    I would agree though, that the old selection style is consolidating too aggressively, which (per gutfeeling) is probably increasing overall user costs and reducing privacy.

  9. RHavar commented at 6:28 pm on March 19, 2018: contributor

    Isn’t #10637 already going to be highly consolidatory? At least when that kicks in, users are getting a substantial privacy and fee saving.

    I personally don’t really see a point in having the “with change fallback” also consolidatory (in fact, it seems a lot worse). If anything the “with change fallback”’s primary objective should be to maximize the chance that the primary “no change” selection is able to be successful in the next run.

  10. murchandamus commented at 10:21 pm on March 19, 2018: contributor
    Yes, that’s why we’re trying to get away from it, but with small steps.
  11. Sjors commented at 8:38 am on November 20, 2019: member
    More coin selection action in #17290 Enable BnB coin selection for preset inputs and subtract fee from outputs, #17331 Use effective values throughout coin selection and #17526 Use Single Random Draw In addition to knapsack as coin selection fallback that can use review.
  12. achow101 commented at 10:05 pm on October 26, 2022: member
    Going to close this now that we’ve done basically everything on the list.
  13. achow101 closed this on Oct 26, 2022

  14. bitcoin locked this on Oct 26, 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: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me