diff options
author | Karl-Johan Alm <karljohan-alm@garage.co.jp> | 2018-03-08 12:15:42 -0500 |
---|---|---|
committer | Karl-Johan Alm <karljohan-alm@garage.co.jp> | 2018-06-11 19:04:55 +0900 |
commit | 475a385a80198a46a6d99846f99b968f04e9b470 (patch) | |
tree | 90b792ecd5f336c4f7c35051f6d90060348ea004 /src | |
parent | 46847d69d2c1cc908fd779daac7884e365955dbd (diff) |
Add GetTransactionAncestry to CTxMemPool for general purpose chain limit checking
Diffstat (limited to 'src')
-rw-r--r-- | src/txmempool.cpp | 10 | ||||
-rw-r--r-- | src/txmempool.h | 6 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 52d223656b..4f740b7c0a 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -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); diff --git a/src/txmempool.h b/src/txmempool.h index b60c2c50b1..d32c29a18f 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -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; |