Enable BnB coin selection for preset inputs and subtract fee from outputs #17290

pull achow101 wants to merge 2 commits into bitcoin:master from achow101:all-bnb changing 3 files +82 −33
  1. achow101 commented at 10:18 pm on October 28, 2019: member

    Currently we explicitly disable BnB when there are preset inputs selected or when the subtract fee from outputs option is enabled. This PR enables BnB for both cases.

    Kind of an alternative to #17246 (implements the subtract fee from outputs part of it) and borrows a test from there too.

  2. fanquake added the label Wallet on Oct 28, 2019
  3. DrahtBot commented at 0:33 am on October 29, 2019: 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)
    • #17458 (Refactor OutputGroup effective value calculations and filtering to occur within the struct by achow101)
    • #17331 (Use effective values throughout coin selection by achow101)
    • #17211 (Allow fundrawtransaction and walletcreatefundedpsbt to take external inputs by achow101)
    • #16910 (wallet: reduce loading time by using unordered maps by achow101)
    • #9381 (Remove CWalletTx merging logic from AddToWallet by ryanofsky)

    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.

  4. in src/wallet/wallet.cpp:2713 in 3da4aef785 outdated
    2709         {
    2710             const CWalletTx& wtx = it->second;
    2711             // Clearly invalid input, fail
    2712-            if (wtx.tx->vout.size() <= outpoint.n)
    2713+            if (wtx.tx->vout.size() <= outpoint.n) {
    2714+                bnb_used = false;
    


    instagibbs commented at 8:17 pm on October 29, 2019:
    are these bnb_used lines really necessary? We aren’t using knapsack solver either on SelectCoins failure

    achow101 commented at 9:11 pm on October 29, 2019:
    Yes. The CreateTransaction loop ends up infinitely looping without them

    Sjors commented at 11:48 am on November 4, 2019:
    I find it a bit concerning that no test breaks when I remove this: https://github.com/Sjors/bitcoin/commit/398877e79bafb6d96bb4d2602568621d759eaf2d

    achow101 commented at 4:41 pm on November 4, 2019:
    Since the same boolean variable is used throughout the tests, it carries over whatever value it had previously. We are expecting SelectCoins and SelectCoinsMinConf to modify it.
  5. in src/wallet/wallet.cpp:2677 in 3da4aef785 outdated
    2673@@ -2674,6 +2674,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
    2674 bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const
    2675 {
    2676     std::vector<COutput> vCoins(vAvailableCoins);
    2677+    CAmount value_select = nTargetValue;
    


    instagibbs commented at 8:19 pm on October 29, 2019:
    nit: value_to_select

    achow101 commented at 11:02 pm on October 29, 2019:
    Done
  6. in src/wallet/test/coinselector_tests.cpp:263 in 3da4aef785 outdated
    259@@ -250,17 +260,24 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
    260     vCoins.at(0).nInputBytes = 40; // Make sure that it has a negative effective value. The next check should assert if this somehow got through. Otherwise it will fail
    261     BOOST_CHECK(!testWallet.SelectCoinsMinConf( 1 * CENT, filter_standard, GroupCoins(vCoins), setCoinsRet, nValueRet, coin_selection_params_bnb, bnb_used));
    262 
    263-    // Make sure that we aren't using BnB when there are preset inputs
    264+    // Make sure that we are using BnB when there are preset inputs
    


    instagibbs commented at 8:24 pm on October 29, 2019:
    s/are/can/

    achow101 commented at 11:02 pm on October 29, 2019:
    Done
  7. achow101 force-pushed on Oct 29, 2019
  8. instagibbs commented at 1:32 pm on October 30, 2019: member

    This change might have broken wallet_bumpfee.py somewhat randomly: https://travis-ci.org/bitcoin/bitcoin/jobs/604712627?utm_medium=notification&utm_source=github_status

    N.B. bumpfee uses preselected inputs to create the transaction, so it might be the case that BnB ended up “hitting” where it previously hadn’t and got rid of the change output earlier than expected in the test.

  9. achow101 commented at 4:19 pm on October 30, 2019: member

    This change might have broken wallet_bumpfee.py somewhat randomly:

    I’m not sure why it would fail randomly since BnB should be deterministic. I also can’t reproduce this at all..

  10. instagibbs commented at 5:23 pm on October 30, 2019: member
    Honestly I do not understand the error either. It seems either the original input was dropped somehow, or that it picked up additional inputs too early. I’ll try to reproduce locally.
  11. instagibbs commented at 5:52 pm on October 30, 2019: member
    ok I’m able to reproduce consistently…. it’s adding 15 inputs for some reason when it shouldn’t be adding any. investigating
  12. in src/wallet/wallet.cpp:2724 in 34a31b2286 outdated
    2727+            if (coin.m_input_bytes <= 0) {
    2728+                bnb_used = false;
    2729+                return false; // Not solvable, can't estimate size for fee
    2730+            }
    2731+            coin.effective_value = coin.txout.nValue - coin_selection_params.effective_fee.GetFee(coin.m_input_bytes);
    2732+            value_to_select -= coin.effective_value;
    


    instagibbs commented at 6:21 pm on October 30, 2019:
    0-            value_to_select -= coin.effective_value;
    1+            if (coin_selection_params.use_bnb) {
    2+                value_to_select -= coin.effective_value;
    3+            } else {
    4+                value_to_select -= coin.txout.nValue;
    5+            }
    

    achow101 commented at 6:32 pm on October 30, 2019:
    Changed.
  13. achow101 force-pushed on Oct 30, 2019
  14. in src/wallet/wallet.cpp:2684 in 7e6cf109c2 outdated
    2677@@ -2674,6 +2678,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
    2678 bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const
    2679 {
    2680     std::vector<COutput> vCoins(vAvailableCoins);
    2681+    CAmount value_to_select = nTargetValue;
    2682 
    2683     // coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
    2684     if (coin_control.HasSelected() && !coin_control.fAllowOtherInputs)
    


    Sjors commented at 12:37 pm on November 4, 2019:
    Would be nice to cover this case as well (used by the GUI and #16377), where coins are selected, but no extra inputs are allowed. Can wait for a followup though.
  15. Sjors approved
  16. Sjors commented at 12:38 pm on November 4, 2019: member
    Code review ACK 7e6cf109c2bc3f824f23fa58cad0bf5fe8184a9f
  17. instagibbs commented at 2:04 pm on November 4, 2019: member

    I find it a bit concerning that no test breaks when I remove this

    That’s a sanity check where the transaction in the wallet somehow doesn’t match the coin requested. Maybe it warrants a log print statement, but that can be done later.

  18. MarcoFalke referenced this in commit 422ec33d45 on Nov 15, 2019
  19. in src/wallet/test/coinselector_tests.cpp:87 in 299373ce61 outdated
    85+    wallet.AddToWallet(*wtx.get());
    86     wtxn.emplace_back(std::move(wtx));
    87 }
    88+static void add_coin(const CAmount& nValue, int nAge = 6*24, bool fIsFromMe = false, int nInput=0, bool spendable = false)
    89+{
    90+    add_coin(testWallet, nValue, nAge, fIsFromMe, nInput);
    


    meshcollider commented at 7:14 am on November 20, 2019:
    spendable?

    achow101 commented at 5:12 pm on November 20, 2019:
    Added
  20. meshcollider commented at 7:19 am on November 20, 2019: contributor

    very light code review ACK 7e6cf109c2bc3f824f23fa58cad0bf5fe8184a9f

    Do not treat my review for much, I am not experienced with coin selection and am only providing limited experience when looking at this code. But it looks ok to me and I trust Sjors and instagibbs’ reviews.

  21. Use BnB when preset inputs are selected db15e71e79
  22. Allow BnB when subtract fee from outputs b007efdf19
  23. achow101 force-pushed on Nov 20, 2019
  24. Sjors commented at 9:12 am on November 22, 2019: member
    re-ACK b007efdf1910db1d38671d6435d2f379bbf847d2
  25. meshcollider referenced this in commit cef87f7a48 on Nov 22, 2019
  26. meshcollider merged this on Nov 22, 2019
  27. meshcollider closed this on Nov 22, 2019

  28. sidhujag referenced this in commit 1dc1ca3075 on Nov 22, 2019
  29. fanquake referenced this in commit 19698ac6bc on Dec 1, 2019
  30. sidhujag referenced this in commit f257825d57 on Dec 1, 2019
  31. jasonbcox referenced this in commit 28efd9a54d on Sep 30, 2020
  32. sidhujag referenced this in commit d130bdca8e on Nov 10, 2020
  33. sidhujag referenced this in commit c9ca316e0d on Nov 10, 2020
  34. MarcoFalke locked this on Dec 16, 2021

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