wallet: Fix -maxtxfee check by moving it to CWallet::CreateTransaction

This commit is contained in:
João Barbosa 2019-07-02 15:16:36 +01:00
parent 6c21a801f3
commit 5c1b9714cb
4 changed files with 21 additions and 8 deletions

View file

@ -221,10 +221,13 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
return TransactionCreationFailed; return TransactionCreationFailed;
} }
// Reject absurdly high fee // Reject absurdly high fee. (This can never happen because the
if (nFeeRequired > m_wallet->getDefaultMaxTxFee()) // 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; return AbsurdFee;
} }
}
return SendCoinsReturn(OK); return SendCoinsReturn(OK);
} }

View file

@ -2694,11 +2694,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
} }
} }
if (nFeeRet > this->m_default_max_tx_fee) {
strFailReason = TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED);
return false;
}
return true; return true;
} }
@ -3135,6 +3130,11 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
} }
} }
if (nFeeRet > m_default_max_tx_fee) {
strFailReason = TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED);
return false;
}
if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) { if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
// Lastly, ensure this tx will pass the mempool's chain limits // Lastly, ensure this tx will pass the mempool's chain limits
if (!chain().checkChainLimits(tx)) { if (!chain().checkChainLimits(tx)) {

View file

@ -136,7 +136,7 @@ class PSBTTest(BitcoinTestFramework):
assert_greater_than(0.06, res["fee"]) assert_greater_than(0.06, res["fee"])
# feeRate of 10 BTC / KB produces a total fee well above -maxtxfee # feeRate of 10 BTC / 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", 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}) 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})
# partially sign multisig things with node 1 # partially sign multisig things with node 1

View file

@ -80,6 +80,7 @@ class BumpFeeTest(BitcoinTestFramework):
test_bumpfee_metadata(rbf_node, dest_address) test_bumpfee_metadata(rbf_node, dest_address)
test_locked_wallet_fails(rbf_node, dest_address) test_locked_wallet_fails(rbf_node, dest_address)
test_change_script_match(rbf_node, dest_address) test_change_script_match(rbf_node, dest_address)
test_maxtxfee_fails(self, rbf_node, dest_address)
# These tests wipe out a number of utxos that are expected in other tests # These tests wipe out a number of utxos that are expected in other tests
test_small_output_with_feerate_succeeds(rbf_node, dest_address) test_small_output_with_feerate_succeeds(rbf_node, dest_address)
test_no_more_inputs_fails(rbf_node, dest_address) test_no_more_inputs_fails(rbf_node, dest_address)
@ -248,6 +249,15 @@ def test_settxfee(rbf_node, dest_address):
rbf_node.settxfee(Decimal("0.00000000")) # unset paytxfee rbf_node.settxfee(Decimal("0.00000000")) # unset paytxfee
def test_maxtxfee_fails(test, rbf_node, dest_address):
test.restart_node(1, ['-maxtxfee=0.00003'] + test.extra_args[1])
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
rbfid = spend_one_input(rbf_node, dest_address)
assert_raises_rpc_error(-4, "Unable to create transaction: Fee exceeds maximum configured by -maxtxfee", rbf_node.bumpfee, rbfid)
test.restart_node(1, test.extra_args[1])
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
def test_rebumping(rbf_node, dest_address): def test_rebumping(rbf_node, dest_address):
# check that re-bumping the original tx fails, but bumping the bumper succeeds # check that re-bumping the original tx fails, but bumping the bumper succeeds
rbfid = spend_one_input(rbf_node, dest_address) rbfid = spend_one_input(rbf_node, dest_address)