Add GetTransactionAncestry to CTxMemPool for general purpose chain limit checking
This commit is contained in:
parent
46847d69d2
commit
475a385a80
2 changed files with 16 additions and 0 deletions
|
@ -1066,6 +1066,16 @@ uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
|
||||||
return top->GetCountWithDescendants();
|
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 {
|
bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const {
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
auto it = mapTx.find(txid);
|
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. */
|
/** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
|
||||||
int Expire(int64_t time);
|
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. */
|
/** 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;
|
bool TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue