Bitcoin Core
28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
bench
block_assemble.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-2022 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 <
consensus/validation.h
>
7
#include <
crypto/sha256.h
>
8
#include <
node/miner.h
>
9
#include <random.h>
10
#include <
test/util/mining.h
>
11
#include <
test/util/script.h
>
12
#include <
test/util/setup_common.h
>
13
#include <txmempool.h>
14
#include <
validation.h
>
15
16
17
#include <vector>
18
19
static
void
AssembleBlock
(
benchmark::Bench
& bench)
20
{
21
const
auto
test_setup =
MakeNoLogFileContext<const TestingSetup>
();
22
23
CScriptWitness
witness;
24
witness.
stack
.push_back(
WITNESS_STACK_ELEM_OP_TRUE
);
25
26
// Collect some loose transactions that spend the coinbases of our mined blocks
27
constexpr
size_t
NUM_BLOCKS{200};
28
std::array<
CTransactionRef
, NUM_BLOCKS -
COINBASE_MATURITY
+ 1> txs;
29
for
(
size_t
b{0}; b < NUM_BLOCKS; ++b) {
30
CMutableTransaction
tx;
31
tx.
vin
.emplace_back(
MineBlock
(test_setup->m_node,
P2WSH_OP_TRUE
));
32
tx.
vin
.back().scriptWitness = witness;
33
tx.
vout
.emplace_back(1337,
P2WSH_OP_TRUE
);
34
if
(NUM_BLOCKS - b >=
COINBASE_MATURITY
)
35
txs.at(b) =
MakeTransactionRef
(tx);
36
}
37
{
38
LOCK
(
::cs_main
);
39
40
for
(
const
auto
& txr : txs) {
41
const
MempoolAcceptResult
res = test_setup->m_node.chainman->ProcessTransaction(txr);
42
assert
(res.
m_result_type
==
MempoolAcceptResult::ResultType::VALID
);
43
}
44
}
45
46
bench.
run
([&] {
47
PrepareBlock
(test_setup->m_node,
P2WSH_OP_TRUE
);
48
});
49
}
50
static
void
BlockAssemblerAddPackageTxns
(
benchmark::Bench
& bench)
51
{
52
FastRandomContext
det_rand{
true
};
53
auto
testing_setup{
MakeNoLogFileContext<TestChain100Setup>
()};
54
testing_setup->PopulateMempool(det_rand,
/*num_transactions=*/
1000,
/*submit=*/
true
);
55
node::BlockAssembler::Options
assembler_options;
56
assembler_options.
test_block_validity
=
false
;
57
58
bench.
run
([&] {
59
PrepareBlock
(testing_setup->m_node,
P2WSH_OP_TRUE
, assembler_options);
60
});
61
}
62
63
BENCHMARK
(
AssembleBlock
,
benchmark::PriorityLevel::HIGH
);
64
BENCHMARK
(
BlockAssemblerAddPackageTxns
,
benchmark::PriorityLevel::LOW
);
bench.h
BENCHMARK
#define BENCHMARK(n, priority_level)
Definition
bench.h:79
AssembleBlock
static void AssembleBlock(benchmark::Bench &bench)
Definition
block_assemble.cpp:19
BlockAssemblerAddPackageTxns
static void BlockAssemblerAddPackageTxns(benchmark::Bench &bench)
Definition
block_assemble.cpp:50
FastRandomContext
Fast randomness source.
Definition
random.h:377
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
validation.h
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:19
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition
cs_main.cpp:8
miner.h
benchmark::HIGH
@ HIGH
Definition
bench.h:47
benchmark::LOW
@ LOW
Definition
bench.h:46
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition
transaction.h:424
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition
transaction.h:423
setup_common.h
MakeNoLogFileContext
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Definition
setup_common.h:230
sha256.h
CMutableTransaction
A mutable version of CTransaction.
Definition
transaction.h:378
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition
transaction.h:380
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition
transaction.h:379
CScriptWitness
Definition
script.h:574
CScriptWitness::stack
std::vector< std::vector< unsigned char > > stack
Definition
script.h:577
MempoolAcceptResult
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition
validation.h:128
MempoolAcceptResult::m_result_type
const ResultType m_result_type
Result type.
Definition
validation.h:137
MempoolAcceptResult::ResultType::VALID
@ VALID
node::BlockAssembler::Options
Definition
miner.h:161
node::BlockAssembler::Options::test_block_validity
bool test_block_validity
Definition
miner.h:166
LOCK
#define LOCK(cs)
Definition
sync.h:257
MineBlock
COutPoint MineBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey)
Returns the generated coin.
Definition
mining.cpp:63
PrepareBlock
std::shared_ptr< CBlock > PrepareBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey, const BlockAssembler::Options &assembler_options)
Definition
mining.cpp:111
mining.h
script.h
WITNESS_STACK_ELEM_OP_TRUE
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
Definition
script.h:11
P2WSH_OP_TRUE
static const CScript P2WSH_OP_TRUE
Definition
script.h:12
assert
assert(!tx.IsCoinBase())
validation.h
Generated on Thu Oct 3 2024 09:20:15 for Bitcoin Core by
1.12.0