Page MenuHomePhabricator

Add Epoch Guards to CTXMemPoolEntry and CTxMemPool, make UpdateTransactionsFromBlock use Epochs
ClosedPublic

Authored by PiRK on Dec 21 2020, 17:19.

Details

Summary

UpdateTransactionsFromBlock is called during a re-org. When a re-org occurs, all of the transactions in the mempool may be descendants from a transaction which is in the pre-reorg block. This can cause us to propagate updates, worst case, to every transaction in the mempool.

Because we construct a setEntries setChildren, which is backed by a std::set, it is possible that this algorithm is O(N log N).

By using an Epoch visitor pattern, we can limit this to O(N) worst case behavior.

Epochs are also less resource intensive than almost any set option (e.g., hash set) because they are allocation free.

This is a backport of Core PR17925

Test Plan

ninja && ninja check

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Dec 21 2020, 17:19
majcosta requested changes to this revision.Dec 21 2020, 18:58
majcosta added a subscriber: majcosta.
majcosta added inline comments.
src/txmempool.cpp
179–180 ↗(On Diff #26506)

to make sense this comment must either be on the same line of the scope's closing brackets or the line immediately before

as it stands it might misleadingly point at the UpdateForDescendants(... call

This revision now requires changes to proceed.Dec 21 2020, 18:58

put the comment back on the same line as closing bracket

This revision is now accepted and ready to land.Dec 21 2020, 21:08