From 48618daf262b84c2e2f7322b5ca14375d7d68b64 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 9 Aug 2018 01:52:42 +1000 Subject: [PATCH 1/2] Add checks for settxfee reasonableness --- src/wallet/rpcwallet.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 281fd461461..46162556ebf 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2982,8 +2982,16 @@ static UniValue settxfee(const JSONRPCRequest& request) LOCK2(cs_main, pwallet->cs_wallet); CAmount nAmount = AmountFromValue(request.params[0]); + CFeeRate tx_fee_rate(nAmount, 1000); + if (tx_fee_rate == 0) { + // 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; } From 317f2cb3f4499afbaa63e3cac80567744f12c95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Mon, 20 Aug 2018 18:34:39 +0100 Subject: [PATCH 2/2] test: Check RPC settxfee errors --- test/functional/wallet_bumpfee.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py index dd95bb5e224..a49590df19c 100755 --- a/test/functional/wallet_bumpfee.py +++ b/test/functional/wallet_bumpfee.py @@ -31,7 +31,7 @@ class BumpFeeTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 self.setup_clean_chain = True - self.extra_args = [["-deprecatedrpc=addwitnessaddress", "-walletrbf={}".format(i)] + self.extra_args = [["-deprecatedrpc=addwitnessaddress", "-walletrbf={}".format(i), "-mintxfee=0.00002"] for i in range(self.num_nodes)] def run_test(self): @@ -190,6 +190,8 @@ def test_dust_to_fee(rbf_node, dest_address): def test_settxfee(rbf_node, dest_address): + assert_raises_rpc_error(-8, "txfee cannot be less than min relay tx fee", rbf_node.settxfee, Decimal('0.000005')) + assert_raises_rpc_error(-8, "txfee cannot be less than wallet min fee", rbf_node.settxfee, Decimal('0.000015')) # check that bumpfee reacts correctly to the use of settxfee (paytxfee) rbfid = spend_one_input(rbf_node, dest_address) requested_feerate = Decimal("0.00025000")