From 1372b1dbe2eb2b5674f5e5816a54a2e5bed96b46 Mon Sep 17 00:00:00 2001 From: junderw Date: Thu, 4 Aug 2022 09:28:06 +0900 Subject: [PATCH] Fix: parse -maxtxfee outside of CWallet This preserves the effect of -maxtxfee even when -disablewallet is active. --- src/init.cpp | 21 ++++++++++++++++++++- src/wallet/wallet.cpp | 14 -------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 38305f2cf..af81b3abc 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1016,7 +1016,6 @@ bool AppInitParameterInteraction() CAmount n = 0; if (!ParseMoney(GetArg("-minrelaytxfee", ""), n) || 0 == n) return InitError(AmountErrMsg("minrelaytxfee", GetArg("-minrelaytxfee", ""))); - // High fee check is done afterward in CWallet::ParameterInteraction() ::minRelayTxFeeRate = CFeeRate(n); } else if (incrementalRelayFee > ::minRelayTxFeeRate) { // Allow only setting incrementalRelayFee to control both @@ -1024,6 +1023,26 @@ bool AppInitParameterInteraction() LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n",::minRelayTxFeeRate.ToString()); } + // This is the maximum absolute fee (in COIN, not satoshis) + // that is allowed for sendrawtransaction RPC and CWallet + // This must be parsed outside of CWallet code in order to + // keep its effect on the RPC even when -disablewallet is + // active. + if (IsArgSet("-maxtxfee")) + { + CAmount nMaxFee = 0; + if (!ParseMoney(GetArg("-maxtxfee", ""), nMaxFee)) + return InitError(AmountErrMsg("maxtxfee", GetArg("-maxtxfee", ""))); + if (nMaxFee > HIGH_MAX_TX_FEE) + InitWarning(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction.")); + ::maxTxFee = nMaxFee; + if (CFeeRate(::maxTxFee, 1000) < ::minRelayTxFeeRate) + { + return InitError(strprintf(_("Invalid amount for -maxtxfee=: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"), + GetArg("-maxtxfee", ""), ::minRelayTxFeeRate.ToString())); + } + } + // Sanity check argument for min fee for including tx in block // TODO: Harmonize which arguments need sanity checking and where that happens if (IsArgSet("-blockmintxfee")) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 38da7ce0f..9784b68f7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3961,20 +3961,6 @@ bool CWallet::ParameterInteraction() CWallet::minTxFee = CFeeRate(nFeePerK,1000); } } - if (IsArgSet("-maxtxfee")) - { - CAmount nMaxFee = 0; - if (!ParseMoney(GetArg("-maxtxfee", ""), nMaxFee)) - return InitError(AmountErrMsg("maxtxfee", GetArg("-maxtxfee", ""))); - if (nMaxFee > HIGH_MAX_TX_FEE) - InitWarning(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction.")); - maxTxFee = nMaxFee; - if (CFeeRate(maxTxFee, 1000) < ::minRelayTxFeeRate) - { - return InitError(strprintf(_("Invalid amount for -maxtxfee=: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"), - GetArg("-maxtxfee", ""), ::minRelayTxFeeRate.ToString())); - } - } if (IsArgSet("-discardthreshold")) { CAmount nDiscardThreshold = 0;