aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/txmempool.cpp17
-rw-r--r--src/txmempool.h13
2 files changed, 18 insertions, 12 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 53de2d2618..4a992bf2a4 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -150,16 +150,18 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
}
}
-bool CTxMemPool::CalculateAncestorsAndCheckLimits(const CTxMemPoolEntry& entry,
+
+bool CTxMemPool::CalculateAncestorsAndCheckLimits(size_t entry_size,
+ size_t entry_count,
setEntries& setAncestors,
- CTxMemPoolEntry::Parents &staged_ancestors,
+ CTxMemPoolEntry::Parents& staged_ancestors,
uint64_t limitAncestorCount,
uint64_t limitAncestorSize,
uint64_t limitDescendantCount,
uint64_t limitDescendantSize,
std::string &errString) const
{
- size_t totalSizeWithAncestors = entry.GetTxSize();
+ size_t totalSizeWithAncestors = entry_size;
while (!staged_ancestors.empty()) {
const CTxMemPoolEntry& stage = staged_ancestors.begin()->get();
@@ -169,10 +171,10 @@ bool CTxMemPool::CalculateAncestorsAndCheckLimits(const CTxMemPoolEntry& entry,
staged_ancestors.erase(stage);
totalSizeWithAncestors += stageit->GetTxSize();
- if (stageit->GetSizeWithDescendants() + entry.GetTxSize() > limitDescendantSize) {
+ if (stageit->GetSizeWithDescendants() + entry_size > limitDescendantSize) {
errString = strprintf("exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
return false;
- } else if (stageit->GetCountWithDescendants() + 1 > limitDescendantCount) {
+ } else if (stageit->GetCountWithDescendants() + entry_count > limitDescendantCount) {
errString = strprintf("too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
return false;
} else if (totalSizeWithAncestors > limitAncestorSize) {
@@ -188,7 +190,7 @@ bool CTxMemPool::CalculateAncestorsAndCheckLimits(const CTxMemPoolEntry& entry,
if (setAncestors.count(parent_it) == 0) {
staged_ancestors.insert(parent);
}
- if (staged_ancestors.size() + setAncestors.size() + 1 > limitAncestorCount) {
+ if (staged_ancestors.size() + setAncestors.size() + entry_count > limitAncestorCount) {
errString = strprintf("too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
return false;
}
@@ -231,7 +233,8 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry,
staged_ancestors = it->GetMemPoolParentsConst();
}
- return CalculateAncestorsAndCheckLimits(entry, setAncestors, staged_ancestors,
+ return CalculateAncestorsAndCheckLimits(entry.GetTxSize(), /* entry_count */ 1,
+ setAncestors, staged_ancestors,
limitAncestorCount, limitAncestorSize,
limitDescendantCount, limitDescendantSize, errString);
}
diff --git a/src/txmempool.h b/src/txmempool.h
index 76ca83c25c..71345ffb5d 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -587,12 +587,15 @@ private:
/**
- * Helper function to populate setAncestors with all the ancestors of entry and apply ancestor
- * and descendant limits.
- * param@[out] setAncestors Will be populated with all mempool ancestors of entry.
- * param@[in] staged_ancestors Should contain mempool parents of entry.
+ * Helper function to calculate all in-mempool ancestors of staged_ancestors and apply ancestor
+ * and descendant limits (including staged_ancestors thsemselves, entry_size and entry_count).
+ * param@[in] entry_size Virtual size to include in the limits.
+ * param@[in] entry_count How many entries to include in the limits.
+ * param@[in] staged_ancestors Should contain entries in the mempool.
+ * param@[out] setAncestors Will be populated with all mempool ancestors.
*/
- bool CalculateAncestorsAndCheckLimits(const CTxMemPoolEntry& entry,
+ bool CalculateAncestorsAndCheckLimits(size_t entry_size,
+ size_t entry_count,
setEntries& setAncestors,
CTxMemPoolEntry::Parents &staged_ancestors,
uint64_t limitAncestorCount,