aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKarl-Johan Alm <karljohan-alm@garage.co.jp>2018-05-23 09:13:43 +0900
committerKarl-Johan Alm <karljohan-alm@garage.co.jp>2018-06-11 19:09:44 +0900
commita08d76bcfee6f563a268933357931abe32060668 (patch)
tree15034792750cfd2d8630d17b99f2c28748acb330 /src
parent6d3568371eb2559d65a3e2334252d36a262319e8 (diff)
mempool: Calculate descendant maximum thoroughly
Diffstat (limited to 'src')
-rw-r--r--src/txmempool.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 9df9b0e45a..c1145d9643 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -1056,14 +1056,25 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpends
}
uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
- // find top parent
- txiter top = entry;
- for (;;) {
- const setEntries& parents = GetMemPoolParents(top);
- if (parents.size() == 0) break;
- top = *parents.begin();
+ // find parent with highest descendant count
+ std::vector<txiter> candidates;
+ setEntries counted;
+ candidates.push_back(entry);
+ uint64_t maximum = 0;
+ while (candidates.size()) {
+ txiter candidate = candidates.back();
+ candidates.pop_back();
+ if (!counted.insert(candidate).second) continue;
+ const setEntries& parents = GetMemPoolParents(candidate);
+ if (parents.size() == 0) {
+ maximum = std::max(maximum, candidate->GetCountWithDescendants());
+ } else {
+ for (txiter i : parents) {
+ candidates.push_back(i);
+ }
+ }
}
- return top->GetCountWithDescendants();
+ return maximum;
}
void CTxMemPool::GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const {