Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
checkblock.cpp
Go to the documentation of this file.
1
// Copyright (c) 2016-present 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 <bench/data/block413567.raw.h>
7
#include <
consensus/validation.h
>
8
#include <
kernel/chainparams.h
>
9
#include <
primitives/block.h
>
10
#include <
primitives/transaction.h
>
11
#include <
serialize.h
>
12
#include <
streams.h
>
13
#include <
util/check.h
>
14
#include <
validation.h
>
15
16
#include <memory>
17
#include <span>
18
#include <vector>
19
20
// These are the two major time-sinks which happen after we have fully received
21
// a block off the wire, but before we can relay the block on to peers using
22
// compact block relay.
23
24
static
void
DeserializeBlockTest
(
benchmark::Bench
& bench)
25
{
26
const
auto
block_data{benchmark::data::block413567};
27
bench.
unit
(
"block"
).
run
([&] {
28
CBlock
block;
29
SpanReader
{block_data} >>
TX_WITH_WITNESS
(block);
30
assert
(block.
vtx
.size() == 1557);
31
});
32
}
33
34
static
void
CheckBlockTest
(
benchmark::Bench
& bench)
35
{
36
const
auto
& chain_params{
CChainParams::Main
()};
37
const
auto
block_data{benchmark::data::block413567};
38
39
CBlock
block;
40
bench.
unit
(
"block"
)
41
.
setup
([&] {
42
block =
CBlock
{};
43
SpanReader
{block_data} >>
TX_WITH_WITNESS
(block);
44
assert
(block.
vtx
.size() == 1557);
45
})
46
.run([&] {
47
BlockValidationState
validationState;
48
const
bool
checked{
CheckBlock
(block, validationState, chain_params->GetConsensus())};
49
assert
(checked);
50
});
51
}
52
53
BENCHMARK
(
DeserializeBlockTest
);
54
BENCHMARK
(
CheckBlockTest
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:69
block.h
check.h
CheckBlockTest
static void CheckBlockTest(benchmark::Bench &bench)
Definition
checkblock.cpp:34
DeserializeBlockTest
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition
checkblock.cpp:24
BlockValidationState
Definition
validation.h:133
CBlock
Definition
block.h:74
CBlock::vtx
std::vector< CTransactionRef > vtx
Definition
block.h:77
CChainParams::Main
static std::unique_ptr< const CChainParams > Main()
Definition
chainparams.h:175
SpanReader
Minimal stream for reading from an existing byte array by std::span.
Definition
streams.h:83
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1308
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
ankerl::nanobench::Bench::setup
detail::SetupRunner< SetupOp > setup(SetupOp setupOp)
Configure an untimed setup step per epoch (forces single-iteration epochs).
Definition
nanobench.h:1302
validation.h
chainparams.h
transaction.h
TX_WITH_WITNESS
constexpr TransactionSerParams TX_WITH_WITNESS
Definition
transaction.h:181
serialize.h
streams.h
CheckBlock
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
Definition
validation.cpp:3926
assert
assert(!tx.IsCoinBase())
validation.h
Generated on
for Bitcoin Core by
1.18.0