Merge bitcoin/bitcoin#24530: wallet: assert BnB's internally calculated waste is the same as GetSelectionWaste

ec7d73628a6397fca3b5b852d4e97ff918b6d3a6 [wallet] assert BnB internally calculated waste is the same as GetSelectionWaste() (glozow)

Pull request description:

  #22009 introduced a `GetSelectionWaste()` function to determine how much "waste" a coin selection solution has, and is a mirror of the waste calculated inside of `SelectCoinsBnB()`. It would be bad for these two waste metrics to deviate, since it could negatively affect how often we select the BnB solution. Add an assertion to help tests catch a potential accidental change.

ACKs for top commit:
  achow101:
    ACK ec7d73628a6397fca3b5b852d4e97ff918b6d3a6
  Xekyo:
    ACK ec7d73628a6397fca3b5b852d4e97ff918b6d3a6

Tree-SHA512: 3ab7ad45ae92e7ce3f21824fb975105b6be8382edf47c252df5d13d973a3abdcb675132d223b42fcbb669cca879672c904b8a58d0676e12bf381a9219f4db37c
This commit is contained in:
Andrew Chow 2022-03-11 16:40:06 +00:00
commit c109e7d51c
No known key found for this signature in database
GPG Key ID: 17565732E08E5E41
2 changed files with 2 additions and 1 deletions

View File

@ -163,6 +163,8 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
result.AddInput(utxo_pool.at(i));
}
}
result.ComputeAndSetWaste(CAmount{0});
assert(best_waste == result.GetWaste());
return result;
}

View File

@ -379,7 +379,6 @@ std::optional<SelectionResult> AttemptSelection(const CWallet& wallet, const CAm
// Note that unlike KnapsackSolver, we do not include the fee for creating a change output as BnB will not create a change output.
std::vector<OutputGroup> positive_groups = GroupOutputs(wallet, coins, coin_selection_params, eligibility_filter, true /* positive_only */);
if (auto bnb_result{SelectCoinsBnB(positive_groups, nTargetValue, coin_selection_params.m_cost_of_change)}) {
bnb_result->ComputeAndSetWaste(CAmount(0));
results.push_back(*bnb_result);
}