Bitcoin ABC 0.34.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
7#include <config.h>
9#include <node/miner.h>
10#include <script/solver.h>
11#include <txmempool.h>
12#include <validation.h>
13
14#include <test/util/mining.h>
15#include <test/util/script.h>
16#include <test/util/setup_common.h>
17#include <test/util/wallet.h>
18
19#include <vector>
20
23 << OP_HASH160
25
26static void AssembleBlock(benchmark::Bench &bench) {
27 const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
28 const Config &config = test_setup->m_node.chainman->GetConfig();
29
30 const CScript scriptSig = CScript() << ToByteVector(CScript() << OP_TRUE);
31
32 // Collect some loose transactions that spend the coinbases of our mined
33 // blocks
34 constexpr size_t NUM_BLOCKS{200};
35 std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
36 for (size_t b = 0; b < NUM_BLOCKS; ++b) {
38 tx.vin.push_back(MineBlock(config, test_setup->m_node, P2SH_OP_TRUE));
39 tx.vin.back().scriptSig = scriptSig;
40 tx.vout.emplace_back(1337 * SATOSHI, P2SH_OP_TRUE);
41 // Pad the tx so it's not undersized
42 tx.vout.emplace_back(Amount::zero(), CScript()
43 << OP_RETURN
44 << std::vector<uint8_t>(100));
45 if (NUM_BLOCKS - b >= COINBASE_MATURITY) {
46 txs.at(b) = MakeTransactionRef(tx);
47 }
48 }
49
50 {
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, P2SH_OP_TRUE); });
61}
62
64 FastRandomContext det_rand{true};
65 auto testing_setup{MakeNoLogFileContext<TestChain100Setup>()};
66 testing_setup->PopulateMempool(det_rand, /*num_transactions=*/1000,
67 /*submit=*/true);
68 const Config &config = testing_setup->m_node.chainman->GetConfig();
69 node::BlockAssembler::Options assembler_options;
70 assembler_options.test_block_validity = false;
71
72 bench.run([&] {
73 PrepareBlock(config, testing_setup->m_node, P2SH_OP_TRUE,
74 assembler_options);
75 });
76}
77
79 FastRandomContext det_rand{true};
80 auto testing_setup = MakeNoLogFileContext<AvalancheTestChain100Setup>();
81 testing_setup->PopulateMempool(det_rand, /*num_transactions=*/1000,
82 /*submit=*/true);
83 const Config &config = testing_setup->m_node.chainman->GetConfig();
84 node::BlockAssembler::Options assembler_options;
85 assembler_options.test_block_validity = false;
86 assembler_options.add_finalized_txs = true;
87
88 bench.run([&] {
89 PrepareBlock(config, testing_setup->m_node, P2SH_OP_TRUE,
90 assembler_options);
91 });
92}
93
static constexpr Amount SATOSHI
Definition amount.h:153
#define BENCHMARK(n)
Definition bench.h:65
static void AssembleBlock(benchmark::Bench &bench)
static void BlockAssemblerAddPackageTxns(benchmark::Bench &bench)
const CScript SCRIPT_PUB
const CScript redeemScript
static void BlockAssemblerAddPackageTxnsPreconsensus(benchmark::Bench &bench)
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< CTxIn > vin
Serialized script, used inside transaction inputs and outputs.
Definition script.h:434
A reference to a CScript: the Hash160 of its serialization.
Definition script.h:564
Fast randomness source.
Definition random.h:411
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
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule).
Definition consensus.h:32
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:7
static CTransactionRef MakeTransactionRef()
std::shared_ptr< const CTransaction > CTransactionRef
@ OP_EQUAL
Definition script.h:125
@ OP_HASH160
Definition script.h:166
@ OP_TRUE
Definition script.h:63
@ OP_DROP
Definition script.h:103
@ OP_RETURN
Definition script.h:90
std::vector< uint8_t > ToByteVector(const T &in)
Definition script.h:48
static constexpr Amount zero() noexcept
Definition amount.h:36
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition validation.h:196
const ResultType m_result_type
Result type.
Definition validation.h:207
@ VALID
Fully validated, valid.
#define LOCK(cs)
Definition sync.h:295
assert(!tx.IsCoinBase())