Bitcoin ABC  0.24.10
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  // Required for ::AcceptToMemoryPool.
52  LOCK(::cs_main);
53 
54  for (const auto &txr : txs) {
55  TxValidationState vstate;
56  bool ret{::AcceptToMemoryPool(config, *test_setup.m_node.mempool,
57  vstate, txr,
58  false /* bypass_limits */)};
59  assert(ret);
60  }
61  }
62 
63  bench.run([&] { PrepareBlock(config, test_setup.m_node, SCRIPT_PUB); });
64 }
65 
MakeTransactionRef
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:320
COINBASE_MATURITY
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule).
Definition: consensus.h:32
validation.h
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
OP_HASH160
@ OP_HASH160
Definition: script.h:159
OP_DROP
@ OP_DROP
Definition: script.h:96
txmempool.h
TxValidationState
Definition: validation.h:137
SATOSHI
static constexpr Amount SATOSHI
Definition: amount.h:153
Config
Definition: config.h:17
cs_main
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:103
CBaseChainParams::REGTEST
static const std::string REGTEST
Definition: chainparamsbase.h:23
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
standard.h
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
bench.h
BENCHMARK
BENCHMARK(AssembleBlock)
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:281
ToByteVector
std::vector< uint8_t > ToByteVector(const T &in)
Definition: script.h:41
LOCK
#define LOCK(cs)
Definition: sync.h:241
OP_TRUE
@ OP_TRUE
Definition: script.h:56
OP_EQUAL
@ OP_EQUAL
Definition: script.h:118
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:319
config.h
AssembleBlock
static void AssembleBlock(benchmark::Bench &bench)
Definition: block_assemble.cpp:17
AcceptToMemoryPool
bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, TxValidationState &state, const CTransactionRef &tx, bool bypass_limits, bool test_accept, Amount *fee_out)
(try to) add transaction to memory pool
Definition: validation.cpp:779
CScriptID
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:65
GetConfig
const Config & GetConfig()
Definition: config.cpp:34
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:280
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:278