Add GetTransactionAncestry to CTxMemPool for general purpose chain limit checking

This commit is contained in:
Karl-Johan Alm 2018-03-08 12:15:42 -05:00
parent 46847d69d2
commit 475a385a80
No known key found for this signature in database
GPG key ID: 57AF762DB3353322
2 changed files with 16 additions and 0 deletions

View file

@ -1066,6 +1066,16 @@ uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
return top->GetCountWithDescendants();
}
void CTxMemPool::GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const {
LOCK(cs);
auto it = mapTx.find(txid);
ancestors = descendants = 0;
if (it != mapTx.end()) {
ancestors = it->GetCountWithAncestors();
descendants = CalculateDescendantMaximum(it);
}
}
bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const {
LOCK(cs);
auto it = mapTx.find(txid);

View file

@ -620,6 +620,12 @@ public:
/** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
int Expire(int64_t time);
/**
* Calculate the ancestor and descendant count for the given transaction.
* The counts include the transaction itself.
*/
void GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const;
/** Returns false if the transaction is in the mempool and not within the chain limit specified. */
bool TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const;