Actually disable BnB when there are preset inputs #12694

pull achow101 wants to merge 2 commits into bitcoin:master from achow101:fix-preset-coins-bnb changing 3 files +25 −11
  1. achow101 commented at 6:45 am on March 15, 2018: member

    We don’t want to use BnB when there are preset inputs because there is some weirdness with making that work with using the KnapsackSolver as the fallback. Currently we say that we haven’t used bnb when there are preset inputs, but we don’t actually disable BnB. This fixes that.

    I thought this was done originally. I guess it got lost in a rebase somewhere.

  2. Actually disable BnB when there are preset inputs
    We don't want to use BnB when there are preset inputs because there
    is some weirdness with making that work with using the KnapsackSolver
    as the fallback. Currently we say that we haven't used bnb when
    there are preset inputs, but we don't actually disable BnB. This fixes
    that.
    6ef99826b9
  3. eklitzke commented at 6:47 am on March 15, 2018: contributor
    Dare I ask if you can write a test for this?
  4. fanquake added the label Wallet on Mar 15, 2018
  5. achow101 commented at 3:26 pm on March 15, 2018: member
    Added a test
  6. in src/wallet/wallet.cpp:2526 in 6ef99826b9 outdated
    2522@@ -2523,6 +2523,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
    2523     {
    2524         // For now, don't use BnB if preset inputs are selected. TODO: Enable this later
    2525         bnb_used = false;
    2526+        coin_selection_params.use_bnb = false;
    


    ryanofsky commented at 6:56 pm on March 15, 2018:

    In commit “Actually disable BnB when there are preset inputs”

    Sorry to repeat my comment from the other PR, but I do think it’d be clearer to add explicit non-reference bool disable_bnb parameters to SelectCoins methods, so the CoinSelectionParams struct can remain const and not be changing on the fly. The current bug seems like evidence to me that controlling bnb through the struct is not a great idea.


    achow101 commented at 7:18 pm on March 15, 2018:
    I agree that it isn’t ideal, but having the caller control whether BnB should be used is just a temporary shim to work with the current coin selection. I intend for it to go away when the replacement fallback strategy is implemented (which I have already started doing so). I don’t think changing it now is worth the additional review effort required when the parameter will be removed later.

    eklitzke commented at 10:19 pm on March 16, 2018:

    Since this is just temporary code anyway, keep the parameter const and make a copy:

    0auto params = coin_selection_params;
    1params.use_bnb = false;
    

    That way this diff doesn’t have to change the function signature, you don’t need to change the header file, and you can have more const. Considering all of the other work this method is doing, the overhead of the copy won’t even be measurable.


    achow101 commented at 4:22 am on March 18, 2018:
    Implemented @eklitzke’s suggestion.

    achow101 commented at 4:29 am on March 18, 2018:
    Actually, I reverted that change. It makes this untestable.
  7. in src/wallet/test/coinselector_tests.cpp:237 in 3f97e7cc12 outdated
    232+    add_coin(2 * CENT);
    233+    CCoinControl coin_control;
    234+    coin_control.fAllowOtherInputs = true;
    235+    coin_control.Select(COutPoint(vCoins.at(0).tx->GetHash(), vCoins.at(0).i));
    236+    BOOST_CHECK(testWallet.SelectCoins(vCoins, 10 * CENT, setCoinsRet, nValueRet, coin_control, coin_selection_params_bnb, bnb_used));
    237+    BOOST_CHECK(!bnb_used && !coin_selection_params_bnb.use_bnb);
    


    ryanofsky commented at 6:59 pm on March 15, 2018:

    In commit “Test that BnB is not used when there are preset inputs”

    Might want to split this up into two BOOST_CHECK statements, so if one condition fails, the output shows which one is failing.


    achow101 commented at 7:22 pm on March 15, 2018:
    Done
  8. ryanofsky commented at 7:00 pm on March 15, 2018: member
    utACK 3f97e7cc129876b3b392057151cfece44e747938
  9. Test that BnB is not used when there are preset inputs 081bf54ee4
  10. achow101 force-pushed on Mar 15, 2018
  11. ryanofsky commented at 7:34 pm on March 15, 2018: member
    utACK 081bf54ee4a282eed72e7de409ad6b9ab97f2987, only change since the last review is splitting BOOST_CHECK
  12. in src/wallet/test/coinselector_tests.cpp:76 in 081bf54ee4
    72@@ -72,6 +73,7 @@ static void add_coin(const CAmount& nValue, int nAge = 6*24, bool fIsFromMe = fa
    73     }
    74     COutput output(wtx.get(), nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
    75     vCoins.push_back(output);
    76+    testWallet.AddToWallet(*wtx.get());
    


    eklitzke commented at 10:13 pm on March 16, 2018:
    I guess the code was like this when you started, but it seems kind of dangerous to be mutating global variables in the test suite like this, because it can cause errors to propagate from one test to another. It looks like it would be pretty straightforward to change the code in the test to not use globals. Consider making these variables local to each method (maybe in a future PR?).

    achow101 commented at 4:21 am on March 18, 2018:
    testWallet isn’t actually used for anything in the tests except for a way to call SelectCoins and SelectCoinsMinConf. Furthermore the coins in the wallet are never actually used by either of those two functions, the only reason it is needed here so that we can pre-select some coins for the test that was just added. And that test is also temporary, so I think it is fine as is as this change does not have any effect on the other tests.

    eklitzke commented at 7:17 am on March 19, 2018:
    Agree that it’s fine as is, but boy scout mentality (“leave you camp site cleaner than it was before”) is helpful, especially in code bases that have a lot of existing style violations (like Bitcoin).

    instagibbs commented at 6:57 pm on March 21, 2018:
    I’d also like to see a little cleanup here, if it’s not much trouble.

    achow101 commented at 7:11 pm on March 21, 2018:
    It’s a lot of trouble to clean this up. The diff would be quite large and out of scope for this PR IMO. I think this is partially why SelectCoins itself is never actually tested; instead all of the tests focus on SelectCoinsMinConf.
  13. fanquake requested review from morcos on Mar 17, 2018
  14. achow101 force-pushed on Mar 18, 2018
  15. achow101 force-pushed on Mar 18, 2018
  16. achow101 force-pushed on Mar 18, 2018
  17. instagibbs approved
  18. instagibbs commented at 7:05 pm on March 21, 2018: member
    utACK
  19. laanwj merged this on Mar 22, 2018
  20. laanwj closed this on Mar 22, 2018

  21. laanwj referenced this in commit 9552dfb1f6 on Mar 22, 2018
  22. achow101 referenced this in commit dd7fd0ea85 on Jun 8, 2018
  23. achow101 referenced this in commit 8de2f67ee7 on Jun 9, 2018
  24. achow101 referenced this in commit bd55b5bfd0 on Jun 11, 2018
  25. achow101 referenced this in commit 8759e05987 on Jun 11, 2018
  26. achow101 referenced this in commit 4ad1cb12db on Jul 3, 2018
  27. achow101 referenced this in commit 2f4ab05c5a on Aug 17, 2018
  28. gmaxwell commented at 5:10 pm on September 14, 2018: contributor
    @achow101 Are you keeping a coinselection todo someplace? The ability to bnb with preset inputs (less than the demanded amount) would be nice, it shouldn’t be forgotten.
  29. achow101 commented at 6:27 pm on September 14, 2018: member

    @gmaxwell I think everything that really needs to be done is done in #13307. I haven’t been working on it recently, partially because SRD does not seem to do as well with regards to the number of UTXOs in the wallet.

    But otherwise, I don’t have a todo tracking coin selection things.

  30. instagibbs referenced this in commit 6736c5a004 on Aug 14, 2019
  31. instagibbs referenced this in commit d06ed67e28 on Aug 14, 2019
  32. instagibbs referenced this in commit 98e51b4378 on Aug 14, 2019
  33. PastaPastaPasta referenced this in commit ee04176530 on Apr 13, 2021
  34. xdustinface referenced this in commit 32cb85da97 on Apr 13, 2021
  35. MarcoFalke locked this on Sep 8, 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-12-18 15:12 UTC

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