Skip to content

Commit bd5a026

Browse files
committed
Make UpdateTransactionsFromBlock use Epochs
1 parent 2ccb7cc commit bd5a026

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/txmempool.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
122122
// setMemPoolChildren will be updated, an assumption made in
123123
// UpdateForDescendants.
124124
for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
125-
// we cache the in-mempool children to avoid duplicate updates
126-
setEntries setChildren;
127125
// calculate children from mapNextTx
128126
txiter it = mapTx.find(hash);
129127
if (it == mapTx.end()) {
@@ -132,17 +130,21 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
132130
auto iter = mapNextTx.lower_bound(COutPoint(hash, 0));
133131
// First calculate the children, and update setMemPoolChildren to
134132
// include them, and update their setMemPoolParents to include this tx.
135-
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
136-
const uint256 &childHash = iter->second->GetHash();
137-
txiter childIter = mapTx.find(childHash);
138-
assert(childIter != mapTx.end());
139-
// We can skip updating entries we've encountered before or that
140-
// are in the block (which are already accounted for).
141-
if (setChildren.insert(childIter).second && !setAlreadyIncluded.count(childHash)) {
142-
UpdateChild(it, childIter, true);
143-
UpdateParent(childIter, it, true);
133+
// we cache the in-mempool children to avoid duplicate updates
134+
{
135+
const auto epoch = GetFreshEpoch();
136+
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
137+
const uint256 &childHash = iter->second->GetHash();
138+
txiter childIter = mapTx.find(childHash);
139+
assert(childIter != mapTx.end());
140+
// We can skip updating entries we've encountered before or that
141+
// are in the block (which are already accounted for).
142+
if (!visited(childIter) && !setAlreadyIncluded.count(childHash)) {
143+
UpdateChild(it, childIter, true);
144+
UpdateParent(childIter, it, true);
145+
}
144146
}
145-
}
147+
} // release epoch guard for UpdateForDescendants
146148
UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
147149
}
148150
}

0 commit comments

Comments
 (0)