diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3562,8 +3562,22 @@ LOCK2(cs_main, pwallet->cs_wallet); Amount nAmount = AmountFromValue(request.params[0]); + CFeeRate tx_fee_rate(nAmount, 1000); + if (tx_fee_rate == CFeeRate()) { + // automatic selection + } else if (tx_fee_rate < ::minRelayTxFee) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + strprintf("txfee cannot be less than min relay tx fee (%s)", + ::minRelayTxFee.ToString())); + } else if (tx_fee_rate < pwallet->m_min_fee) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + strprintf("txfee cannot be less than wallet min fee (%s)", + pwallet->m_min_fee.ToString())); + } - pwallet->m_pay_tx_fee = CFeeRate(nAmount, 1000); + pwallet->m_pay_tx_fee = tx_fee_rate; return true; } 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 @@ -6,18 +6,19 @@ from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal +from test_framework.util import assert_equal, assert_raises_rpc_error class EstimateFeeTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True - self.num_nodes = 2 - self.extra_args = [[], ["-minrelaytxfee=0.001"]] + self.num_nodes = 3 + self.extra_args = [[], ["-minrelaytxfee=0.001"], ["-mintxfee=0.00002"]] def run_test(self): default_node = self.nodes[0] diff_relay_fee_node = self.nodes[1] + diff_tx_fee_node = self.nodes[2] for i in range(5): self.nodes[0].generate(1) @@ -27,6 +28,12 @@ # estimatefee may be different for nodes that set it in their config assert_equal(diff_relay_fee_node.estimatefee(), Decimal('0.001')) + # Check the reasonableness of settxfee + assert_raises_rpc_error(-8, "txfee cannot be less than min relay tx fee", + 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')) + if __name__ == '__main__': EstimateFeeTest().main()