Skip to content

Commit

Permalink
wallet: propagete checkChainLimits error message to wallet
Browse files Browse the repository at this point in the history
Also update test to reflect the error message from `CTxMempool`
`CheckPackageLimits` output.
  • Loading branch information
ismaelsadeeq committed Nov 24, 2023
1 parent e862bce commit 28115d8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <blockfilter.h>
#include <common/settings.h>
#include <primitives/transaction.h> // For CTransactionRef
#include <util/result.h>

#include <functional>
#include <memory>
Expand Down Expand Up @@ -260,7 +261,7 @@ class Chain
virtual void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) = 0;

//! Check if transaction will pass the mempool's chain limits.
virtual bool checkChainLimits(const CTransactionRef& tx) = 0;
virtual util::Result<void> checkChainLimits(const CTransactionRef& tx) = 0;

//! Estimate smart fee.
virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc = nullptr) = 0;
Expand Down
8 changes: 5 additions & 3 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <uint256.h>
#include <univalue.h>
#include <util/check.h>
#include <util/result.h>
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
Expand Down Expand Up @@ -698,14 +699,15 @@ class ChainImpl : public Chain
limit_ancestor_count = limits.ancestor_count;
limit_descendant_count = limits.descendant_count;
}
bool checkChainLimits(const CTransactionRef& tx) override
util::Result<void> checkChainLimits(const CTransactionRef& tx) override
{
if (!m_node.mempool) return true;
if (!m_node.mempool) return {};
LockPoints lp;
CTxMemPoolEntry entry(tx, 0, 0, 0, 0, false, 0, lp);
LOCK(m_node.mempool->cs);
std::string err_string;
return m_node.mempool->CheckPackageLimits({tx}, entry.GetTxSize(), err_string);
if (m_node.mempool->CheckPackageLimits({tx}, entry.GetTxSize(), err_string)) return {};
return util::Error{Untranslated(err_string)};
}
CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
{
Expand Down
5 changes: 3 additions & 2 deletions src/wallet/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,9 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(

if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
// Lastly, ensure this tx will pass the mempool's chain limits
if (!wallet.chain().checkChainLimits(tx)) {
return util::Error{_("Transaction has too long of a mempool chain")};
auto result = wallet.chain().checkChainLimits(tx);
if (!result) {
return util::Error{util::ErrorString(result)};
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def run_test(self):

node0_balance = self.nodes[0].getbalance()
# With walletrejectlongchains we will not create the tx and store it in our wallet.
assert_raises_rpc_error(-6, "Transaction has too long of a mempool chain", self.nodes[0].sendtoaddress, sending_addr, node0_balance - Decimal('0.01'))
assert_raises_rpc_error(-6, f"too many unconfirmed ancestors [limit: {chainlimit * 2}]", self.nodes[0].sendtoaddress, sending_addr, node0_balance - Decimal('0.01'))

# Verify nothing new in wallet
assert_equal(total_txs, len(self.nodes[0].listtransactions("*", 99999)))
Expand Down

0 comments on commit 28115d8

Please sign in to comment.