mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Try to reduce change output to make needed fee in CreateTransaction
Once we've picked coins and dummy-signed the transaction to calculate fee, if we don't have sufficient fee, then try to meet the fee by reducing change before resorting to picking new coins.
This commit is contained in:
@@ -2537,6 +2537,18 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
|
||||
if (nFeeRet >= nFeeNeeded)
|
||||
break; // Done, enough fee included.
|
||||
|
||||
// Try to reduce change to include necessary fee
|
||||
if (nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) {
|
||||
CAmount additionalFeeNeeded = nFeeNeeded - nFeeRet;
|
||||
vector<CTxOut>::iterator change_position = txNew.vout.begin()+nChangePosInOut;
|
||||
// Only reduce change if remaining amount is still a large enough output.
|
||||
if (change_position->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) {
|
||||
change_position->nValue -= additionalFeeNeeded;
|
||||
nFeeRet += additionalFeeNeeded;
|
||||
break; // Done, able to increase fee from change
|
||||
}
|
||||
}
|
||||
|
||||
// Include more fee and try again.
|
||||
nFeeRet = nFeeNeeded;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user