Make UpdateTransactionsFromBlock use Epochs

This commit is contained in:
Jeremy Rubin 2020-01-14 11:45:46 -08:00
parent 2ccb7cca4a
commit bd5a026928

View File

@ -122,8 +122,6 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
// setMemPoolChildren will be updated, an assumption made in // setMemPoolChildren will be updated, an assumption made in
// UpdateForDescendants. // UpdateForDescendants.
for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) { for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
// we cache the in-mempool children to avoid duplicate updates
setEntries setChildren;
// calculate children from mapNextTx // calculate children from mapNextTx
txiter it = mapTx.find(hash); txiter it = mapTx.find(hash);
if (it == mapTx.end()) { if (it == mapTx.end()) {
@ -132,17 +130,21 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
auto iter = mapNextTx.lower_bound(COutPoint(hash, 0)); auto iter = mapNextTx.lower_bound(COutPoint(hash, 0));
// First calculate the children, and update setMemPoolChildren to // First calculate the children, and update setMemPoolChildren to
// include them, and update their setMemPoolParents to include this tx. // include them, and update their setMemPoolParents to include this tx.
// we cache the in-mempool children to avoid duplicate updates
{
const auto epoch = GetFreshEpoch();
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) { for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
const uint256 &childHash = iter->second->GetHash(); const uint256 &childHash = iter->second->GetHash();
txiter childIter = mapTx.find(childHash); txiter childIter = mapTx.find(childHash);
assert(childIter != mapTx.end()); assert(childIter != mapTx.end());
// We can skip updating entries we've encountered before or that // We can skip updating entries we've encountered before or that
// are in the block (which are already accounted for). // are in the block (which are already accounted for).
if (setChildren.insert(childIter).second && !setAlreadyIncluded.count(childHash)) { if (!visited(childIter) && !setAlreadyIncluded.count(childHash)) {
UpdateChild(it, childIter, true); UpdateChild(it, childIter, true);
UpdateParent(childIter, it, true); UpdateParent(childIter, it, true);
} }
} }
} // release epoch guard for UpdateForDescendants
UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded); UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
} }
} }