aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurch <murch@murch.one>2024-01-08 15:35:05 -0500
committerMurch <murch@murch.one>2024-02-09 10:50:10 +0100
commit1502231229dbc32c94e80a2fc2959275c5d246ef (patch)
tree2867b67a28771ee9ae862146d549e4652bbd0833
parent7488acc64685ae16e20b78e7ad018137f27fe404 (diff)
downloadbitcoin-1502231229dbc32c94e80a2fc2959275c5d246ef.tar.xz
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.
-rw-r--r--src/wallet/coinselection.cpp12
-rw-r--r--src/wallet/coinselection.h8
2 files changed, 20 insertions, 0 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index 20944b3c8d..abd710d56d 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -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;
diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h
index ba9e6bafd9..80c92e1b0e 100644
--- a/src/wallet/coinselection.h
+++ b/src/wallet/coinselection.h
@@ -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);