Skip to content

Commit 7bb07bf

Browse files
committed
Merge bitcoin/bitcoin#25932: refactor: Simplify backtrack logic
81d4a2b refactor: Move feerate comparison invariant outside of the loop (yancy) 365aca4 refactor: Simplify feerate comparison statement (yancy) Pull request description: This is a small nit, however I think it's more understandable to write: `utxo_pool.at(0).fee > utxo_pool.at(0).long_term_fee` vs `(utxo_pool.at(0).fee - utxo_pool.at(0).long_term_fee) > 0` ACKs for top commit: Xekyo: ACK 81d4a2b achow101: ACK 81d4a2b aureleoules: ACK 81d4a2b Tree-SHA512: 3e89377989c36716b53114fe40178261671dde5688075fab1c21ec173ac310f8c84ed6af90354d7c329176cb7262dfcaa7191fd19847d3b7147a9a10c3e31176
2 parents 1e6b384 + 81d4a2b commit 7bb07bf

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

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