diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -6,6 +6,7 @@ #define BITCOIN_INTERFACES_CHAIN_H #include +#include #include #include @@ -150,6 +151,9 @@ //! transaction. virtual void getTransactionAncestry(const TxId &txid, size_t &ancestors, size_t &descendants) = 0; + + //! Check chain limits. + virtual bool checkChainLimits(CTransactionRef tx) = 0; }; //! Interface to let node manage chain clients (wallets, or maybe tools for diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -198,6 +199,29 @@ size_t &descendants) override { ::g_mempool.GetTransactionAncestry(txid, ancestors, descendants); } + bool checkChainLimits(CTransactionRef tx) override { + LockPoints lp; + CTxMemPoolEntry entry(tx, Amount(), 0, 0, false, 0, lp); + CTxMemPool::setEntries ancestors; + auto limit_ancestor_count = + gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT); + auto limit_ancestor_size = + gArgs.GetArg("-limitancestorsize", + DEFAULT_ANCESTOR_SIZE_LIMIT) * + 1000; + auto limit_descendant_count = + gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT); + auto limit_descendant_size = + gArgs.GetArg("-limitdescendantsize", + DEFAULT_DESCENDANT_SIZE_LIMIT) * + 1000; + std::string unused_error_string; + LOCK(::g_mempool.cs); + return ::g_mempool.CalculateMemPoolAncestors( + entry, ancestors, limit_ancestor_count, limit_ancestor_size, + limit_descendant_count, limit_descendant_size, + unused_error_string); + } }; } // namespace diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3395,26 +3395,8 @@ if (gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) { - // Lastly, ensure this tx will pass the mempool's chain limits. - LockPoints lp; - CTxMemPoolEntry entry(tx, Amount::zero(), 0, 0, false, 0, lp); - CTxMemPool::setEntries setAncestors; - size_t nLimitAncestors = - gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT); - size_t nLimitAncestorSize = - gArgs.GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT) * - 1000; - size_t nLimitDescendants = - gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT); - size_t nLimitDescendantSize = - gArgs.GetArg("-limitdescendantsize", - DEFAULT_DESCENDANT_SIZE_LIMIT) * - 1000; - std::string errString; - LOCK(::g_mempool.cs); - if (!g_mempool.CalculateMemPoolAncestors( - entry, setAncestors, nLimitAncestors, nLimitAncestorSize, - nLimitDescendants, nLimitDescendantSize, errString)) { + // Lastly, ensure this tx will pass the mempool's chain limits + if (!chain().checkChainLimits(tx)) { strFailReason = _("Transaction has too long of a mempool chain"); return false; }