From 8b15afd3156224dd7c3f46f4cc8c5ab483bec1f9 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 27 Mar 2018 10:23:24 -0700 Subject: [PATCH] Closes #3110. Ensure user can see error message about absurdly high fees. --- qa/rpc-tests/wallet.py | 20 ++++++++++++++++++++ src/main.cpp | 11 +++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 12dfac0e4..158a77c88 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -89,6 +89,26 @@ class WalletTest (BitcoinTestFramework): assert_equal(len(node2utxos), 2) assert_equal(sum(int(uxto["generated"] is True) for uxto in node2utxos), 0) + # Catch an attempt to send a transaction with an absurdly high fee. + # Send 1.0 from an utxo of value 10.0 but don't specify a change output, so then + # the change of 9.0 becomes the fee, which is greater than estimated fee of 0.0019. + inputs = [] + outputs = {} + for utxo in node2utxos: + if utxo["amount"] == Decimal("10.0"): + break + assert_equal(utxo["amount"], Decimal("10.0")) + inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]}) + outputs[self.nodes[2].getnewaddress("")] = Decimal("1.0") + raw_tx = self.nodes[2].createrawtransaction(inputs, outputs) + signed_tx = self.nodes[2].signrawtransaction(raw_tx) + try: + self.nodes[2].sendrawtransaction(signed_tx["hex"]) + except JSONRPCException,e: + errorString = e.error['message'] + assert("absurdly high fees" in errorString) + assert("900000000 > 190000" in errorString) + # create both transactions txns_to_send = [] for utxo in node0utxos: diff --git a/src/main.cpp b/src/main.cpp index eb2aacc78..ab5ca204e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1357,10 +1357,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa dFreeCount += nSize; } - if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000) - return error("AcceptToMemoryPool: absurdly high fees %s, %d > %d", - hash.ToString(), - nFees, ::minRelayTxFee.GetFee(nSize) * 10000); + if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000) { + string errmsg = strprintf("absurdly high fees %s, %d > %d", + hash.ToString(), + nFees, ::minRelayTxFee.GetFee(nSize) * 10000); + LogPrint("mempool", errmsg.c_str()); + return state.Error("AcceptToMemoryPool: " + errmsg); + } // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks.