mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
Add GetTransactionAncestry to CTxMemPool for general purpose chain limit checking
This commit is contained in:
parent
46847d69d2
commit
475a385a80
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user