Skip to content

Commit 17d6449

Browse files
committed
Merge #13988: Add checks for settxfee reasonableness
317f2cb test: Check RPC settxfee errors (João Barbosa) 48618da 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
2 parents 0738b88 + 317f2cb commit 17d6449

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2982,8 +2982,16 @@ static UniValue settxfee(const JSONRPCRequest& request)
29822982
LOCK2(cs_main, pwallet->cs_wallet);
29832983

29842984
CAmount nAmount = AmountFromValue(request.params[0]);
2985+
CFeeRate tx_fee_rate(nAmount, 1000);
2986+
if (tx_fee_rate == 0) {
2987+
// automatic selection
2988+
} else if (tx_fee_rate < ::minRelayTxFee) {
2989+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than min relay tx fee (%s)", ::minRelayTxFee.ToString()));
2990+
} else if (tx_fee_rate < pwallet->m_min_fee) {
2991+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than wallet min fee (%s)", pwallet->m_min_fee.ToString()));
2992+
}
29852993

2986-
pwallet->m_pay_tx_fee = CFeeRate(nAmount, 1000);
2994+
pwallet->m_pay_tx_fee = tx_fee_rate;
29872995
return true;
29882996
}
29892997

test/functional/wallet_bumpfee.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BumpFeeTest(BitcoinTestFramework):
3131
def set_test_params(self):
3232
self.num_nodes = 2
3333
self.setup_clean_chain = True
34-
self.extra_args = [["-deprecatedrpc=addwitnessaddress", "-walletrbf={}".format(i)]
34+
self.extra_args = [["-deprecatedrpc=addwitnessaddress", "-walletrbf={}".format(i), "-mintxfee=0.00002"]
3535
for i in range(self.num_nodes)]
3636

3737
def run_test(self):
@@ -190,6 +190,8 @@ def test_dust_to_fee(rbf_node, dest_address):
190190

191191

192192
def test_settxfee(rbf_node, dest_address):
193+
assert_raises_rpc_error(-8, "txfee cannot be less than min relay tx fee", rbf_node.settxfee, Decimal('0.000005'))
194+
assert_raises_rpc_error(-8, "txfee cannot be less than wallet min fee", rbf_node.settxfee, Decimal('0.000015'))
193195
# check that bumpfee reacts correctly to the use of settxfee (paytxfee)
194196
rbfid = spend_one_input(rbf_node, dest_address)
195197
requested_feerate = Decimal("0.00025000")

0 commit comments

Comments
 (0)