Skip to content

Commit

Permalink
[refactor] Move some CTxMemPool methods to implementation.
Browse files Browse the repository at this point in the history
This allows them to use the mapTx without including the full mapTx
definition in the header.

The context of this change is an effort towards removing the boost multi
index includes from the header tree. The goal is that the experimental
`bitcoin-chainstate` binary can be compiled without requiring boost
includes.
  • Loading branch information
TheCharlatan committed Nov 14, 2023
1 parent d5e8314 commit 1fbd9d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 21 additions & 0 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,27 @@ void CTxMemPool::SetLoadTried(bool load_tried)
m_load_tried = load_tried;
}

unsigned long CTxMemPool::size() const
{
LOCK(cs);
return mapTx->impl.size();
}

bool CTxMemPool::exists(const GenTxid& gtxid) const
{
LOCK(cs);
if (gtxid.IsWtxid()) {
return (mapTx->impl.get<MemPoolMultiIndex::index_by_wtxid>().count(gtxid.GetHash()) != 0);
}
return (mapTx->impl.count(gtxid.GetHash()) != 0);
}

std::unique_ptr<txiter> CTxMemPool::get_iter_from_wtxid(const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
{
AssertLockHeld(cs);
return std::make_unique<txiter>(mapTx->impl.project<0>(mapTx->impl.get<MemPoolMultiIndex::index_by_wtxid>().find(wtxid)));
}

std::vector<CTxMemPoolEntryRef> CTxMemPool::GatherClusters(const std::vector<uint256>& txids) const
{
AssertLockHeld(cs);
Expand Down
21 changes: 3 additions & 18 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,7 @@ class CTxMemPool
*/
void SetLoadTried(bool load_tried);

unsigned long size() const
{
LOCK(cs);
return mapTx->impl.size();
}
unsigned long size() const;

uint64_t GetTotalTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
{
Expand All @@ -484,14 +480,7 @@ class CTxMemPool
return m_total_fee;
}

bool exists(const GenTxid& gtxid) const
{
LOCK(cs);
if (gtxid.IsWtxid()) {
return (mapTx->impl.get<MemPoolMultiIndex::index_by_wtxid>().count(gtxid.GetHash()) != 0);
}
return (mapTx->impl.count(gtxid.GetHash()) != 0);
}
bool exists(const GenTxid& gtxid) const;

const CTxMemPoolEntry* GetEntry(const Txid& txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs);

Expand Down Expand Up @@ -593,11 +582,7 @@ class CTxMemPool
*/
void removeUnchecked(txiter& entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs);

std::unique_ptr<txiter> get_iter_from_wtxid(const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
{
AssertLockHeld(cs);
return std::make_unique<txiter>(mapTx->impl.project<0>(mapTx->impl.get<MemPoolMultiIndex::index_by_wtxid>().find(wtxid)));
}
std::unique_ptr<txiter> get_iter_from_wtxid(const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs);

/** Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
* Does not require that all of the hashes correspond to actual transactions in the mempool,
Expand Down

0 comments on commit 1fbd9d7

Please sign in to comment.