diff --git a/src/config.h b/src/config.h --- a/src/config.h +++ b/src/config.h @@ -28,6 +28,9 @@ virtual void SetExcessUTXOCharge(Amount amt) = 0; virtual Amount GetExcessUTXOCharge() const = 0; + + virtual void SetMinFeePerKB(CFeeRate amt) = 0; + virtual CFeeRate GetMinFeePerKB() const = 0; }; class GlobalConfig final : public Config { @@ -44,9 +47,13 @@ void SetExcessUTXOCharge(Amount) override; Amount GetExcessUTXOCharge() const override; + void SetMinFeePerKB(CFeeRate amt) override; + CFeeRate GetMinFeePerKB() const override; + private: bool useCashAddr; Amount excessUTXOCharge; + CFeeRate feePerKB; }; // Dummy for subclassing in unittests @@ -70,6 +77,9 @@ void SetExcessUTXOCharge(Amount amt) override {} Amount GetExcessUTXOCharge() const override { return Amount(0); } + void SetMinFeePerKB(CFeeRate amt) override{}; + CFeeRate GetMinFeePerKB() const override { return CFeeRate(Amount(0)); } + private: std::unique_ptr chainParams; }; diff --git a/src/config.cpp b/src/config.cpp --- a/src/config.cpp +++ b/src/config.cpp @@ -71,3 +71,11 @@ Amount GlobalConfig::GetExcessUTXOCharge() const { return excessUTXOCharge; } + +void GlobalConfig::SetMinFeePerKB(CFeeRate fee) { + feePerKB = fee; +} + +CFeeRate GlobalConfig::GetMinFeePerKB() const { + return feePerKB; +} diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1565,7 +1565,9 @@ return InitError(AmountErrMsg("minrelaytxfee", gArgs.GetArg("-minrelaytxfee", ""))); // High fee check is done afterward in CWallet::ParameterInteraction() - ::minRelayTxFee = CFeeRate(n); + config.SetMinFeePerKB(CFeeRate(n)); + } else { + config.SetMinFeePerKB(CFeeRate(DEFAULT_MIN_RELAY_TX_FEE)); } // Sanity check argument for min fee for including tx in block diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3767,8 +3767,8 @@ // If we don't allow free transactions, then we always have a fee // filter of at least minRelayTxFee if (gArgs.GetArg("-limitfreerelay", DEFAULT_LIMITFREERELAY) <= 0) { - filterToSend = - std::max(filterToSend, ::minRelayTxFee.GetFeePerK()); + filterToSend = std::max(filterToSend, + config.GetMinFeePerKB().GetFeePerK()); } if (filterToSend != pto->lastSentFeeFilter) { diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -126,8 +126,8 @@ } obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()))); #endif - obj.push_back( - Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); + obj.push_back(Pair("relayfee", + ValueFromAmount(config.GetMinFeePerKB().GetFeePerK()))); obj.push_back(Pair("errors", GetWarnings("statusbar"))); return obj; } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -563,8 +563,8 @@ (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); } obj.push_back(Pair("networks", GetNetworksInfo())); - obj.push_back( - Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); + obj.push_back(Pair("relayfee", + ValueFromAmount(config.GetMinFeePerKB().GetFeePerK()))); obj.push_back(Pair("excessutxocharge", ValueFromAmount(config.GetExcessUTXOCharge()))); UniValue localAddresses(UniValue::VARR); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -210,11 +210,6 @@ extern bool fCheckpointsEnabled; extern size_t nCoinCacheUsage; -/** - * A fee rate smaller than this is considered zero fee (for relaying, mining and - * transaction creation) - */ -extern CFeeRate minRelayTxFee; /** * Absolute maximum transaction fee (in satoshis) used by wallet and mempool * (rejects high fee in sendrawtransaction) diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -81,7 +81,6 @@ uint256 hashAssumeValid; arith_uint256 nMinimumChainWork; -CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); Amount maxTxFee = DEFAULT_TRANSACTION_MAXFEE; CTxMemPool mempool; @@ -907,6 +906,7 @@ strprintf("%d", nSigOpsCount)); } + CFeeRate minRelayTxFee = config.GetMinFeePerKB(); Amount mempoolRejectFee = pool.GetMinFee( gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * @@ -919,7 +919,7 @@ } if (gArgs.GetBoolArg("-relaypriority", DEFAULT_RELAYPRIORITY) && - nModifiedFees < ::minRelayTxFee.GetFee(nSize) && + nModifiedFees < minRelayTxFee.GetFee(nSize) && !AllowFree(entry.GetPriority(chainActive.Height() + 1))) { // Require that free transactions have sufficient priority to be // mined in the next block. @@ -931,7 +931,7 @@ // This mitigates 'penny-flooding' -- sending thousands of free // transactions just to be annoying or make others' transactions take // longer to confirm. - if (fLimitFree && nModifiedFees < ::minRelayTxFee.GetFee(nSize)) { + if (fLimitFree && nModifiedFees < minRelayTxFee.GetFee(nSize)) { static CCriticalSection csFreeLimiter; static double dFreeCount; static int64_t nLastTime; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2945,7 +2945,8 @@ // 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)) { + Amount minFee = GetConfig().GetMinFeePerKB().GetFee(nBytes); + if (nFeeNeeded < minFee) { strFailReason = _("Transaction too large for fee policy"); return false; } @@ -3127,7 +3128,7 @@ Amount CWallet::GetRequiredFee(unsigned int nTxBytes) { return std::max(minTxFee.GetFee(nTxBytes), - ::minRelayTxFee.GetFee(nTxBytes)); + GetConfig().GetMinFeePerKB().GetFee(nTxBytes)); } Amount CWallet::GetMinimumFee(unsigned int nTxBytes, @@ -4326,6 +4327,8 @@ } bool CWallet::ParameterInteraction() { + CFeeRate minRelayTxFee = GetConfig().GetMinFeePerKB(); + gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT); const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1; @@ -4397,7 +4400,7 @@ "-reindex which will download the whole blockchain again.")); } - if (::minRelayTxFee.GetFeePerK() > HIGH_TX_FEE_PER_KB) { + if (minRelayTxFee.GetFeePerK() > HIGH_TX_FEE_PER_KB) { InitWarning( AmountHighWarn("-minrelaytxfee") + " " + _("The wallet will avoid paying less than the minimum relay fee.")); @@ -4451,11 +4454,11 @@ } payTxFee = CFeeRate(nFeePerK, 1000); - if (payTxFee < ::minRelayTxFee) { + if (payTxFee < minRelayTxFee) { return InitError(strprintf( _("Invalid amount for -paytxfee=: '%s' (must " "be at least %s)"), - gArgs.GetArg("-paytxfee", ""), ::minRelayTxFee.ToString())); + gArgs.GetArg("-paytxfee", ""), minRelayTxFee.ToString())); } } @@ -4472,12 +4475,12 @@ } maxTxFee = nMaxFee; - if (CFeeRate(maxTxFee, 1000) < ::minRelayTxFee) { + if (CFeeRate(maxTxFee, 1000) < minRelayTxFee) { return InitError(strprintf( _("Invalid amount for -maxtxfee=: '%s' (must " "be at least the minrelay fee of %s to prevent " "stuck transactions)"), - gArgs.GetArg("-maxtxfee", ""), ::minRelayTxFee.ToString())); + gArgs.GetArg("-maxtxfee", ""), minRelayTxFee.ToString())); } }