diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2826,7 +2826,9 @@ RPCHelpMan{ "settxfee", "Set the transaction fee per kB for this wallet. Overrides the " - "global -paytxfee command line parameter.\n", + "global -paytxfee command line parameter.\n" + "Can be deactivated by passing 0 as the fee. In that case automatic " + "fee selection will be used by default.\n", { {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The transaction fee in " + CURRENCY_UNIT + "/kB"}, @@ -2841,6 +2843,7 @@ Amount nAmount = AmountFromValue(request.params[0]); CFeeRate tx_fee_rate(nAmount, 1000); + CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000); if (tx_fee_rate == CFeeRate()) { // automatic selection } else if (tx_fee_rate < pwallet->chain().relayMinFee()) { @@ -2853,6 +2856,11 @@ RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than wallet min fee (%s)", pwallet->m_min_fee.ToString())); + } else if (tx_fee_rate > max_tx_fee_rate) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + strprintf("txfee cannot be more than wallet max tx fee (%s)", + max_tx_fee_rate.ToString())); } pwallet->m_pay_tx_fee = tx_fee_rate; diff --git a/test/functional/rpc_estimatefee.py b/test/functional/rpc_estimatefee.py --- a/test/functional/rpc_estimatefee.py +++ b/test/functional/rpc_estimatefee.py @@ -13,7 +13,11 @@ def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 3 - self.extra_args = [[], ["-minrelaytxfee=0.001"], ["-mintxfee=0.00002"]] + self.extra_args = [ + [], + ["-minrelaytxfee=0.001"], + ["-mintxfee=0.00002", "-maxtxfee=0.000025"], + ] def skip_test_if_missing_module(self): self.skip_if_no_wallet() @@ -37,6 +41,8 @@ diff_tx_fee_node.settxfee, Decimal('0.000005')) assert_raises_rpc_error(-8, "txfee cannot be less than wallet min fee", diff_tx_fee_node.settxfee, Decimal('0.000015')) + assert_raises_rpc_error(-8, "txfee cannot be more than wallet max tx fee", + diff_tx_fee_node.settxfee, Decimal('0.00003')) if __name__ == '__main__': diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -6,6 +6,7 @@ Verify that a bitcoind node can load multiple wallet files """ +from decimal import Decimal import os import shutil import time @@ -229,9 +230,9 @@ self.log.info('Check for per-wallet settxfee call') assert_equal(w1.getwalletinfo()['paytxfee'], 0) assert_equal(w2.getwalletinfo()['paytxfee'], 0) - w2.settxfee(4.0) + w2.settxfee(0.001) assert_equal(w1.getwalletinfo()['paytxfee'], 0) - assert_equal(w2.getwalletinfo()['paytxfee'], 4.0) + assert_equal(w2.getwalletinfo()['paytxfee'], Decimal('0.00100000')) self.log.info("Test dynamic wallet loading")