wallet: replace MIN_FINAL_CHANGE with the discard threshold

MIN_FINAL_CHANGE was a hardcoded limit that was impossible to be
changed by users. This causes problems when the dust limit is
changing because then a user would need a new release to be able
to have lower change outputs.

This commit replaces the entire notion of MIN_FINAL_CHANGE to just
follow the discard threshold, which can be set by the user using
-discardthreshold.
This commit is contained in:
Patrick Lodder 2021-10-09 16:41:41 +02:00
parent c338c5e6c4
commit 2cdacb07ab
No known key found for this signature in database
GPG Key ID: 2D3A345B98D0DC1F
2 changed files with 10 additions and 3 deletions

View File

@ -2735,7 +2735,16 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
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) {
/* Dogecoin: this has been changed from a static MIN_FINAL_CHANGE that
* followed DEFAULT_DISCARD_THRESHOLD to instead use the configurable
* discard threshold.
*
* Note:
* If MIN_CHANGE ever becomes configurable or otherwise changes to no
* longer be derived from DEFAULT_DISCARD_THRESHOLD, then this check
* must be adapted.
*/
if (change_position->nValue >= discardThreshold + additionalFeeNeeded) {
change_position->nValue -= additionalFeeNeeded;
nFeeRet += additionalFeeNeeded;
break; // Done, able to increase fee from change

View File

@ -105,8 +105,6 @@ static const CAmount WALLET_INCREMENTAL_RELAY_FEE = RECOMMENDED_MIN_TX_FEE / 10;
*/
//! target minimum change amount
static const CAmount MIN_CHANGE = DEFAULT_DISCARD_THRESHOLD + 2 * RECOMMENDED_MIN_TX_FEE;
//! final minimum change amount after paying for fees
static const CAmount MIN_FINAL_CHANGE = DEFAULT_DISCARD_THRESHOLD;
//! Default for -spendzeroconfchange
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;