Skip to content

Commit 9d20052

Browse files
committed
doc: Revise comments and whitespace to clarify
1 parent def43a4 commit 9d20052

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/wallet/coinselection.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
7171
// Calculate curr_available_value
7272
CAmount curr_available_value = 0;
7373
for (const OutputGroup& utxo : utxo_pool) {
74-
// Assert that this utxo is not negative. It should never be negative, effective value calculation should have removed it
74+
// Assert that this utxo is not negative. It should never be negative,
75+
// effective value calculation should have removed it
7576
assert(utxo.GetSelectionAmount() > 0);
7677
curr_available_value += utxo.GetSelectionAmount();
7778
}
@@ -90,8 +91,8 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
9091
for (size_t curr_try = 0, utxo_pool_index = 0; curr_try < TOTAL_TRIES; ++curr_try, ++utxo_pool_index) {
9192
// Conditions for starting a backtrack
9293
bool backtrack = false;
93-
if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
94-
curr_value > selection_target + cost_of_change || // Selected value is out of range, go back and try other branch
94+
if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
95+
curr_value > selection_target + cost_of_change || // Selected value is out of range, go back and try other branch
9596
(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
9697
backtrack = true;
9798
} else if (curr_value >= selection_target) { // Selected value is within range
@@ -111,13 +112,12 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
111112
backtrack = true;
112113
}
113114

114-
// Backtracking, moving backwards
115-
if (backtrack) {
115+
if (backtrack) { // Backtracking, moving backwards
116116
if (curr_selection.empty()) { // We have walked back to the first utxo and no branch is untraversed. All solutions searched
117117
break;
118118
}
119119

120-
// Walk backwards to find the last included UTXO that still needs to have its omission branch traversed.
120+
// Add omitted UTXOs back to lookahead before traversing the omission branch of last included UTXO.
121121
for (--utxo_pool_index; utxo_pool_index > curr_selection.back(); --utxo_pool_index) {
122122
curr_available_value += utxo_pool.at(utxo_pool_index).GetSelectionAmount();
123123
}
@@ -134,11 +134,11 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_poo
134134
// Remove this utxo from the curr_available_value utxo amount
135135
curr_available_value -= utxo.GetSelectionAmount();
136136

137-
// Avoid searching a branch if the previous UTXO has the same value and same waste and was excluded. Since the ratio of fee to
138-
// long term fee is the same, we only need to check if one of those values match in order to know that the waste is the same.
139137
if (curr_selection.empty() ||
140138
// The previous index is included and therefore not relevant for exclusion shortcut
141139
(utxo_pool_index - 1) == curr_selection.back() ||
140+
// Avoid searching a branch if the previous UTXO has the same value and same waste and was excluded.
141+
// Since the ratio of fee to long term fee is the same, we only need to check if one of those values match in order to know that the waste is the same.
142142
utxo.GetSelectionAmount() != utxo_pool.at(utxo_pool_index - 1).GetSelectionAmount() ||
143143
utxo.fee != utxo_pool.at(utxo_pool_index - 1).fee)
144144
{

0 commit comments

Comments
 (0)