Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
checkblock.cpp
Go to the documentation of this file.
1// Copyright (c) 2016-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 <bench/data.h>
7
8#include <chainparams.h>
9#include <common/args.h>
11#include <streams.h>
12#include <util/chaintype.h>
13#include <validation.h>
14
15// These are the two major time-sinks which happen after we have fully received
16// a block off the wire, but before we can relay the block on to peers using
17// compact block relay.
18
20{
22 std::byte a{0};
23 stream.write({&a, 1}); // Prevent compaction
24
25 bench.unit("block").run([&] {
26 CBlock block;
27 stream >> TX_WITH_WITNESS(block);
28 bool rewound = stream.Rewind(benchmark::data::block413567.size());
29 assert(rewound);
30 });
31}
32
34{
36 std::byte a{0};
37 stream.write({&a, 1}); // Prevent compaction
38
39 ArgsManager bench_args;
40 const auto chainParams = CreateChainParams(bench_args, ChainType::MAIN);
41
42 bench.unit("block").run([&] {
43 CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
44 stream >> TX_WITH_WITNESS(block);
45 bool rewound = stream.Rewind(benchmark::data::block413567.size());
46 assert(rewound);
47
48 BlockValidationState validationState;
49 bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
50 assert(checked);
51 });
52}
53
#define BENCHMARK(n, priority_level)
Definition bench.h:79
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const ChainType chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition block.h:69
Double ended buffer combining vector and stream-like interfaces.
Definition streams.h:147
void write(Span< const value_type > src)
Definition streams.h:251
bool Rewind(std::optional< size_type > n=std::nullopt)
Definition streams.h:197
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition nanobench.h:1234
Bench & unit(char const *unit)
Sets the operation unit.
const std::vector< uint8_t > block413567
Definition data.cpp:11
@ HIGH
Definition bench.h:47
static constexpr TransactionSerParams TX_WITH_WITNESS
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
assert(!tx.IsCoinBase())