Skip to content

Commit

Permalink
lock it up
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Aug 14, 2024
1 parent e5368f0 commit 6de1171
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ std::optional<std::vector<Txid>> CTxMemPool::FindEvictionCandidates(const CTxMem
std::vector<TxEntry::TxEntryRef> 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<Txid, SaltedTxidHasher> all_ancestor_txids;
for (const auto& ancestor : all_ancestors) {
Expand Down Expand Up @@ -297,21 +299,18 @@ std::optional<std::vector<Txid>> 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;
Expand Down

0 comments on commit 6de1171

Please sign in to comment.