diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -220,7 +220,9 @@ return TransactionCreationFailed; } - // Reject absurdly high fee + // Reject absurdly high fee. (This can never happen because the + // wallet never creates transactions with fee greater than + // m_default_max_tx_fee. This merely a belt-and-suspenders check). if (nFeeRequired > m_wallet->getDefaultMaxTxFee()) { return AbsurdFee; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3194,12 +3194,6 @@ } } - if (nFeeRet > this->m_default_max_tx_fee) { - strFailReason = - TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED); - return false; - } - return true; } @@ -3522,15 +3516,6 @@ Amount nFeeNeeded = GetMinimumFee(*this, nBytes, coinControl); - // If we made it here and we aren't even able to meet the relay fee - // on the next pass, give up because we must be at the maximum - // allowed fee. - if (nFeeNeeded < chain().relayMinFee().GetFee(nBytes)) { - strFailReason = - _("Transaction too large for fee policy").translated; - return false; - } - if (nFeeRet >= nFeeNeeded) { // Reduce fee to only the needed amount if possible. This // prevents potential overpayment in fees if the coins selected @@ -3663,6 +3648,12 @@ } } + if (nFeeRet > m_default_max_tx_fee) { + strFailReason = + TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED); + return false; + } + if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) { // Lastly, ensure this tx will pass the mempool's chain limits diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -91,7 +91,7 @@ assert_greater_than(0.07, res["fee"]) # feeRate of 10 BCH / KB produces a total fee well above -maxtxfee - # previously this was silenty capped at -maxtxfee + # previously this was silently capped at -maxtxfee assert_raises_rpc_error( -4, "Fee exceeds maximum configured by -maxtxfee", diff --git a/test/functional/wallet_create_tx.py b/test/functional/wallet_create_tx.py --- a/test/functional/wallet_create_tx.py +++ b/test/functional/wallet_create_tx.py @@ -6,6 +6,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, + assert_raises_rpc_error, ) from test_framework.blocktools import ( TIME_GENESIS_BLOCK, @@ -26,6 +27,10 @@ self.nodes[0].generate(200) self.nodes[0].setmocktime(0) + self.test_anti_fee_sniping() + self.test_tx_size_too_large() + + def test_anti_fee_sniping(self): self.log.info( 'Check that we have some (old) blocks and that anti-fee-sniping is disabled') assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200) @@ -42,6 +47,43 @@ self.nodes[0].gettransaction(txid)['hex']) assert 0 < tx['locktime'] <= 201 + def test_tx_size_too_large(self): + # More than 10kB of outputs, so that we hit -maxtxfee with a high + # feerate + outputs = {self.nodes[0].getnewaddress(): 0.000025 for i in range(400)} + raw_tx = self.nodes[0].createrawtransaction(inputs=[], outputs=outputs) + + for fee_setting in ['-minrelaytxfee=0.01', + '-mintxfee=0.01', '-paytxfee=0.01']: + self.log.info( + 'Check maxtxfee in combination with {}'.format(fee_setting)) + self.restart_node(0, extra_args=[fee_setting]) + assert_raises_rpc_error( + -6, + "Fee exceeds maximum configured by -maxtxfee", + lambda: self.nodes[0].sendmany(dummy="", amounts=outputs), + ) + assert_raises_rpc_error( + -4, + "Fee exceeds maximum configured by -maxtxfee", + lambda: self.nodes[0].fundrawtransaction(hexstring=raw_tx), + ) + + self.log.info('Check maxtxfee in combination with settxfee') + self.restart_node(0) + self.nodes[0].settxfee(0.01) + assert_raises_rpc_error( + -6, + "Fee exceeds maximum configured by -maxtxfee", + lambda: self.nodes[0].sendmany(dummy="", amounts=outputs), + ) + assert_raises_rpc_error( + -4, + "Fee exceeds maximum configured by -maxtxfee", + lambda: self.nodes[0].fundrawtransaction(hexstring=raw_tx), + ) + self.nodes[0].settxfee(0) + if __name__ == '__main__': CreateTxWalletTest().main()