From 6de11719f3706fc076fbbddca339f3674bec5837 Mon Sep 17 00:00:00 2001 From: Greg Sanders Date: Wed, 14 Aug 2024 17:18:45 -0400 Subject: [PATCH] lock it up --- src/txmempool.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index caf105b455060..30249657ab0f0 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -241,6 +241,8 @@ std::optional> CTxMemPool::FindEvictionCandidates(const CTxMem std::vector parents_entry; for (const auto& parent : parents) parents_entry.push_back(*parent); + LOCK(cs); + const auto all_ancestors = txgraph.GetAncestors(parents_entry); std::unordered_set all_ancestor_txids; for (const auto& ancestor : all_ancestors) { @@ -297,21 +299,18 @@ std::optional> CTxMemPool::FindEvictionCandidates(const CTxMem // and topologically valid to remove from the list for (const auto eviction_candidate : processed_txids) { - { - LOCK(cs); - // Only keep candidates who have no parent in the conflicts list - const auto parents = GetParents(*GetEntry(eviction_candidate)); - bool found_parent = false; - for (const auto& parent : parents) { - if (processed_txids.contains(parent.get().GetTx().GetHash())) { - found_parent = true; - break; - } - } - if (!found_parent) { - eviction_candidates.push_back(eviction_candidate); + // Only keep candidates who have no parent in the conflicts list + const auto parents = GetParents(*GetEntry(eviction_candidate)); + bool found_parent = false; + for (const auto& parent : parents) { + if (processed_txids.contains(parent.get().GetTx().GetHash())) { + found_parent = true; + break; } } + if (!found_parent) { + eviction_candidates.push_back(eviction_candidate); + } } if (eviction_candidates.empty()) return std::nullopt;