Skip to content

Commit 5fb9ddf

Browse files
committed
[refactor] Add txmempool helper for node/interfaces
1 parent 2b01ae2 commit 5fb9ddf

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/node/interfaces.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,7 @@ class ChainImpl : public Chain
648648
{
649649
if (!m_node.mempool) return false;
650650
LOCK(m_node.mempool->cs);
651-
auto it = m_node.mempool->GetIter(txid);
652-
return it && (*it)->GetCountWithDescendants() > 1;
651+
return m_node.mempool->GetTxCountWithDescendants(txid) > 1;
653652
}
654653
bool broadcastTransaction(const CTransactionRef& tx,
655654
const CAmount& max_tx_fee,

src/txmempool.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,14 @@ bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const
993993
return true;
994994
}
995995

996+
uint64_t CTxMemPool::GetTxCountWithDescendants(const uint256& txid) const
997+
{
998+
AssertLockHeld(cs);
999+
auto it = GetIter(txid);
1000+
if (!it) return 0;
1001+
return (*it)->GetCountWithDescendants();
1002+
}
1003+
9961004
CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { }
9971005

9981006
bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const {

src/txmempool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ class CTxMemPool
531531
* don't actually exist in the mempool, returns an empty vector. */
532532
std::vector<txiter> GetIterVec(const std::vector<uint256>& txids) const EXCLUSIVE_LOCKS_REQUIRED(cs);
533533

534+
uint64_t GetTxCountWithDescendants(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs);
535+
534536
/** Remove a set of transactions from the mempool.
535537
* If a transaction is in this set, then all in-mempool descendants must
536538
* also be in the set, unless this transaction is being removed for being

0 commit comments

Comments
 (0)