mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 13:59:06 +01:00
ef4dfa8524
(script modified to account for Dash backports, doesn't account for rebasing) ------------- BEGIN SCRIPT --------------- mkdir -p src/util git mv src/util.h src/util/system.h git mv src/util.cpp src/util/system.cpp git mv src/utilmemory.h src/util/memory.h git mv src/utilmoneystr.h src/util/moneystr.h git mv src/utilmoneystr.cpp src/util/moneystr.cpp git mv src/utilstrencodings.h src/util/strencodings.h git mv src/utilstrencodings.cpp src/util/strencodings.cpp git mv src/utiltime.h src/util/time.h git mv src/utiltime.cpp src/util/time.cpp git mv src/utilasmap.h src/util/asmap.h git mv src/utilasmap.cpp src/util/asmap.cpp git mv src/utilstring.h src/util/string.h git mv src/utilstring.cpp src/util/string.cpp gsed -i 's/<util\.h>/<util\/system\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilmemory\.h>/<util\/memory\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilmoneystr\.h>/<util\/moneystr\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utiltime\.h>/<util\/time\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilasmap\.h>/<util\/asmap\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/<utilstring\.h>/<util\/string\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') gsed -i 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h gsed -i 's/BITCOIN_UTILMEMORY_H/BITCOIN_UTIL_MEMORY_H/g' src/util/memory.h gsed -i 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h gsed -i 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h gsed -i 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h gsed -i 's/BITCOIN_UTILASMAP_H/BITCOIN_UTIL_ASMAP_H/g' src/util/asmap.h gsed -i 's/BITCOIN_UTILSTRING_H/BITCOIN_UTIL_STRING_H/g' src/util/string.h gsed -i 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am gsed -i 's/utilmemory\.\(h\|cpp\)/util\/memory\.\1/g' src/Makefile.am gsed -i 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am gsed -i 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am gsed -i 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am gsed -i 's/utilasmap\.\(h\|cpp\)/util\/asmap\.\1/g' src/Makefile.am gsed -i 's/utilstring\.\(h\|cpp\)/util\/string\.\1/g' src/Makefile.am gsed -i 's/-> util ->/-> util\/system ->/' test/lint/lint-circular-dependencies.sh gsed -i 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-format-strings.py test/lint/lint-locale-dependence.sh gsed -i 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh gsed -i 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh ------------- END SCRIPT ---------------
99 lines
4.4 KiB
C++
99 lines
4.4 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2017 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <wallet/fees.h>
|
|
|
|
#include <policy/policy.h>
|
|
#include <txmempool.h>
|
|
#include <util/system.h>
|
|
#include <validation.h>
|
|
#include <wallet/coincontrol.h>
|
|
#include <wallet/wallet.h>
|
|
|
|
|
|
CAmount GetRequiredFee(const CWallet& wallet, unsigned int nTxBytes)
|
|
{
|
|
return GetRequiredFeeRate(wallet).GetFee(nTxBytes);
|
|
}
|
|
|
|
CAmount GetMinimumFee(const CWallet& wallet, unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation* feeCalc)
|
|
{
|
|
CAmount fee_needed = GetMinimumFeeRate(wallet, coin_control, pool, estimator, feeCalc).GetFee(nTxBytes);
|
|
// Always obey the maximum
|
|
if (fee_needed > maxTxFee) {
|
|
fee_needed = maxTxFee;
|
|
if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE;
|
|
}
|
|
return fee_needed;
|
|
}
|
|
|
|
CFeeRate GetRequiredFeeRate(const CWallet& wallet)
|
|
{
|
|
return std::max(wallet.m_min_fee, ::minRelayTxFee);
|
|
}
|
|
|
|
CFeeRate GetMinimumFeeRate(const CWallet& wallet, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation* feeCalc)
|
|
{
|
|
/* User control of how to calculate fee uses the following parameter precedence:
|
|
1. coin_control.m_feerate
|
|
2. coin_control.m_confirm_target
|
|
3. m_pay_tx_fee (user-set member variable of wallet)
|
|
4. m_confirm_target (user-set member variable of wallet)
|
|
The first parameter that is set is used.
|
|
*/
|
|
CFeeRate feerate_needed;
|
|
if (coin_control.m_feerate) { // 1.
|
|
feerate_needed = *(coin_control.m_feerate);
|
|
if (feeCalc) feeCalc->reason = FeeReason::PAYTXFEE;
|
|
// Allow to override automatic min/max check over coin control instance
|
|
if (coin_control.fOverrideFeeRate) return feerate_needed;
|
|
}
|
|
else if (!coin_control.m_confirm_target && wallet.m_pay_tx_fee != CFeeRate(0)) { // 3. TODO: remove magic value of 0 for wallet member m_pay_tx_fee
|
|
feerate_needed = wallet.m_pay_tx_fee;
|
|
if (feeCalc) feeCalc->reason = FeeReason::PAYTXFEE;
|
|
}
|
|
else { // 2. or 4.
|
|
// We will use smart fee estimation
|
|
unsigned int target = coin_control.m_confirm_target ? *coin_control.m_confirm_target : wallet.m_confirm_target;
|
|
// By default estimates are economical
|
|
bool conservative_estimate = true;
|
|
// Allow to override the default fee estimate mode over the CoinControl instance
|
|
if (coin_control.m_fee_mode == FeeEstimateMode::CONSERVATIVE) conservative_estimate = true;
|
|
else if (coin_control.m_fee_mode == FeeEstimateMode::ECONOMICAL) conservative_estimate = false;
|
|
|
|
feerate_needed = estimator.estimateSmartFee(target, feeCalc, conservative_estimate);
|
|
if (feerate_needed == CFeeRate(0)) {
|
|
// if we don't have enough data for estimateSmartFee, then use fallback fee
|
|
feerate_needed = wallet.m_fallback_fee;
|
|
if (feeCalc) feeCalc->reason = FeeReason::FALLBACK;
|
|
}
|
|
// Obey mempool min fee when using smart fee estimation
|
|
CFeeRate min_mempool_feerate = pool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
|
|
if (feerate_needed < min_mempool_feerate) {
|
|
feerate_needed = min_mempool_feerate;
|
|
if (feeCalc) feeCalc->reason = FeeReason::MEMPOOL_MIN;
|
|
}
|
|
}
|
|
|
|
// prevent user from paying a fee below the required fee rate
|
|
CFeeRate required_feerate = GetRequiredFeeRate(wallet);
|
|
if (required_feerate > feerate_needed) {
|
|
feerate_needed = required_feerate;
|
|
if (feeCalc) feeCalc->reason = FeeReason::REQUIRED;
|
|
}
|
|
return feerate_needed;
|
|
}
|
|
|
|
CFeeRate GetDiscardRate(const CWallet& wallet, const CBlockPolicyEstimator& estimator)
|
|
{
|
|
unsigned int highest_target = estimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
|
|
CFeeRate discard_rate = estimator.estimateSmartFee(highest_target, nullptr /* FeeCalculation */, false /* conservative */);
|
|
// Don't let discard_rate be greater than longest possible fee estimate if we get a valid fee estimate
|
|
discard_rate = (discard_rate == CFeeRate(0)) ? wallet.m_discard_rate : std::min(discard_rate, wallet.m_discard_rate);
|
|
// Discard rate must be at least dustRelayFee
|
|
discard_rate = std::max(discard_rate, ::dustRelayFee);
|
|
return discard_rate;
|
|
}
|