Skip to content

Commit 5c1b971

Browse files
committed
wallet: Fix -maxtxfee check by moving it to CWallet::CreateTransaction
1 parent 6c21a80 commit 5c1b971

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,11 +2694,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
26942694
}
26952695
}
26962696

2697-
if (nFeeRet > this->m_default_max_tx_fee) {
2698-
strFailReason = TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED);
2699-
return false;
2700-
}
2701-
27022697
return true;
27032698
}
27042699

@@ -3135,6 +3130,11 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
31353130
}
31363131
}
31373132

3133+
if (nFeeRet > m_default_max_tx_fee) {
3134+
strFailReason = TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED);
3135+
return false;
3136+
}
3137+
31383138
if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
31393139
// Lastly, ensure this tx will pass the mempool's chain limits
31403140
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)

0 commit comments

Comments
 (0)