scripted-diff: rename some variables

actual_target -> selection_target
nChange -> change_and_fee

-BEGIN VERIFY SCRIPT-
sed -i -e 's/actual_target/selection_target/g' src/wallet/coinselection.cpp
sed -i -e '2801,3691s/nChange /change_and_fee /g' src/wallet/wallet.cpp
sed -i -e '2801,3691s/nChange,/change_and_fee,/g' src/wallet/wallet.cpp
sed -i -e '2801,3691s/nChange;/change_and_fee;/g' src/wallet/wallet.cpp
-END VERIFY SCRIPT-
This commit is contained in:
Andrew Chow 2021-05-06 14:12:13 -04:00
parent b34bf2b42c
commit 1bf4a62cb6
2 changed files with 12 additions and 12 deletions

View File

@ -70,7 +70,7 @@ bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& target_v
std::vector<bool> curr_selection; // select the utxo at this index std::vector<bool> curr_selection; // select the utxo at this index
curr_selection.reserve(utxo_pool.size()); curr_selection.reserve(utxo_pool.size());
CAmount actual_target = not_input_fees + target_value; CAmount selection_target = not_input_fees + target_value;
// Calculate curr_available_value // Calculate curr_available_value
CAmount curr_available_value = 0; CAmount curr_available_value = 0;
@ -79,7 +79,7 @@ bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& target_v
assert(utxo.effective_value > 0); assert(utxo.effective_value > 0);
curr_available_value += utxo.effective_value; curr_available_value += utxo.effective_value;
} }
if (curr_available_value < actual_target) { if (curr_available_value < selection_target) {
return false; return false;
} }
@ -94,12 +94,12 @@ bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& target_v
for (size_t i = 0; i < TOTAL_TRIES; ++i) { for (size_t i = 0; i < TOTAL_TRIES; ++i) {
// Conditions for starting a backtrack // Conditions for starting a backtrack
bool backtrack = false; bool backtrack = false;
if (curr_value + curr_available_value < actual_target || // Cannot possibly reach target with the amount remaining in the curr_available_value. if (curr_value + curr_available_value < selection_target || // Cannot possibly reach target with the amount remaining in the curr_available_value.
curr_value > actual_target + cost_of_change || // Selected value is out of range, go back and try other branch 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) > 0)) { // Don't select things which we know will be more wasteful if the waste is increasing (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
backtrack = true; backtrack = true;
} else if (curr_value >= actual_target) { // Selected value is within range } else if (curr_value >= selection_target) { // Selected value is within range
curr_waste += (curr_value - actual_target); // This is the excess value which is added to the waste for the below comparison curr_waste += (curr_value - selection_target); // This is the excess value which is added to the waste for the below comparison
// Adding another UTXO after this check could bring the waste down if the long term fee is higher than the current fee. // Adding another UTXO after this check could bring the waste down if the long term fee is higher than the current fee.
// However we are not going to explore that because this optimization for the waste is only done when we have hit our target // However we are not going to explore that because this optimization for the waste is only done when we have hit our target
// value. Adding any more UTXOs will be just burning the UTXO; it will go entirely to fees. Thus we aren't going to // value. Adding any more UTXOs will be just burning the UTXO; it will go entirely to fees. Thus we aren't going to
@ -112,7 +112,7 @@ bool SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool, const CAmount& target_v
break; break;
} }
} }
curr_waste -= (curr_value - actual_target); // Remove the excess value as we will be selecting different coins now curr_waste -= (curr_value - selection_target); // Remove the excess value as we will be selecting different coins now
backtrack = true; backtrack = true;
} }

View File

@ -2990,19 +2990,19 @@ bool CWallet::CreateTransactionInternal(
bnb_used = false; bnb_used = false;
} }
const CAmount nChange = nValueIn - nValueToSelect; const CAmount change_and_fee = nValueIn - nValueToSelect;
if (nChange > 0) if (change_and_fee > 0)
{ {
// Fill a vout to ourself // Fill a vout to ourself
CTxOut newTxOut(nChange, scriptChange); CTxOut newTxOut(change_and_fee, scriptChange);
// Never create dust outputs; if we would, just // Never create dust outputs; if we would, just
// add the dust to the fee. // add the dust to the fee.
// The nChange when BnB is used is always going to go to fees. // The change_and_fee when BnB is used is always going to go to fees.
if (IsDust(newTxOut, coin_selection_params.m_discard_feerate) || bnb_used) if (IsDust(newTxOut, coin_selection_params.m_discard_feerate) || bnb_used)
{ {
nChangePosInOut = -1; nChangePosInOut = -1;
nFeeRet += nChange; nFeeRet += change_and_fee;
} }
else else
{ {