Repository: bitcoin/bitcoin
File: src/txmempool.h (C/C++)

Code before:
#include <boost/multi_index/indexed_by.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/tag.hpp>
#include <boost/multi_index_container.hpp>

#include <atomic>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

class CChain;
class ValidationSignals;

struct bilingual_str;

/** 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;

/** How much linearization cost required for TxGraph clusters to have
 * "acceptable" quality, if they cannot be optimally linearized with less cost. */
static constexpr uint64_t ACCEPTABLE_COST = 64'000;

/** How much work we ask TxGraph to do after a mempool change occurs (either
 * due to a changeset being applied, a new block being found, or a reorg). */
static constexpr uint64_t POST_CHANGE_COST = 5 * ACCEPTABLE_COST;

/**
 * Test whether the LockPoints height and time are still valid on the current chain
 */
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

// extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
struct mempoolentry_txid
{
    typedef Txid result_type;
    result_type operator() (const CTxMemPoolEntry &entry) const
    {
        return entry.GetTx().GetHash();
    }

    result_type operator() (const CTransactionRef& tx) const
    {
        return tx->GetHash();
    }
};


Review comment (suggestion):
I was a bit surprised to see that the `ACCEPTABLE_COST` is flat per cluster. From what I understand in conjunction with the costs from above, small clusters of up to 15 txs will generally be optimal even within the `ACCEPTABLE_COST`, but assuming roughly similarly sized txs, it would mean that we would be willing to do a lot more work per total transaction weight, if we get a whole mempool full of clusters with 16–20 txs than if the mempool were filled with clusters that have 64 txs. Assuming the limit is chosen not to be an issue at highest compute per weight, but just thought it was counter-intuitive.

Code after:
#include <boost/multi_index/indexed_by.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/tag.hpp>
#include <boost/multi_index_container.hpp>

#include <atomic>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

class CChain;
class ValidationSignals;

struct bilingual_str;

/** 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;

/** How much linearization cost required for TxGraph clusters to have
 * "acceptable" quality, if they cannot be optimally linearized with less cost. */
static constexpr uint64_t ACCEPTABLE_COST = 75'000;

/** How much work we ask TxGraph to do after a mempool change occurs (either
 * due to a changeset being applied, a new block being found, or a reorg). */
static constexpr uint64_t POST_CHANGE_COST = 5 * ACCEPTABLE_COST;

/**
 * Test whether the LockPoints height and time are still valid on the current chain
 */
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

// extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
struct mempoolentry_txid
{
    typedef Txid result_type;
    result_type operator() (const CTxMemPoolEntry &entry) const
    {
        return entry.GetTx().GetHash();
    }

    result_type operator() (const CTransactionRef& tx) const
    {
        return tx->GetHash();
    }
};