mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-10 15:47:17 +02:00
Enforce minRelayTxFee on wallet created tx and add a maxtxfee option.
Previously the minRelayTxFee was only enforced on user specified values.
It was possible for smartfee to produce a fee below minRelayTxFee which
would just result in the transaction getting stuck because it can't be
relayed.
This also introduces a maxtxfee option which sets an absolute maximum
for any fee created by the wallet, with an intention of increasing
user confidence that the automatic fees won't burn them. This was
frequently a concern even before smartfees.
If the configured fee policy won't even allow the wallet to meet the relay
fee the transaction creation may be aborted.
Rebased-From: aa279d6131
Github-Pull: #5485
This commit is contained in:
committed by
Wladimir J. van der Laan
parent
8446262597
commit
11855c1f99
@@ -26,6 +26,7 @@ using namespace std;
|
||||
* Settings
|
||||
*/
|
||||
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE);
|
||||
CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE;
|
||||
unsigned int nTxConfirmTarget = 1;
|
||||
bool bSpendZeroConfChange = true;
|
||||
bool fSendFreeTransactions = false;
|
||||
@@ -1499,28 +1500,33 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, CAmount> >& vecSend,
|
||||
}
|
||||
dPriority = wtxNew.ComputePriority(dPriority, nBytes);
|
||||
|
||||
// Can we complete this as a free transaction?
|
||||
if (fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE)
|
||||
{
|
||||
// Not enough fee: enough priority?
|
||||
double dPriorityNeeded = mempool.estimatePriority(nTxConfirmTarget);
|
||||
// Not enough mempool history to estimate: use hard-coded AllowFree.
|
||||
if (dPriorityNeeded <= 0 && AllowFree(dPriority))
|
||||
break;
|
||||
|
||||
// Small enough, and priority high enough, to send for free
|
||||
if (dPriorityNeeded > 0 && dPriority >= dPriorityNeeded)
|
||||
break;
|
||||
}
|
||||
|
||||
CAmount nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
|
||||
|
||||
// If we made it here and we aren't even able to meet the relay fee on the next pass, give up
|
||||
// because we must be at the maximum allowed fee.
|
||||
if (nFeeNeeded < ::minRelayTxFee.GetFee(nBytes))
|
||||
{
|
||||
strFailReason = _("Transaction too large for fee policy");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nFeeRet >= nFeeNeeded)
|
||||
break; // Done, enough fee included.
|
||||
|
||||
// Too big to send for free? Include more fee and try again:
|
||||
if (!fSendFreeTransactions || nBytes > MAX_FREE_TRANSACTION_CREATE_SIZE)
|
||||
{
|
||||
nFeeRet = nFeeNeeded;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Not enough fee: enough priority?
|
||||
double dPriorityNeeded = mempool.estimatePriority(nTxConfirmTarget);
|
||||
// Not enough mempool history to estimate: use hard-coded AllowFree.
|
||||
if (dPriorityNeeded <= 0 && AllowFree(dPriority))
|
||||
break;
|
||||
|
||||
// Small enough, and priority high enough, to send for free
|
||||
if (dPriorityNeeded > 0 && dPriority >= dPriorityNeeded)
|
||||
break;
|
||||
|
||||
// Include more fee and try again.
|
||||
nFeeRet = nFeeNeeded;
|
||||
continue;
|
||||
@@ -1591,9 +1597,6 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
|
||||
{
|
||||
// payTxFee is user-set "I want to pay this much"
|
||||
CAmount nFeeNeeded = payTxFee.GetFee(nTxBytes);
|
||||
// prevent user from paying a non-sense fee (like 1 satoshi): 0 < fee < minRelayFee
|
||||
if (nFeeNeeded > 0 && nFeeNeeded < ::minRelayTxFee.GetFee(nTxBytes))
|
||||
nFeeNeeded = ::minRelayTxFee.GetFee(nTxBytes);
|
||||
// user selected total at least (default=true)
|
||||
if (fPayAtLeastCustomFee && nFeeNeeded > 0 && nFeeNeeded < payTxFee.GetFeePerK())
|
||||
nFeeNeeded = payTxFee.GetFeePerK();
|
||||
@@ -1604,6 +1607,12 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
|
||||
// back to a hard-coded fee
|
||||
if (nFeeNeeded == 0)
|
||||
nFeeNeeded = minTxFee.GetFee(nTxBytes);
|
||||
// prevent user from paying a non-sense fee (like 1 satoshi): 0 < fee < minRelayFee
|
||||
if (nFeeNeeded < ::minRelayTxFee.GetFee(nTxBytes))
|
||||
nFeeNeeded = ::minRelayTxFee.GetFee(nTxBytes);
|
||||
// But always obey the maximum
|
||||
if (nFeeNeeded > maxTxFee)
|
||||
nFeeNeeded = maxTxFee;
|
||||
return nFeeNeeded;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user