diff options
author | Alex Morcos <morcos@chaincode.com> | 2017-04-25 15:39:32 -0400 |
---|---|---|
committer | Alex Morcos <morcos@chaincode.com> | 2017-06-13 12:35:04 -0400 |
commit | 1bebfc8d3aa615dfdd0221f21b87319e36821b71 (patch) | |
tree | 092a7224efb48fac182bc26aa2aef39844884c01 /src/wallet | |
parent | 9c248e39f2807a7f89e555e99cc55cb2de1ad335 (diff) |
Output Fee Estimation Calculations in CreateTransaction
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/feebumper.cpp | 2 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 37 | ||||
-rw-r--r-- | src/wallet/wallet.h | 3 |
3 files changed, 31 insertions, 11 deletions
diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp index 46ef87b7b1..6a9e6cf9ff 100644 --- a/src/wallet/feebumper.cpp +++ b/src/wallet/feebumper.cpp @@ -165,7 +165,7 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, int newConf nNewFee = totalFee; nNewFeeRate = CFeeRate(totalFee, maxNewTxSize); } else { - nNewFee = CWallet::GetMinimumFee(maxNewTxSize, newConfirmTarget, mempool, ::feeEstimator, ignoreGlobalPayTxFee); + nNewFee = CWallet::GetMinimumFee(maxNewTxSize, newConfirmTarget, mempool, ::feeEstimator, nullptr, ignoreGlobalPayTxFee); nNewFeeRate = CFeeRate(nNewFee, maxNewTxSize); // New fee rate must be at least old rate + minimum incremental relay rate diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b2706d09f6..796580728e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2524,7 +2524,8 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT assert(txNew.nLockTime <= (unsigned int)chainActive.Height()); assert(txNew.nLockTime < LOCKTIME_THRESHOLD); - + FeeCalculation feeCalc; + unsigned int nBytes; { std::set<CInputCoin> setCoins; LOCK2(cs_main, cs_wallet); @@ -2696,7 +2697,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT return false; } - unsigned int nBytes = GetVirtualTransactionSize(txNew); + nBytes = GetVirtualTransactionSize(txNew); CTransaction txNewConst(txNew); @@ -2711,7 +2712,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT if (coinControl && coinControl->nConfirmTarget > 0) currentConfirmationTarget = coinControl->nConfirmTarget; - CAmount nFeeNeeded = GetMinimumFee(nBytes, currentConfirmationTarget, ::mempool, ::feeEstimator); + CAmount nFeeNeeded = GetMinimumFee(nBytes, currentConfirmationTarget, ::mempool, ::feeEstimator, &feeCalc); if (coinControl && coinControl->fOverrideFeeRate) nFeeNeeded = coinControl->nFeeRate.GetFee(nBytes); @@ -2808,6 +2809,15 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT return false; } } + + LogPrintf("Fee Calculation: Fee:%d Bytes:%u Tgt:%d (requested %d) Reason:\"%s\" Decay %.5f: Estimation: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out) Fail: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out)\n", + nFeeRet, nBytes, feeCalc.returnedTarget, feeCalc.desiredTarget, StringForFeeReason(feeCalc.reason), feeCalc.est.decay, + feeCalc.est.pass.start, feeCalc.est.pass.end, + 100 * feeCalc.est.pass.withinTarget / (feeCalc.est.pass.totalConfirmed + feeCalc.est.pass.inMempool + feeCalc.est.pass.leftMempool), + feeCalc.est.pass.withinTarget, feeCalc.est.pass.totalConfirmed, feeCalc.est.pass.inMempool, feeCalc.est.pass.leftMempool, + feeCalc.est.fail.start, feeCalc.est.fail.end, + 100 * feeCalc.est.fail.withinTarget / (feeCalc.est.fail.totalConfirmed + feeCalc.est.fail.inMempool + feeCalc.est.fail.leftMempool), + feeCalc.est.fail.withinTarget, feeCalc.est.fail.totalConfirmed, feeCalc.est.fail.inMempool, feeCalc.est.fail.leftMempool); return true; } @@ -2882,23 +2892,32 @@ CAmount CWallet::GetRequiredFee(unsigned int nTxBytes) return std::max(minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFee(nTxBytes)); } -CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, bool ignoreGlobalPayTxFee) +CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation *feeCalc, bool ignoreGlobalPayTxFee) { // payTxFee is the user-set global for desired feerate CAmount nFeeNeeded = payTxFee.GetFee(nTxBytes); // User didn't set: use -txconfirmtarget to estimate... if (nFeeNeeded == 0 || ignoreGlobalPayTxFee) { - int estimateFoundTarget = nConfirmTarget; - nFeeNeeded = estimator.estimateSmartFee(nConfirmTarget, &estimateFoundTarget, pool).GetFee(nTxBytes); + nFeeNeeded = estimator.estimateSmartFee(nConfirmTarget, feeCalc, pool, true).GetFee(nTxBytes); // ... unless we don't have enough mempool data for estimatefee, then use fallbackFee - if (nFeeNeeded == 0) + if (nFeeNeeded == 0) { nFeeNeeded = fallbackFee.GetFee(nTxBytes); + if (feeCalc) feeCalc->reason = FeeReason::FALLBACK; + } + } else { + if (feeCalc) feeCalc->reason = FeeReason::PAYTXFEE; } // prevent user from paying a fee below minRelayTxFee or minTxFee - nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes)); + CAmount requiredFee = GetRequiredFee(nTxBytes); + if (requiredFee > nFeeNeeded) { + nFeeNeeded = requiredFee; + if (feeCalc) feeCalc->reason = FeeReason::REQUIRED; + } // But always obey the maximum - if (nFeeNeeded > maxTxFee) + if (nFeeNeeded > maxTxFee) { nFeeNeeded = maxTxFee; + if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE; + } return nFeeNeeded; } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index a9c50aee4d..f0bf2c5afb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -76,6 +76,7 @@ class CScheduler; class CTxMemPool; class CBlockPolicyEstimator; class CWalletTx; +class FeeCalculation; /** (client) version numbers for particular wallet features */ enum WalletFeature @@ -956,7 +957,7 @@ public: * Estimate the minimum fee considering user set parameters * and the required fee */ - static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, bool ignoreGlobalPayTxFee = false); + static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation *feeCalc = nullptr, bool ignoreGlobalPayTxFee = false); /** * Return the minimum required fee taking into account the * floating relay fee and user set minimum transaction fee |