Skip to content

Commit ec7d736

Browse files
committed
[wallet] assert BnB internally calculated waste is the same as GetSelectionWaste()
These two implementations of waste calculation should never deviate. Still keep the SelectCoinsBnB internal calculation because incremental calculate-as-you-go is much more performant than calling GetSelectionWaste() over and over again.
1 parent ce1fabe commit ec7d736

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/wallet/coinselection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
163163
result.AddInput(utxo_pool.at(i));
164164
}
165165
}
166+
result.ComputeAndSetWaste(CAmount{0});
167+
assert(best_waste == result.GetWaste());
166168

167169
return result;
168170
}

src/wallet/spend.cpp

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

0 commit comments

Comments
 (0)