Skip to content

Commit 475a385

Browse files
committed
Add GetTransactionAncestry to CTxMemPool for general purpose chain limit checking
1 parent 46847d6 commit 475a385

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/txmempool.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,16 @@ uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
10661066
return top->GetCountWithDescendants();
10671067
}
10681068

1069+
void CTxMemPool::GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const {
1070+
LOCK(cs);
1071+
auto it = mapTx.find(txid);
1072+
ancestors = descendants = 0;
1073+
if (it != mapTx.end()) {
1074+
ancestors = it->GetCountWithAncestors();
1075+
descendants = CalculateDescendantMaximum(it);
1076+
}
1077+
}
1078+
10691079
bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const {
10701080
LOCK(cs);
10711081
auto it = mapTx.find(txid);

src/txmempool.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,12 @@ class CTxMemPool
620620
/** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
621621
int Expire(int64_t time);
622622

623+
/**
624+
* Calculate the ancestor and descendant count for the given transaction.
625+
* The counts include the transaction itself.
626+
*/
627+
void GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const;
628+
623629
/** Returns false if the transaction is in the mempool and not within the chain limit specified. */
624630
bool TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const;
625631

0 commit comments

Comments
 (0)