Bitcoin Core
31.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 <chainparams.h>
8
#include <
common/args.h
>
9
#include <
consensus/validation.h
>
10
#include <
primitives/block.h
>
11
#include <
primitives/transaction.h
>
12
#include <
serialize.h
>
13
#include <
span.h
>
14
#include <
streams.h
>
15
#include <
util/chaintype.h
>
16
#include <
validation.h
>
17
18
#include <cassert>
19
#include <cstddef>
20
#include <memory>
21
#include <optional>
22
#include <vector>
23
24
// These are the two major time-sinks which happen after we have fully received
25
// a block off the wire, but before we can relay the block on to peers using
26
// compact block relay.
27
28
static
void
DeserializeBlockTest
(
benchmark::Bench
& bench)
29
{
30
DataStream
stream(benchmark::data::block413567);
31
std::byte a{0};
32
stream.
write
({&a, 1});
// Prevent compaction
33
34
bench.
unit
(
"block"
).
run
([&] {
35
CBlock
block;
36
stream >>
TX_WITH_WITNESS
(block);
37
bool
rewound = stream.
Rewind
(benchmark::data::block413567.size());
38
assert
(rewound);
39
});
40
}
41
42
static
void
DeserializeAndCheckBlockTest
(
benchmark::Bench
& bench)
43
{
44
DataStream
stream(benchmark::data::block413567);
45
std::byte a{0};
46
stream.
write
({&a, 1});
// Prevent compaction
47
48
ArgsManager
bench_args;
49
const
auto
chainParams =
CreateChainParams
(bench_args,
ChainType::MAIN
);
50
51
bench.
unit
(
"block"
).
run
([&] {
52
CBlock
block;
// Note that CBlock caches its checked state, so we need to recreate it here
53
stream >>
TX_WITH_WITNESS
(block);
54
bool
rewound = stream.
Rewind
(benchmark::data::block413567.size());
55
assert
(rewound);
56
57
BlockValidationState
validationState;
58
bool
checked =
CheckBlock
(block, validationState, chainParams->GetConsensus());
59
assert
(checked);
60
});
61
}
62
63
BENCHMARK
(
DeserializeBlockTest
);
64
BENCHMARK
(
DeserializeAndCheckBlockTest
);
args.h
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
block.h
CreateChainParams
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const ChainType chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
Definition
chainparams.cpp:117
chaintype.h
ChainType::MAIN
@ MAIN
Definition
chaintype.h:12
DeserializeAndCheckBlockTest
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
Definition
checkblock.cpp:42
DeserializeBlockTest
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition
checkblock.cpp:28
ArgsManager
Definition
args.h:103
BlockValidationState
Definition
validation.h:126
CBlock
Definition
block.h:74
DataStream
Double ended buffer combining vector and stream-like interfaces.
Definition
streams.h:133
DataStream::write
void write(std::span< const value_type > src)
Definition
streams.h:236
DataStream::Rewind
bool Rewind(std::optional< size_type > n=std::nullopt)
Definition
streams.h:183
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
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
validation.h
transaction.h
TX_WITH_WITNESS
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition
transaction.h:180
serialize.h
span.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:3966
assert
assert(!tx.IsCoinBase())
validation.h
Generated on
for Bitcoin Core by
1.17.0