From 95a8297d481e96d65ac81e4dac72b2ebecb9c765 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Thu, 23 Jan 2025 09:26:05 -0500 Subject: [PATCH] Check cluster limits when using -walletrejectlongchains --- src/node/interfaces.cpp | 7 ++++--- src/txmempool.cpp | 11 +++++++++++ src/txmempool.h | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 0626e2c6837..8e38ae126ff 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -719,10 +719,11 @@ public: util::Result checkChainLimits(const CTransactionRef& tx) override { if (!m_node.mempool) return {}; - LockPoints lp; - CTxMemPoolEntry entry(TxGraph::Ref(), tx, 0, 0, 0, 0, false, 0, lp); + if (!m_node.mempool->CheckPolicyLimits(tx)) { + return util::Error{Untranslated("too many unconfirmed transactions in cluster")}; + } LOCK(m_node.mempool->cs); - return m_node.mempool->CheckPackageLimits({tx}, entry.GetTxSize()); + return m_node.mempool->CheckPackageLimits({tx}, GetVirtualTransactionSize(*tx)); } CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override { diff --git a/src/txmempool.cpp b/src/txmempool.cpp index af3a54cc4aa..e5a318524dd 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1078,6 +1078,17 @@ void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants, MemPool } } +bool CTxMemPool::CheckPolicyLimits(const CTransactionRef& tx) +{ + LOCK(cs); + // Use ChangeSet interface to check whether the chain + // limits would be violated. Note that the changeset will be destroyed + // when it goes out of scope. + auto changeset = GetChangeSet(); + (void) changeset->StageAddition(tx, /*fee=*/0, /*time=*/0, /*entry_height=*/0, /*entry_sequence=*/0, /*spends_coinbase=*/false, /*sigops_cost=*/0, LockPoints{}); + return changeset->CheckMemPoolPolicyLimits(); +} + int CTxMemPool::Expire(std::chrono::seconds time) { AssertLockHeld(cs); diff --git a/src/txmempool.h b/src/txmempool.h index 60087561fea..2b5882c8a4b 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -681,6 +681,8 @@ public: if (exists(txid)) m_unbroadcast_txids.insert(txid); }; + bool CheckPolicyLimits(const CTransactionRef& tx); + /** Removes a transaction from the unbroadcast set */ void RemoveUnbroadcastTx(const Txid& txid, const bool unchecked = false);