diff options
| author | Alex Morcos <[email protected]> | 2017-08-25 14:46:07 -0500 |
|---|---|---|
| committer | Alex Morcos <[email protected]> | 2017-08-25 14:59:35 -0500 |
| commit | a54c7b94f8825e9b52fec9066fe7c1d5b6f53482 (patch) | |
| tree | 3418b0e5a9c31a385d250f2bb21cf07e1f86a1b9 /src/wallet/wallet.cpp | |
| parent | Merge #11112: [developer-notes] By default, declare single-argument construct... (diff) | |
| download | discoin-a54c7b94f8825e9b52fec9066fe7c1d5b6f53482.tar.xz discoin-a54c7b94f8825e9b52fec9066fe7c1d5b6f53482.zip | |
Fix rounding errors in calculation of minimum change size
Diffstat (limited to 'src/wallet/wallet.cpp')
| -rw-r--r-- | src/wallet/wallet.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 291bcc7a2..503354b66 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2861,13 +2861,15 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT // new inputs. We now know we only need the smaller fee // (because of reduced tx size) and so we should add a // change output. Only try this once. - CAmount fee_needed_for_change = GetMinimumFee(change_prototype_size, coin_control, ::mempool, ::feeEstimator, nullptr); - CAmount minimum_value_for_change = GetDustThreshold(change_prototype_txout, discard_rate); - CAmount max_excess_fee = fee_needed_for_change + minimum_value_for_change; - if (nFeeRet > nFeeNeeded + max_excess_fee && nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && pick_new_inputs) { - pick_new_inputs = false; - nFeeRet = nFeeNeeded + fee_needed_for_change; - continue; + if (nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && pick_new_inputs) { + unsigned int tx_size_with_change = nBytes + change_prototype_size + 2; // Add 2 as a buffer in case increasing # of outputs changes compact size + CAmount fee_needed_with_change = GetMinimumFee(tx_size_with_change, coin_control, ::mempool, ::feeEstimator, nullptr); + CAmount minimum_value_for_change = GetDustThreshold(change_prototype_txout, discard_rate); + if (nFeeRet >= fee_needed_with_change + minimum_value_for_change) { + pick_new_inputs = false; + nFeeRet = fee_needed_with_change; + continue; + } } // If we have change output already, just increase it |