test: Remove unused coin_selection param #26110

pull yancyribbens wants to merge 1 commits into bitcoin:master from yancyribbens:remove-unused-bnb-test-param changing 1 files +0 −1
  1. yancyribbens commented at 2:05 PM on September 16, 2022: contributor

    The param min_viable_change is never used in any of the subsequent tests and can be removed.

  2. fanquake added the label Tests on Sep 16, 2022
  3. achow101 commented at 2:58 PM on September 16, 2022: member

    I don't think it is unused. There are a number of calls to SelectCoins in the following tests and that function uses min_viable_change.

    Note that the tests are not exhaustive. If tests do not fail due to removal of code, it is not necessarily that the code was unnecessary or unused, but often that the test was deficient.

  4. yancyribbens commented at 3:14 PM on September 16, 2022: contributor

    @achow101 yes that's true, however this is part of bnb_search_test which is testing SelectCoinsBnB.

    It's confusing that the tests use SelectCoins to call SelectCoinsBnB right now.

  5. DrahtBot commented at 3:50 AM on September 17, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept NACK S3RK

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26111 (refactor: Simplify bnb coin_selection test params by yancyribbens)

    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.

  6. S3RK commented at 7:39 AM on September 19, 2022: contributor

    NACK. I added min_viable_change and it's definitely used. You can check it with git grep min_viable_change

    P.S. min_viable_change is not related to BnB algorithm. it's a parameter for the transaction building.

  7. yancyribbens commented at 7:52 AM on September 19, 2022: contributor

    The test suit should fail then if it is used, however the tests all pass. Under what circumstance would min_viable_change affect the BnB algorithm? Maybe there's a test or assertion that can be added if min_viable_change setting is important to the selection process.

  8. aureleoules commented at 6:52 PM on November 3, 2022: member

    It's confusing that the tests use SelectCoins to call SelectCoinsBnB right now.

    The coins supplied to the selection algorithm are of round value and match exactly the target, which is the reason why BnB should be used in SelectCoins.

    Since BnB does not create change outputs, wouldn't it make sense to remove min_viable_change from the test?

    <details> <summary>Suggestion</summary>

    diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
    index 264c0aa59..4a5309a4f 100644
    --- a/src/wallet/test/coinselector_tests.cpp
    +++ b/src/wallet/test/coinselector_tests.cpp
    @@ -345,6 +345,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
             coin_selection_params_bnb.m_effective_feerate = CFeeRate(0);
             const auto result10 = SelectCoins(*wallet, available_coins, selected_input, 10 * CENT, coin_control, coin_selection_params_bnb);
             BOOST_CHECK(result10);
    +        BOOST_CHECK_EQUAL(result10->GetAlgo(), SelectionAlgorithm::BNB);
         }
         {
             std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase());
    @@ -368,6 +369,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
             CCoinControl coin_control;
             const auto result11 = SelectCoins(*wallet, available_coins, /*pre_set_inputs=*/{}, 10 * CENT, coin_control, coin_selection_params_bnb);
             BOOST_CHECK(EquivalentResult(expected_result, *result11));
    +        BOOST_CHECK_EQUAL(result11->GetAlgo(), SelectionAlgorithm::BNB);
             available_coins.Clear();
     
             // more coins should be selected when effective fee < long term fee
    @@ -383,6 +385,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
             add_coin(1 * CENT, 2, expected_result);
             const auto result12 = SelectCoins(*wallet, available_coins, /*pre_set_inputs=*/{}, 10 * CENT, coin_control, coin_selection_params_bnb);
             BOOST_CHECK(EquivalentResult(expected_result, *result12));
    +        BOOST_CHECK_EQUAL(result12->GetAlgo(), SelectionAlgorithm::BNB);
             available_coins.Clear();
     
             // pre selected coin should be selected even if disadvantageous
    @@ -404,6 +407,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
             available_coins.coins[OutputType::BECH32].erase(++available_coins.coins[OutputType::BECH32].begin());
             const auto result13 = SelectCoins(*wallet, available_coins, selected_input, 10 * CENT, coin_control, coin_selection_params_bnb);
             BOOST_CHECK(EquivalentResult(expected_result, *result13));
    +        BOOST_CHECK_EQUAL(result13->GetAlgo(), SelectionAlgorithm::BNB);
         }
     }
    

    </details>

  9. yancyribbens commented at 7:41 PM on November 3, 2022: contributor

    @aureleoules

    The coins supplied to the selection algorithm are of round value and match exactly the target, which is the reason why BnB should be used in SelectCoins

    It seems to me it would be cleaner to just test BnB directly instead of indirectly testing via SelectCoins, however, that seems like a much larger refactor.

    Since BnB does not create change outputs, wouldn't it make sense to remove min_viable_change from the test?

    I think we are driving at the same thing. BnB does not use min_viable_change nor does it accept it as an argument, which is why I removed it in this PR. I think we could certainly add the assertion you suggested, although that seems like a separate change IMO from this PR.

  10. S3RK commented at 8:30 AM on November 7, 2022: contributor

    min_viable_change is used by ComputeAndSetWaste within SelectCoins. It just so happen that the tests pass with the current default value min_viable_change=0. I think there are a few ways to improve the test:

    1. #26466
    2. Switch to use SelectCoinsBnB instead of SelectCoins
    3. initialisemin_viable_change with 0 explicitly

    However, I'm not sure whether option 3 is a good option in light of #26466

  11. yancyribbens commented at 12:06 PM on November 7, 2022: contributor

    SelectCoinsBnB uses cost_of_change, nont min_viable_change to call ComputeAndSetWaste:

    https://github.com/bitcoin/bitcoin/blob/master/src/wallet/coinselection.cpp#L159

    As I mentioned above, I do think it's better to have the tests bnb_search_test test SelectCoinsBnB instead of testing SelectCoins (option 2). In the meantime, since SelectCoinsBnB doesn't use min_viable_change we can remove that param.

  12. DrahtBot added the label Needs rebase on Jan 4, 2023
  13. yancyribbens force-pushed on Jan 19, 2023
  14. test: Remove unused coin_selection param c65f842f7e
  15. DrahtBot removed the label Needs rebase on Jan 19, 2023
  16. achow101 commented at 3:53 PM on April 25, 2023: member

    The feature request didn't seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open issues.

    Closing due to lack of interest. Pull requests with improvements are always welcome.

  17. achow101 closed this on Apr 25, 2023

  18. bitcoin locked this on Apr 24, 2024

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

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