Skip to content

Commit 6c1e45c

Browse files
committed
Merge #16322: wallet: Fix -maxtxfee check by moving it to CWallet::CreateTransaction
0d101a3 test: Add test for maxtxfee option (MarcoFalke) 1775501 wallet: Remove unreachable code in CreateTransaction (MarcoFalke) 5c1b971 wallet: Fix -maxtxfee check by moving it to CWallet::CreateTransaction (João Barbosa) Pull request description: Follow up to #16257, this PR makes `bumpfee` aware of `-maxtxfee`. It also prevents dangling locked unspents when calling `fundrawtransaction` - because the previous check was after `LockCoin`. ACKs for top commit: MarcoFalke: re-ACK 0d101a3, only change is small test fixup Tree-SHA512: 3464b24ae7cd4e72ed41438c6661828ba1304af020f05da62720b23668ae734e16cf47c6d97e150cc84ef631ee099b16fc786c858f3d089905845437338fd512
2 parents d1fc827 + 0d101a3 commit 6c1e45c

File tree

5 files changed

+60
-16
lines changed

5 files changed

+60
-16
lines changed

src/qt/walletmodel.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
221221
return TransactionCreationFailed;
222222
}
223223

224-
// Reject absurdly high fee
225-
if (nFeeRequired > m_wallet->getDefaultMaxTxFee())
224+
// Reject absurdly high fee. (This can never happen because the
225+
// wallet never creates transactions with fee greater than
226+
// m_default_max_tx_fee. This merely a belt-and-suspenders check).
227+
if (nFeeRequired > m_wallet->getDefaultMaxTxFee()) {
226228
return AbsurdFee;
229+
}
227230
}
228231

229232
return SendCoinsReturn(OK);

src/wallet/wallet.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,11 +2696,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
26962696
}
26972697
}
26982698

2699-
if (nFeeRet > this->m_default_max_tx_fee) {
2700-
strFailReason = TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED);
2701-
return false;
2702-
}
2703-
27042699
return true;
27052700
}
27062701

@@ -3010,14 +3005,6 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
30103005
return false;
30113006
}
30123007

3013-
// If we made it here and we aren't even able to meet the relay fee on the next pass, give up
3014-
// because we must be at the maximum allowed fee.
3015-
if (nFeeNeeded < chain().relayMinFee().GetFee(nBytes))
3016-
{
3017-
strFailReason = _("Transaction too large for fee policy");
3018-
return false;
3019-
}
3020-
30213008
if (nFeeRet >= nFeeNeeded) {
30223009
// Reduce fee to only the needed amount if possible. This
30233010
// prevents potential overpayment in fees if the coins
@@ -3134,6 +3121,11 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
31343121
}
31353122
}
31363123

