rpc_mempool.cpp raw

   1  // Copyright (c) 2011-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  #include <bench/bench.h>
   6  #include <consensus/amount.h>
   7  #include <kernel/cs_main.h>
   8  #include <primitives/transaction.h>
   9  #include <rpc/mempool.h>
  10  #include <script/script.h>
  11  #include <sync.h>
  12  #include <test/util/setup_common.h>
  13  #include <test/util/txmempool.h>
  14  #include <txmempool.h>
  15  #include <univalue.h>
  16  #include <util/check.h>
  17  #include <validation.h>
  18  
  19  #include <memory>
  20  #include <vector>
  21  
  22  
  23  static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)
  24  {
  25      LockPoints lp;
  26      AddToMempool(pool, CTxMemPoolEntry(tx, fee, /*time=*/0, /*entry_height=*/0, /*entry_sequence=*/0, COIN_AGE_CACHE_ZERO, /*spends_coinbase=*/false, /*extra_weight=*/0, /*sigops_cost=*/4, lp));
  27  }
  28  
  29  static void RpcMempool(benchmark::Bench& bench)
  30  {
  31      const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN);
  32      auto& chainman = *testing_setup->m_node.chainman;
  33      CTxMemPool& pool = *Assert(testing_setup->m_node.mempool);
  34      LOCK2(cs_main, pool.cs);
  35  
  36      for (int i = 0; i < 1000; ++i) {
  37          CMutableTransaction tx = CMutableTransaction();
  38          tx.vin.resize(1);
  39          tx.vin[0].scriptSig = CScript() << OP_1;
  40          tx.vin[0].scriptWitness.stack.push_back({1});
  41          tx.vout.resize(1);
  42          tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
  43          tx.vout[0].nValue = i;
  44          const CTransactionRef tx_r{MakeTransactionRef(tx)};
  45          AddTx(tx_r, /*fee=*/i, pool);
  46      }
  47  
  48      bench.run([&] {
  49          (void)MempoolToJSON(chainman, pool, /*verbose=*/true);
  50      });
  51  }
  52  
  53  BENCHMARK(RpcMempool, benchmark::PriorityLevel::HIGH);
  54