Skip to content

Commit 3867727

Browse files
committed
rpc: settxfee respects -maxtxfee wallet setting
1 parent bda84a0 commit 3867727

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,12 +2337,15 @@ static UniValue settxfee(const JSONRPCRequest& request)
23372337

23382338
CAmount nAmount = AmountFromValue(request.params[0]);
23392339
CFeeRate tx_fee_rate(nAmount, 1000);
2340+
CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000);
23402341
if (tx_fee_rate == CFeeRate(0)) {
23412342
// automatic selection
23422343
} else if (tx_fee_rate < pwallet->chain().relayMinFee()) {
23432344
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than min relay tx fee (%s)", pwallet->chain().relayMinFee().ToString()));
23442345
} else if (tx_fee_rate < pwallet->m_min_fee) {
23452346
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than wallet min fee (%s)", pwallet->m_min_fee.ToString()));
2347+
} else if (tx_fee_rate > max_tx_fee_rate) {
2348+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be more than wallet max tx fee (%s)", max_tx_fee_rate.ToString()));
23462349
}
23472350

23482351
pwallet->m_pay_tx_fee = tx_fee_rate;

test/functional/wallet_bumpfee.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ def run_test(self):
8282
test_notmine_bumpfee_fails(self, rbf_node, peer_node, dest_address)
8383
test_bumpfee_with_descendant_fails(self, rbf_node, rbf_node_address, dest_address)
8484
test_dust_to_fee(self, rbf_node, dest_address)
85-
test_settxfee(self, rbf_node, dest_address)
8685
test_watchonly_psbt(self, peer_node, rbf_node, dest_address)
8786
test_rebumping(self, rbf_node, dest_address)
8887
test_rebumping_not_replaceable(self, rbf_node, dest_address)
8988
test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address)
9089
test_bumpfee_metadata(self, rbf_node, dest_address)
9190
test_locked_wallet_fails(self, rbf_node, dest_address)
9291
test_change_script_match(self, rbf_node, dest_address)
92+
test_settxfee(self, rbf_node, dest_address)
9393
test_maxtxfee_fails(self, rbf_node, dest_address)
9494
# These tests wipe out a number of utxos that are expected in other tests
9595
test_small_output_with_feerate_succeeds(self, rbf_node, dest_address)
@@ -281,9 +281,15 @@ def test_settxfee(self, rbf_node, dest_address):
281281
assert_greater_than(Decimal("0.00001000"), abs(requested_feerate - actual_feerate))
282282
rbf_node.settxfee(Decimal("0.00000000")) # unset paytxfee
283283

284+
# check that settxfee respects -maxtxfee
285+
self.restart_node(1, ['-maxtxfee=0.000025'] + self.extra_args[1])
286+
assert_raises_rpc_error(-8, "txfee cannot be more than wallet max tx fee", rbf_node.settxfee, Decimal('0.00003'))
287+
self.restart_node(1, self.extra_args[1])
288+
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
289+
284290

285291
def test_maxtxfee_fails(self, rbf_node, dest_address):
286-
self.log.info('Test that bumpfee fails when it hits -matxfee')
292+
self.log.info('Test that bumpfee fails when it hits -maxtxfee')
287293
# size of bumped transaction (p2wpkh, 1 input, 2 outputs): 141 vbytes
288294
# expected bump fee of 141 vbytes * 0.00200000 BTC / 1000 vbytes = 0.00002820 BTC
289295
# which exceeds maxtxfee and is expected to raise

test/functional/wallet_multiwallet.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
Verify that a bitcoind node can load multiple wallet files
88
"""
9+
from decimal import Decimal
910
import os
1011
import shutil
1112
import time
@@ -193,9 +194,9 @@ def wallet_file(name):
193194
self.log.info('Check for per-wallet settxfee call')
194195
assert_equal(w1.getwalletinfo()['paytxfee'], 0)
195196
assert_equal(w2.getwalletinfo()['paytxfee'], 0)
196-
w2.settxfee(4.0)
197+
w2.settxfee(0.001)
197198
assert_equal(w1.getwalletinfo()['paytxfee'], 0)
198-
assert_equal(w2.getwalletinfo()['paytxfee'], 4.0)
199+
assert_equal(w2.getwalletinfo()['paytxfee'], Decimal('0.00100000'))
199200

200201
self.log.info("Test dynamic wallet loading")
201202

0 commit comments

Comments
 (0)