aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/coinselection.cpp
diff options
context:
space:
mode:
authoryancy <yancy@yancy.lol>2022-09-16 14:26:00 +0200
committeryancy <yancy@yancy.lol>2022-09-17 10:07:51 +0200
commit81d4a2b14ff65fe07085ef2a967a466015370ce3 (patch)
tree8c38165de7d30a129d4ee32342920f92023840e9 /src/wallet/coinselection.cpp
parent365aca40453995163bbd17231251512f9f9a103b (diff)
downloadbitcoin-81d4a2b14ff65fe07085ef2a967a466015370ce3.tar.xz
refactor: Move feerate comparison invariant outside of the loop
Diffstat (limited to 'src/wallet/coinselection.cpp')
-rw-r--r--src/wallet/coinselection.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index 718bced07d..c281c91585 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -87,13 +87,15 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
std::vector<size_t> best_selection;
CAmount best_waste = MAX_MONEY;
+ bool is_feerate_high = utxo_pool.at(0).fee > utxo_pool.at(0).long_term_fee;
+
// Depth First search loop for choosing the UTXOs
for (size_t curr_try = 0, utxo_pool_index = 0; curr_try < TOTAL_TRIES; ++curr_try, ++utxo_pool_index) {
// Conditions for starting a backtrack
bool backtrack = false;
if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
curr_value > selection_target + cost_of_change || // Selected value is out of range, go back and try other branch
- (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
+ (curr_waste > best_waste && is_feerate_high)) { // Don't select things which we know will be more wasteful if the waste is increasing
backtrack = true;
} else if (curr_value >= selection_target) { // Selected value is within range
curr_waste += (curr_value - selection_target); // This is the excess value which is added to the waste for the below comparison