0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

coinselection: Track whether CG completed

CoinGrinder may not be able to exhaustively search all potentially
interesting combinations for large UTXO pools, so we keep track of
whether the search was terminated by the iteration limit.
This commit is contained in:
Murch 2024-01-08 15:35:05 -05:00
parent 7488acc646
commit 1502231229
2 changed files with 20 additions and 0 deletions

View file

@ -426,6 +426,7 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
if (curr_try >= TOTAL_TRIES) {
// Solution is not guaranteed to be optimal if `curr_try` hit TOTAL_TRIES
result.SetAlgoCompleted(false);
break;
}
@ -447,6 +448,7 @@ util::Result<SelectionResult> CoinGrinder(std::vector<OutputGroup>& utxo_pool, c
// Set `next_utxo` to one after last selected, then deselect last selected UTXO
if (curr_selection.empty()) {
// Exhausted search space before running into attempt limit
result.SetAlgoCompleted(true);
break;
}
next_utxo = curr_selection.back() + 1;
@ -794,6 +796,16 @@ void SelectionResult::ComputeAndSetWaste(const CAmount min_viable_change, const
}
}
void SelectionResult::SetAlgoCompleted(bool algo_completed)
{
m_algo_completed = algo_completed;
}
bool SelectionResult::GetAlgoCompleted() const
{
return m_algo_completed;
}
void SelectionResult::SetSelectionsEvaluated(size_t attempts)
{
m_selections_evaluated = attempts;

View file

@ -330,6 +330,8 @@ private:
bool m_use_effective{false};
/** The computed waste */
std::optional<CAmount> m_waste;
/** False if algorithm was cut short by hitting limit of attempts and solution is non-optimal */
bool m_algo_completed{true};
/** The count of selections that were evaluated by this coin selection attempt */
size_t m_selections_evaluated;
/** Total weight of the selected inputs */
@ -389,6 +391,12 @@ public:
void ComputeAndSetWaste(const CAmount min_viable_change, const CAmount change_cost, const CAmount change_fee);
[[nodiscard]] CAmount GetWaste() const;
/** Tracks that algorithm was able to exhaustively search the entire combination space before hitting limit of tries */
void SetAlgoCompleted(bool algo_completed);
/** Get m_algo_completed */
bool GetAlgoCompleted() const;
/** Record the number of selections that were evaluated */
void SetSelectionsEvaluated(size_t attempts);