Skip to content

Commit b1a95d8

Browse files
committed
merge bitcoin#25932: Simplify backtrack logic
1 parent eff27a4 commit b1a95d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/wallet/coinselection.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
9090
std::vector<size_t> best_selection;
9191
CAmount best_waste = MAX_MONEY;
9292

93+
bool is_feerate_high = utxo_pool.at(0).fee > utxo_pool.at(0).long_term_fee;
94+
9395
// Depth First search loop for choosing the UTXOs
9496
for (size_t curr_try = 0, utxo_pool_index = 0; curr_try < TOTAL_TRIES; ++curr_try, ++utxo_pool_index) {
9597
// Conditions for starting a backtrack
9698
bool backtrack = false;
9799
if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
98100
curr_value > selection_target + cost_of_change || // Selected value is out of range, go back and try other branch
99-
(curr_waste > best_waste && (utxo_pool.at(0).fee - utxo_pool.at(0).long_term_fee) > 0)) { // Don't select things which we know will be more wasteful if the waste is increasing
101+
(curr_waste > best_waste && is_feerate_high)) { // Don't select things which we know will be more wasteful if the waste is increasing
100102
backtrack = true;
101103
} else if (curr_value >= selection_target) { // Selected value is within range
102104
curr_waste += (curr_value - selection_target); // This is the excess value which is added to the waste for the below comparison

0 commit comments

Comments
 (0)