Bitcoin ABC
0.30.5
P2P Digital Currency
src
bench
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
auto
test_setup = MakeNoLogFileContext<const TestingSetup>();
19
const
Config
&config = test_setup->m_node.chainman->GetConfig();
20
21
const
CScript redeemScript = CScript() <<
OP_DROP
<<
OP_TRUE
;
22
const
CScript SCRIPT_PUB =
23
CScript() <<
OP_HASH160
<<
ToByteVector
(
CScriptID
(redeemScript))
24
<<
OP_EQUAL
;
25
26
const
CScript scriptSig = CScript() << std::vector<uint8_t>(100, 0xff)
27
<<
ToByteVector
(redeemScript);
28
29
// Collect some loose transactions that spend the coinbases of our mined
30
// blocks
31
constexpr
size_t
NUM_BLOCKS{200};
32
std::array<
CTransactionRef
, NUM_BLOCKS -
COINBASE_MATURITY
+ 1> txs;
33
for
(
size_t
b = 0; b < NUM_BLOCKS; ++b) {
34
CMutableTransaction
tx;
35
tx.
vin
.push_back(MineBlock(config, test_setup->m_node, SCRIPT_PUB));
36
tx.
vin
.back().scriptSig = scriptSig;
37
tx.
vout
.emplace_back(1337 *
SATOSHI
, SCRIPT_PUB);
38
if
(NUM_BLOCKS - b >=
COINBASE_MATURITY
) {
39
txs.at(b) =
MakeTransactionRef
(tx);
40
}
41
}
42
43
{
44
LOCK
(
::cs_main
);
45
46
for
(
const
auto
&txr : txs) {
47
const
MempoolAcceptResult
res =
48
test_setup->m_node.chainman->ProcessTransaction(txr);
49
assert
(res.
m_result_type
==
MempoolAcceptResult::ResultType::VALID
);
50
}
51
}
52
53
bench.
run
([&] { PrepareBlock(config, test_setup->m_node, SCRIPT_PUB); });
54
}
55
56
BENCHMARK
(
AssembleBlock
);
SATOSHI
static constexpr Amount SATOSHI
Definition:
amount.h:143
bench.h
AssembleBlock
static void AssembleBlock(benchmark::Bench &bench)
Definition:
block_assemble.cpp:17
BENCHMARK
BENCHMARK(AssembleBlock)
CMutableTransaction
A mutable version of CTransaction.
Definition:
transaction.h:274
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition:
transaction.h:277
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition:
transaction.h:276
CScriptID
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition:
standard.h:24
Config
Definition:
config.h:19
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition:
nanobench.h:616
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition:
nanobench.h:1183
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:32
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition:
cs_main.cpp:7
MakeTransactionRef
static CTransactionRef MakeTransactionRef()
Definition:
transaction.h:316
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition:
transaction.h:315
OP_EQUAL
@ OP_EQUAL
Definition:
script.h:119
OP_HASH160
@ OP_HASH160
Definition:
script.h:160
OP_TRUE
@ OP_TRUE
Definition:
script.h:57
OP_DROP
@ OP_DROP
Definition:
script.h:97
ToByteVector
std::vector< uint8_t > ToByteVector(const T &in)
Definition:
script.h:42
standard.h
MempoolAcceptResult
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition:
validation.h:207
MempoolAcceptResult::m_result_type
const ResultType m_result_type
Result type.
Definition:
validation.h:218
MempoolAcceptResult::ResultType::VALID
@ VALID
Fully validated, valid.
LOCK
#define LOCK(cs)
Definition:
sync.h:306
txmempool.h
assert
assert(!tx.IsCoinBase())
validation.h
Generated on Wed Nov 20 2024 17:55:57 for Bitcoin ABC by
1.9.4