Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2022-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_TEST_UTIL_TXMEMPOOL_H6#define BITCOIN_TEST_UTIL_TXMEMPOOL_H8#include <policy/packages.h>9#include <txmempool.h>10#include <util/time.h>12namespace node {13struct NodeContext;14}15struct PackageMempoolAcceptResult;17CTxMemPool::Options MemPoolOptionsForTest(const node::NodeContext& node);19struct TestMemPoolEntryHelper {20// Default values21CAmount nFee{0};22NodeSeconds time{};23unsigned int nHeight{1};24uint64_t m_sequence{0};25bool spendsCoinbase{false};26unsigned int sigOpCost{4};27LockPoints lp;29CTxMemPoolEntry FromTx(const CMutableTransaction& tx) const;30CTxMemPoolEntry FromTx(const CTransactionRef& tx) const;32// Change the default value33TestMemPoolEntryHelper& Fee(CAmount _fee) { nFee = _fee; return *this; }34TestMemPoolEntryHelper& Time(NodeSeconds tp) { time = tp; return *this; }35TestMemPoolEntryHelper& Height(unsigned int _height) { nHeight = _height; return *this; }36TestMemPoolEntryHelper& Sequence(uint64_t _seq) { m_sequence = _seq; return *this; }37TestMemPoolEntryHelper& SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }38TestMemPoolEntryHelper& SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }39};41/** Check expected properties for every PackageMempoolAcceptResult, regardless of value. Returns42* a string if an error occurs with error populated, nullopt otherwise. If mempool is provided,43* checks that the expected transactions are in mempool (this should be set to nullptr for a test_accept).44*/45std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,46const PackageMempoolAcceptResult& result,47bool expect_valid,48const CTxMemPool* mempool);50/** Check that we never get into a state where an ephemeral dust51* transaction would be mined without the spend of the dust52* also being mined. This assumes standardness checks are being53* enforced.54*/55void CheckMempoolEphemeralInvariants(const CTxMemPool& tx_pool);57/** For every transaction in tx_pool, check TRUC invariants:58* - a TRUC tx's ancestor count must be within TRUC_ANCESTOR_LIMIT59* - a TRUC tx's descendant count must be within TRUC_DESCENDANT_LIMIT60* - if a TRUC tx has ancestors, its sigop-adjusted vsize must be within TRUC_CHILD_MAX_VSIZE61* - any non-TRUC tx must only have non-TRUC parents62* - any TRUC tx must only have TRUC parents63* */64void CheckMempoolTRUCInvariants(const CTxMemPool& tx_pool);66/** One-line wrapper for creating a mempool changeset with a single transaction67* and applying it if the policy limits are respected. */68void TryAddToMempool(CTxMemPool& tx_pool, const CTxMemPoolEntry& entry);70/** Mock the mempool minimum feerate by adding a transaction and calling TrimToSize(0),71* simulating the mempool "reaching capacity" and evicting by descendant feerate. Note that72* this clears the mempool, and the new minimum feerate will depend on the maximum feerate of73* transactions removed, so this must be called while the mempool is empty.74*75* @param target_feerate The new mempool minimum feerate after this function returns.76* Must be above max(incremental feerate, min relay feerate),77* or 1sat/vB with default settings.78* @param mempool The mempool to mock the minimum feerate for. Must be empty79* when called.80*/81void MockMempoolMinFee(const CFeeRate& target_feerate, CTxMemPool& mempool);83#endif // BITCOIN_TEST_UTIL_TXMEMPOOL_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.