Page MenuHomePhabricator

Migrate the mempool to hold shared pointers
ClosedPublic

Authored by Fabien on Mar 23 2023, 16:24.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC5471411dba6d: Migrate the mempool to hold shared pointers
Summary

The mempool actually stores CTxMemPoolEntry objects, which are wrappers
around transactions with added/cached statistics. Since there is a
single mempool this is not a problem and all the algorithms are using
iterators and/or references to manipulate the objects that remain owned
by the mempool.

With pre-consensus we will need to move these entries to other data
structures: the conflicting txs will be voted on and need to be stored,
and we want to build a tree of the finalized txs that will be used to
generate the block template.

In order to not lose and having to recompute the cached data (especially
the fees) we need to be able to move the entries from one container to
another. Using a shared pointer is a step in this direction. In the end
we will probably use a RCUPtr but this require additional refactors,
as it makes the entry non copyable. This first step is the purpose of
this diff.

Depends on D13439 and D13440.

Test Plan

With debug:

ninja all check-all

ninja check-extended

Run the ASAN, UBSAN and TSAN builds.

Diff Detail

Event Timeline

Improve comment on CompareIteratorById

Fix a use after move issue

src/txmempool.h
103

This needs to be refactored, or updated to not hold shared pointers.
It creates a circular reference which causes a memory leak upon entry destruction, because the reference counter will never reach 0.

Fabien published this revision for review.Jan 12 2024, 15:21
This revision is now accepted and ready to land.Jan 12 2024, 16:14
This revision was automatically updated to reflect the committed changes.