Bitcoin ABC  0.26.3
P2P Digital Currency
block_assemble.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 The Bitcoin Core 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 <config.h>
7 #include <consensus/validation.h>
8 #include <script/standard.h>
9 #include <test/util/mining.h>
10 #include <test/util/setup_common.h>
11 #include <test/util/wallet.h>
12 #include <txmempool.h>
13 #include <validation.h>
14 
15 #include <vector>
16 
17 static void AssembleBlock(benchmark::Bench &bench) {
18  const Config &config = GetConfig();
19  TestingSetup test_setup{
21  /* extra_args */
22  {
23  "-nodebuglogfile",
24  "-nodebug",
25  },
26  };
27 
28  const CScript redeemScript = CScript() << OP_DROP << OP_TRUE;
29  const CScript SCRIPT_PUB =
30  CScript() << OP_HASH160 << ToByteVector(CScriptID(redeemScript))
31  << OP_EQUAL;
32 
33  const CScript scriptSig = CScript() << std::vector<uint8_t>(100, 0xff)
34  << ToByteVector(redeemScript);
35 
36  // Collect some loose transactions that spend the coinbases of our mined
37  // blocks
38  constexpr size_t NUM_BLOCKS{200};
39  std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
40  for (size_t b = 0; b < NUM_BLOCKS; ++b) {
42  tx.vin.push_back(MineBlock(config, test_setup.m_node, SCRIPT_PUB));
43  tx.vin.back().scriptSig = scriptSig;
44  tx.vout.emplace_back(1337 * SATOSHI, SCRIPT_PUB);
45  if (NUM_BLOCKS - b >= COINBASE_MATURITY) {
46  txs.at(b) = MakeTransactionRef(tx);
47  }
48  }
49 
50  {
51  LOCK(::cs_main);
52 
53  for (const auto &txr : txs) {
54  const MempoolAcceptResult res =
55  test_setup.m_node.chainman->ProcessTransaction(txr);
57  }
58  }
59 
60  bench.run([&] { PrepareBlock(config, test_setup.m_node, SCRIPT_PUB); });
61 }
62 
static constexpr Amount SATOSHI
Definition: amount.h:143
static void AssembleBlock(benchmark::Bench &bench)
BENCHMARK(AssembleBlock)
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:113
static const std::string REGTEST
A mutable version of CTransaction.
Definition: transaction.h:274
std::vector< CTxOut > vout
Definition: transaction.h:277
std::vector< CTxIn > vin
Definition: transaction.h:276
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:431
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:25
Definition: config.h:17
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
const Config & GetConfig()
Definition: config.cpp:34
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule).
Definition: consensus.h:32
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:316
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
std::vector< uint8_t > ToByteVector(const T &in)
Definition: script.h:42
@ OP_EQUAL
Definition: script.h:119
@ OP_HASH160
Definition: script.h:160
@ OP_TRUE
Definition: script.h:57
@ OP_DROP
Definition: script.h:97
Validation result for a single transaction mempool acceptance.
Definition: validation.h:216
const ResultType m_result_type
Definition: validation.h:226
@ VALID
Fully validated, valid.
#define LOCK(cs)
Definition: sync.h:306
assert(!tx.IsCoinBase())