Skip to content

Commit 6c5c60c

Browse files
committed
mempool: Use m_limit for UpdateTransactionsFromBlock
Since: - UpdateTransactionsFromBlock is only called by MaybeUpdateMempoolForReorg, which calls it with the gArgs-determined ancestor limits - UpdateForDescendants is only called by UpdateTransactionsFromBlock with the ancestor limits unchanged We can remove the requirement to specify the ancestor limits for both UpdateTransactionsFromBlock and UpdateForDescendants and just use the values in the m_limits member. Also move some removed comments to MemPoolLimits struct members. The uint64_t cast in UpdateForDescendants is not new behavior, see the diff in CChainState::MaybeUpdateMempoolForReorg for where they were previously.
1 parent 9e93b10 commit 6c5c60c

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

src/kernel/mempool_limits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ namespace kernel {
1616
* Most of the time, this struct should be referenced as CTxMemPool::Limits.
1717
*/
1818
struct MemPoolLimits {
19+
//! The maximum allowed number of transactions in a package including the entry and its ancestors.
1920
int64_t ancestor_count{DEFAULT_ANCESTOR_LIMIT};
21+
//! The maximum allowed size in virtual bytes of an entry and its ancestors within a package.
2022
int64_t ancestor_size_vbytes{DEFAULT_ANCESTOR_SIZE_LIMIT_KVB * 1'000};
23+
//! The maximum allowed number of transactions in a package including the entry and its descendants.
2124
int64_t descendant_count{DEFAULT_DESCENDANT_LIMIT};
25+
//! The maximum allowed size in virtual bytes of an entry and its descendants within a package.
2226
int64_t descendant_size_vbytes{DEFAULT_DESCENDANT_SIZE_LIMIT_KVB * 1'000};
2327
};
2428
} // namespace kernel

src/txmempool.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ size_t CTxMemPoolEntry::GetTxSize() const
107107
}
108108

109109
void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
110-
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove,
111-
uint64_t ancestor_size_limit, uint64_t ancestor_count_limit)
110+
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove)
112111
{
113112
CTxMemPoolEntry::Children stageEntries, descendants;
114113
stageEntries = updateIt->GetMemPoolChildrenConst();
@@ -148,15 +147,15 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
148147
// Don't directly remove the transaction here -- doing so would
149148
// invalidate iterators in cachedDescendants. Mark it for removal
150149
// by inserting into descendants_to_remove.
151-
if (descendant.GetCountWithAncestors() > ancestor_count_limit || descendant.GetSizeWithAncestors() > ancestor_size_limit) {
150+
if (descendant.GetCountWithAncestors() > uint64_t(m_limits.ancestor_count) || descendant.GetSizeWithAncestors() > uint64_t(m_limits.ancestor_size_vbytes)) {
152151
descendants_to_remove.insert(descendant.GetTx().GetHash());
153152
}
154153
}
155154
}
156155
mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
157156
}
158157

159-
void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate, uint64_t ancestor_size_limit, uint64_t ancestor_count_limit)
158+
void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate)
160159
{
161160
AssertLockHeld(cs);
162161
// For each entry in vHashesToUpdate, store the set of in-mempool, but not
@@ -199,7 +198,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
199198
}
200199
}
201200
} // release epoch guard for UpdateForDescendants
202-
UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded, descendants_to_remove, ancestor_size_limit, ancestor_count_limit);
201+
UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded, descendants_to_remove);
203202
}
204203

205204
for (const auto& txid : descendants_to_remove) {

src/txmempool.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,8 @@ class CTxMemPool
659659
*
660660
* @param[in] vHashesToUpdate The set of txids from the
661661
* disconnected block that have been accepted back into the mempool.
662-
* @param[in] ancestor_size_limit The maximum allowed size in virtual
663-
* bytes of an entry and its ancestors
664-
* @param[in] ancestor_count_limit The maximum allowed number of
665-
* transactions including the entry and its ancestors.
666662
*/
667-
void UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate,
668-
uint64_t ancestor_size_limit, uint64_t ancestor_count_limit) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
663+
void UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
669664

670665
/** Try to calculate all in-mempool ancestors of entry.
671666
* (these are all calculated including the tx itself)
@@ -840,14 +835,9 @@ class CTxMemPool
840835
* @param[out] descendants_to_remove Populated with the txids of entries that
841836
* exceed ancestor limits. It's the responsibility of the caller to
842837
* removeRecursive them.
843-
* @param[in] ancestor_size_limit the max number of ancestral bytes allowed
844-
* for any descendant
845-
* @param[in] ancestor_count_limit the max number of ancestor transactions
846-
* allowed for any descendant
847838
*/
848839
void UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
849-
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove,
850-
uint64_t ancestor_size_limit, uint64_t ancestor_count_limit) EXCLUSIVE_LOCKS_REQUIRED(cs);
840+
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs);
851841
/** Update ancestors of hash to add/remove it as a descendant transaction. */
852842
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs);
853843
/** Set ancestor state for an entry */

src/validation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ void CChainState::MaybeUpdateMempoolForReorg(
320320
// previously-confirmed transactions back to the mempool.
321321
// UpdateTransactionsFromBlock finds descendants of any transactions in
322322
// the disconnectpool that were added back and cleans up the mempool state.
323-
const uint64_t ancestor_count_limit = gArgs.GetIntArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
324-
const uint64_t ancestor_size_limit = gArgs.GetIntArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT_KVB) * 1000;
325-
m_mempool->UpdateTransactionsFromBlock(vHashUpdate, ancestor_size_limit, ancestor_count_limit);
323+
m_mempool->UpdateTransactionsFromBlock(vHashUpdate);
326324

327325
// Predicate to use for filtering transactions in removeForReorg.
328326
// Checks whether the transaction is still final and, if it spends a coinbase output, mature.

0 commit comments

Comments
 (0)