3124+
if (nFeeRet > m_default_max_tx_fee) {
3125+
strFailReason = TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED);
3126+
return false;
3127+
}
3128+
31373129
if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
31383130
// Lastly, ensure this tx will pass the mempool's chain limits
31393131
if (!chain().checkChainLimits(tx)) {

test/functional/rpc_psbt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def run_test(self):
136136
assert_greater_than(0.06, res["fee"])
137137

138138
# feeRate of 10 BTC / KB produces a total fee well above -maxtxfee
139-
# previously this was silenty capped at -maxtxfee
139+
# previously this was silently capped at -maxtxfee
140140
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by -maxtxfee", self.nodes[1].walletcreatefundedpsbt, [{"txid":txid,"vout":p2wpkh_pos},{"txid":txid,"vout":p2sh_p2wpkh_pos},{"txid":txid,"vout":p2pkh_pos}], {self.nodes[1].getnewaddress():29.99}, 0, {"feeRate": 10})
141141

142142
# partially sign multisig things with node 1

test/functional/wallet_bumpfee.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def run_test(self):
8080
test_bumpfee_metadata(rbf_node, dest_address)
8181
test_locked_wallet_fails(rbf_node, dest_address)
8282
test_change_script_match(rbf_node, dest_address)
83+
test_maxtxfee_fails(self, rbf_node, dest_address)
8384
# These tests wipe out a number of utxos that are expected in other tests
8485
test_small_output_with_feerate_succeeds(rbf_node, dest_address)
8586
test_no_more_inputs_fails(rbf_node, dest_address)
@@ -248,6 +249,15 @@ def test_settxfee(rbf_node, dest_address):
248249
rbf_node.settxfee(Decimal("0.00000000")) # unset paytxfee
249250

250251

252+
def test_maxtxfee_fails(test, rbf_node, dest_address):
253+
test.restart_node(1, ['-maxtxfee=0.00003'] + test.extra_args[1])
254+
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
255+
rbfid = spend_one_input(rbf_node, dest_address)
256+
assert_raises_rpc_error(-4, "Unable to create transaction: Fee exceeds maximum configured by -maxtxfee", rbf_node.bumpfee, rbfid)
257+
test.restart_node(1, test.extra_args[1])
258+
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
259+
260+
251261
def test_rebumping(rbf_node, dest_address):
252262
# check that re-bumping the original tx fails, but bumping the bumper succeeds
253263
rbfid = spend_one_input(rbf_node, dest_address)

test/functional/wallet_create_tx.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from test_framework.test_framework import BitcoinTestFramework
77
from test_framework.util import (
88
assert_equal,
9+
assert_raises_rpc_error,
910
)
1011
from test_framework.blocktools import (
1112
TIME_GENESIS_BLOCK,
@@ -26,6 +27,10 @@ def run_test(self):
2627
self.nodes[0].generate(200)
2728
self.nodes[0].setmocktime(0)
2829

30+
self.test_anti_fee_sniping()
31+
self.test_tx_size_too_large()
32+
33+
def test_anti_fee_sniping(self):
2934
self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')
3035
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
3136
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
@@ -38,6 +43,40 @@ def run_test(self):
3843
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex'])
3944
assert 0 < tx['locktime'] <= 201
4045

46+
def test_tx_size_too_large(self):
47+
# More than 10kB of outputs, so that we hit -maxtxfee with a high feerate
48+
outputs = {self.nodes[0].getnewaddress(address_type='bech32'): 0.000025 for i in range(400)}
49+
raw_tx = self.nodes[0].createrawtransaction(inputs=[], outputs=outputs)
50+
51+
for fee_setting in ['-minrelaytxfee=0.01', '-mintxfee=0.01', '-paytxfee=0.01']:
52+
self.log.info('Check maxtxfee in combination with {}'.format(fee_setting))
53+
self.restart_node(0, extra_args=[fee_setting])
54+
assert_raises_rpc_error(
55+
-6,
56+
"Fee exceeds maximum configured by -maxtxfee",
57+
lambda: self.nodes[0].sendmany(dummy="", amounts=outputs),
58+
)
59+
assert_raises_rpc_error(
60+
-4,
61+
"Fee exceeds maximum configured by -maxtxfee",
62+
lambda: self.nodes[0].fundrawtransaction(hexstring=raw_tx),
63+
)
64+
65+
self.log.info('Check maxtxfee in combination with settxfee')
66+
self.restart_node(0)
67+
self.nodes[0].settxfee(0.01)
68+
assert_raises_rpc_error(
69+
-6,
70+
"Fee exceeds maximum configured by -maxtxfee",
71+
lambda: self.nodes[0].sendmany(dummy="", amounts=outputs),
72+
)
73+
assert_raises_rpc_error(
74+
-4,
75+
"Fee exceeds maximum configured by -maxtxfee",
76+
lambda: self.nodes[0].fundrawtransaction(hexstring=raw_tx),
77+
)
78+
self.nodes[0].settxfee(0)
79+
4180

4281
if __name__ == '__main__':
4382
CreateTxWalletTest().main()

0 commit comments

Comments
 (0)