txmempool.h raw

   1  // Copyright (c) 2022 The Limenka developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef LIMENKA_TEST_UTIL_TXMEMPOOL_H
   6  #define LIMENKA_TEST_UTIL_TXMEMPOOL_H
   7  
   8  #include <policy/coin_age_priority.h>
   9  #include <policy/packages.h>
  10  #include <txmempool.h>
  11  #include <util/time.h>
  12  
  13  namespace node {
  14  struct NodeContext;
  15  }
  16  struct PackageMempoolAcceptResult;
  17  
  18  CTxMemPool::Options MemPoolOptionsForTest(const node::NodeContext& node);
  19  
  20  struct TestMemPoolEntryHelper {
  21      // Default values
  22      CAmount nFee{0};
  23      NodeSeconds time{};
  24      unsigned int nHeight{1};
  25      uint64_t m_sequence{0};
  26      bool spendsCoinbase{false};
  27      unsigned int sigOpCost{4};
  28      LockPoints lp;
  29  
  30      CTxMemPoolEntry FromTx(const CMutableTransaction& tx) const;
  31      CTxMemPoolEntry FromTx(const CTransactionRef& tx) const;
  32  
  33      // Change the default value
  34      TestMemPoolEntryHelper& Fee(CAmount _fee) { nFee = _fee; return *this; }
  35      TestMemPoolEntryHelper& Time(NodeSeconds tp) { time = tp; return *this; }
  36      TestMemPoolEntryHelper& Height(unsigned int _height) { nHeight = _height; return *this; }
  37      TestMemPoolEntryHelper& Sequence(uint64_t _seq) { m_sequence = _seq; return *this; }
  38      TestMemPoolEntryHelper& SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
  39      TestMemPoolEntryHelper& SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }
  40  };
  41  
  42  /** Check expected properties for every PackageMempoolAcceptResult, regardless of value. Returns
  43   * a string if an error occurs with error populated, nullopt otherwise. If mempool is provided,
  44   * checks that the expected transactions are in mempool (this should be set to nullptr for a test_accept).
  45  */
  46  std::optional<std::string>  CheckPackageMempoolAcceptResult(const Package& txns,
  47                                                              const PackageMempoolAcceptResult& result,
  48                                                              bool expect_valid,
  49                                                              const CTxMemPool* mempool);
  50  
  51  /** Check that we never get into a state where an ephemeral dust
  52   *  transaction would be mined without the spend of the dust
  53   *  also being mined. This assumes standardness checks are being
  54   *  enforced.
  55  */
  56  void CheckMempoolEphemeralInvariants(const CTxMemPool& tx_pool);
  57  
  58  /** For every transaction in tx_pool, check TRUC invariants:
  59   * - a TRUC tx's ancestor count must be within TRUC_ANCESTOR_LIMIT
  60   * - a TRUC tx's descendant count must be within TRUC_DESCENDANT_LIMIT
  61   * - if a TRUC tx has ancestors, its sigop-adjusted vsize must be within TRUC_CHILD_MAX_VSIZE
  62   * - any non-TRUC tx must only have non-TRUC parents
  63   * - any TRUC tx must only have TRUC parents
  64   *   */
  65  void CheckMempoolTRUCInvariants(const CTxMemPool& tx_pool);
  66  
  67  /** One-line wrapper for creating a mempool changeset with a single transaction
  68   *  and applying it. */
  69  void AddToMempool(CTxMemPool& tx_pool, const CTxMemPoolEntry& entry);
  70  
  71  #endif // LIMENKA_TEST_UTIL_TXMEMPOOL_H
  72