Skip to content

Commit 81d4a2b

Browse files
committed
refactor: Move feerate comparison invariant outside of the loop
1 parent 365aca4 commit 81d4a2b

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
@@ -87,13 +87,15 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
8787
std::vector<size_t> best_selection;
8888
CAmount best_waste = MAX_MONEY;
8989

90+
bool is_feerate_high = utxo_pool.at(0).fee > utxo_pool.at(0).long_term_fee;
91+
9092
// Depth First search loop for choosing the UTXOs
9193
for (size_t curr_try = 0, utxo_pool_index = 0; curr_try < TOTAL_TRIES; ++curr_try, ++utxo_pool_index) {
9294
// Conditions for starting a backtrack
9395
bool backtrack = false;
9496
if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
9597
curr_value > selection_target + cost_of_change || // Selected value is out of range, go back and try other branch
96-
(curr_waste > best_waste && (utxo_pool.at(0).fee > utxo_pool.at(0).long_term_fee))) { // Don't select things which we know will be more wasteful if the waste is increasing
98+
(curr_waste > best_waste && is_feerate_high)) { // Don't select things which we know will be more wasteful if the waste is increasing
9799
backtrack = true;
98100
} else if (curr_value >= selection_target) { // Selected value is within range
99101
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)