Skip to content

Commit

Permalink
[refactor] Complete ripping boost includes from txmempool.h
Browse files Browse the repository at this point in the history
All the header files should now no longer contain boost multi index
includes. Only the implementation files directly include the multi index
types for manipulating mempool data structures.

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 091204b commit 49ead1a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <consensus/validation.h>
#include <deploymentstatus.h>
#include <logging.h>
#include <mempool_set_definitions.h>
#include <policy/feerate.h>
#include <policy/policy.h>
#include <pow.h>
Expand All @@ -35,6 +36,7 @@

using MemPoolMultiIndex::ancestor_score;
using MemPoolMultiIndex::CompareTxMemPoolEntryByAncestorFee;
using MemPoolMultiIndex::indexed_transaction_set;
using MemPoolMultiIndex::raw_txiter;

// Container for tracking updates to ancestor feerate as we include (parent)
Expand Down Expand Up @@ -413,7 +415,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
// Keep track of entries that failed inclusion, to avoid duplicate work
std::set<Txid> failedTx;

CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx->impl.get<ancestor_score>().begin();
indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx->impl.get<ancestor_score>().begin();
raw_txiter iter;

// Limit the number of attempts to add transactions to the block when it is
Expand Down
4 changes: 3 additions & 1 deletion src/test/mempool_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/system.h>
#include <mempool_set_definitions.h>
#include <policy/policy.h>
#include <test/util/txmempool.h>
#include <txmempool.h>
Expand All @@ -15,6 +16,7 @@

using MemPoolMultiIndex::ancestor_score;
using MemPoolMultiIndex::descendant_score;
using MemPoolMultiIndex::indexed_transaction_set;

BOOST_FIXTURE_TEST_SUITE(mempool_tests, TestingSetup)

Expand Down Expand Up @@ -122,7 +124,7 @@ template <typename name>
static void CheckSort(CTxMemPool& pool, std::vector<std::string>& sortedOrder) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
{
BOOST_CHECK_EQUAL(pool.size(), sortedOrder.size());
typename CTxMemPool::indexed_transaction_set::index<name>::type::iterator it = pool.mapTx->impl.get<name>().begin();
typename indexed_transaction_set::index<name>::type::iterator it = pool.mapTx->impl.get<name>().begin();
int count = 0;
for (; it != pool.mapTx->impl.get<name>().end(); ++it, ++count) {
BOOST_CHECK_EQUAL(it->GetTx().GetHash().ToString(), sortedOrder[count]);
Expand Down
17 changes: 11 additions & 6 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <consensus/tx_verify.h>
#include <consensus/validation.h>
#include <logging.h>
#include <mempool_set_definitions.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <policy/settings.h>
Expand All @@ -34,6 +35,7 @@
using MemPoolMultiIndex::CompareTxMemPoolEntryByScore;
using MemPoolMultiIndex::descendant_score;
using MemPoolMultiIndex::entry_time;
using MemPoolMultiIndex::indexed_transaction_set;
using MemPoolMultiIndex::MapTxImpl;
using MemPoolMultiIndex::raw_setEntries;
using MemPoolMultiIndex::raw_txiter;
Expand Down Expand Up @@ -423,6 +425,8 @@ CTxMemPool::CTxMemPool(const Options& opts)
{
}

CTxMemPool::~CTxMemPool() = default;

bool CTxMemPool::isSpent(const COutPoint& outpoint) const
{
LOCK(cs);
Expand Down Expand Up @@ -679,7 +683,7 @@ namespace {
class DepthAndScoreComparator
{
public:
bool operator()(const CTxMemPool::indexed_transaction_set::const_iterator& a, const CTxMemPool::indexed_transaction_set::const_iterator& b)
bool operator()(const indexed_transaction_set::const_iterator& a, const indexed_transaction_set::const_iterator& b)
{
uint64_t counta = a->GetCountWithAncestors();
uint64_t countb = b->GetCountWithAncestors();
Expand All @@ -691,15 +695,15 @@ class DepthAndScoreComparator
};
} // namespace

static std::vector<MemPoolMultiIndex::indexed_transaction_set::const_iterator> GetSortedDepthAndScore(
const std::unique_ptr<MemPoolMultiIndex::MapTxImpl>& mapTx, RecursiveMutex& cs) EXCLUSIVE_LOCKS_REQUIRED(cs)
static std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore(
const std::unique_ptr<MapTxImpl>& mapTx, RecursiveMutex& cs) EXCLUSIVE_LOCKS_REQUIRED(cs)
{
std::vector<MemPoolMultiIndex::indexed_transaction_set::const_iterator> iters;
std::vector<indexed_transaction_set::const_iterator> iters;
AssertLockHeld(cs);

iters.reserve(mapTx->impl.size());

for (MemPoolMultiIndex::indexed_transaction_set::iterator mi = mapTx->impl.begin(); mi != mapTx->impl.end(); ++mi) {
for (indexed_transaction_set::iterator mi = mapTx->impl.begin(); mi != mapTx->impl.end(); ++mi) {
iters.push_back(mi);
}
std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
Expand Down Expand Up @@ -844,7 +848,8 @@ void CTxMemPool::queryHashes(std::vector<uint256>& vtxid) const
}
}

static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
static TxMempoolInfo GetInfo(indexed_transaction_set::const_iterator it)
{
return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
}

Expand Down
10 changes: 8 additions & 2 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <kernel/mempool_limits.h> // IWYU pragma: export
#include <kernel/mempool_options.h> // IWYU pragma: export
#include <kernel/mempool_removal_reason.h> // IWYU pragma: export
#include <mempool_set_definitions.h>
#include <policy/feerate.h>
#include <policy/packages.h>
#include <primitives/transaction.h>
Expand All @@ -34,6 +33,12 @@

class CChain;

namespace MemPoolMultiIndex {
struct txiter;
struct MapTxImpl;
struct setEntries;
} // namespace MemPoolMultiIndex

/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;

Expand Down Expand Up @@ -197,7 +202,6 @@ class CTxMemPool
* the mempool is consistent with the new chain tip and fully populated.
*/

using indexed_transaction_set = MemPoolMultiIndex::indexed_transaction_set;
using MapTxImpl = MemPoolMultiIndex::MapTxImpl;

mutable RecursiveMutex cs;
Expand Down Expand Up @@ -272,6 +276,8 @@ class CTxMemPool
*/
explicit CTxMemPool(const Options& opts);

~CTxMemPool();

/**
* If sanity-checking is turned on, check makes sure the pool is
* consistent (does not contain two transactions that spend the same inputs,
Expand Down

0 comments on commit 49ead1a

Please sign in to comment.