bnb: exit selection when best_waste is 0 #18262

pull achow101 wants to merge 1 commits into bitcoin:master from achow101:bnb-waste-zero changing 2 files +6 −4
  1. achow101 commented at 9:37 pm on March 4, 2020: member

    If we find a solution which has no waste, just use that. This solution is what we would consider to be optimal, and other solutions we find would have to also have 0 waste, so they are equivalent to the first one with 0 waste. Thus we can optimize by just choosing the first one with 0 waste.

    Closes #18257

  2. bnb: exit selection when best_waste is 0
    If we find a solution which has no waste, just use that. This solution
    is what we would consider to be optimal, and other solutions we find
    would have to also have 0 waste, so they are equivalent to the first
    one with 0 waste. Thus we can optimize by just choosing the first one
    with 0 waste.
    9b5950db86
  3. fanquake added the label Wallet on Mar 4, 2020
  4. DrahtBot commented at 10:58 pm on March 4, 2020: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #17526 (Use Single Random Draw In addition to knapsack as coin selection fallback by achow101)
    • #17331 (Use effective values throughout coin selection by achow101)

    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.

  5. practicalswift commented at 11:07 pm on March 4, 2020: contributor
    Concept ACK
  6. fjahr commented at 11:44 pm on March 4, 2020: member

    Concept ACK on this as it is an improvement!

    However, looking at this I had another thought: given we have two possible solutions with 0 waste, would we not want to minimize fees by selecting the one with fewer inputs? So, instead of stopping early we could still run through all the tries and select the best waste option with the least inputs. Actually this could be an additional breaker between any equal waste options.

  7. achow101 commented at 0:11 am on March 5, 2020: member

    However, looking at this I had another thought: given we have two possible solutions with 0 waste, would we not want to minimize fees by selecting the one with fewer inputs? So, instead of stopping early we could still run through all the tries and select the best waste option with the least inputs. Actually this could be an additional breaker between any equal waste options.

    Fewer inputs does not necessarily minimize fees. It depends on the exact scripts being used. Regardless, I don’t think an explicit check for fees is needed. So long as fee > long_term_fee, the waste metric will include an amount that is proportional to the fee each input requires, so in the end, the selection that has the least waste also pays the least in transaction fees.

  8. fanquake requested review from instagibbs on Mar 5, 2020
  9. fanquake requested review from meshcollider on Mar 5, 2020
  10. instagibbs commented at 1:54 pm on March 5, 2020: member

    So long as fee > long_term_fee, the waste metric will include an amount that is proportional to the fee each input requires, so in the end, the selection that has the least waste also pays the least in transaction fees.

    just to nit, in this case, fee == long_term_fee, right? I think it could go either way, if the user expects long term fees to go up or down they might want to pick more or fewer inputs. In the absence of evidence, simply returning with first result seems optimal.

  11. instagibbs commented at 1:54 pm on March 5, 2020: member
    aka concept ACK
  12. in src/wallet/test/coinselector_tests.cpp:179 in 9b5950db86
    175@@ -176,8 +176,8 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
    176     selection.clear();
    177 
    178     // Select 5 Cent
    179-    add_coin(3 * CENT, 3, actual_selection);
    180-    add_coin(2 * CENT, 2, actual_selection);
    181+    add_coin(4 * CENT, 4, actual_selection);
    


    instagibbs commented at 2:11 pm on March 5, 2020:
    why these changes?

    achow101 commented at 4:08 pm on March 5, 2020:
    There is an optimal result earlier in the selection so that changes the outcome here.
  13. yancyribbens approved
  14. yancyribbens commented at 6:13 pm on March 5, 2020: contributor
    LGTM
  15. laanwj commented at 6:10 pm on March 6, 2020: member
    Obvious concept ACK. Is this a case that happens in practice though? I mean, is it worth special-casing, or doesn’t it really matter to do a few more iterations in an unlikely ‘optimal’ case? I don’t really have an intuition for this.
  16. yancyribbens commented at 9:43 am on March 7, 2020: contributor

    Is this a case that happens in practice though?

    That’s also a question I have. My intuition is it’s very unlikely to have an exact match in practice. Also, I think If the cost of change is sufficiently small, its unlikely to have any match including an exact match.

  17. achow101 commented at 2:34 pm on March 7, 2020: member
    I think this condition is fairly hard to hit and probably doesn’t make much of a difference. I think that most wallets will hit the iteration limit in BnB as we do search for more solutions after finding the first one, so exiting early probably isn’t helping that much anyways.
  18. instagibbs commented at 6:57 pm on March 20, 2020: member
    I think this extra logic is really easy to understand and maintainable, therefore should be merged(provided proper review) regardless or not how theoretical people find it.
  19. meshcollider commented at 8:16 pm on April 16, 2020: contributor
    utACK 9b5950db8683f9b4be03f79ee0aae8a780b01a4b
  20. meshcollider merged this on Apr 17, 2020
  21. meshcollider closed this on Apr 17, 2020

  22. sidhujag referenced this in commit 87fa1c591a on Apr 17, 2020
  23. ComputerCraftr referenced this in commit 7c27e96ed3 on Jun 10, 2020
  24. jasonbcox referenced this in commit 113104448c on Oct 23, 2020
  25. vijaydasmp referenced this in commit ebb5549a34 on Aug 29, 2021
  26. PastaPastaPasta referenced this in commit f134a068f0 on Sep 17, 2021
  27. PastaPastaPasta referenced this in commit 421fcde34d on Sep 17, 2021
  28. PastaPastaPasta referenced this in commit aaf2a17767 on Sep 18, 2021
  29. thelazier referenced this in commit ac01d4b41f on Sep 25, 2021
  30. DrahtBot locked this on Feb 15, 2022

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-02-07 00:13 UTC

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