aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-08-22 11:03:01 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2018-08-22 11:10:41 +0200
commit17d644901bbd770578619545bbd8bc930fe6f2d9 (patch)
tree80f398d8fa9b28baddcd361f9e71d1c4714cd856
parent0738b88fe0b6c840e3cefa810c2b6de6c8b32ed0 (diff)
parent317f2cb3f4499afbaa63e3cac80567744f12c95b (diff)
downloadbitcoin-17d644901bbd770578619545bbd8bc930fe6f2d9.tar.xz
Merge #13988: Add checks for settxfee reasonableness
317f2cb3f4499afbaa63e3cac80567744f12c95b test: Check RPC settxfee errors (João Barbosa) 48618daf262b84c2e2f7322b5ca14375d7d68b64 Add checks for settxfee reasonableness (Anthony Towns) Pull request description: When using the `settxfee` RPC, the value is silently ignored if it is less than either than minrelaytxfee or the wallet's mintxfee. This adds an error response if that's going to happen, but still allows "settxfee 0" to deliberately default to the minimum value. Tree-SHA512: ce685584cf8d6b9ca2cc97196d494220e3892b6a804a458086e04b3a23df281da432ad0a3053106a064c90c541ddb6f6b96a27cf8376d45af1e44449baf88456
-rw-r--r--src/wallet/rpcwallet.cpp10
-rwxr-xr-xtest/functional/wallet_bumpfee.py4
2 files changed, 12 insertions, 2 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 0966334b82..b108d6df53 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;
}
diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py
index dd95bb5e22..a49590df19 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")