Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
checkblock.cpp
Go to the documentation of this file.
1// Copyright (c) 2016 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 <config.h>
11#include <streams.h>
12#include <validation.h>
13
14// These are the two major time-sinks which happen after we have fully received
15// a block off the wire, but before we can relay the block on to peers using
16// compact block relay.
17
21 std::byte a{0};
22 // Prevent compaction
23 stream.write({&a, 1});
24
25 bench.unit("block").run([&] {
26 CBlock block;
27 stream >> block;
28 bool rewound = stream.Rewind(benchmark::data::block413567.size());
30 });
31}
32
36 std::byte a{0};
37 // Prevent compaction
38 stream.write({&a, 1});
39
40 const Config &config = GetConfig();
41 const Consensus::Params params = config.GetChainParams().GetConsensus();
42 BlockValidationOptions options(config);
43 bench.unit("block").run([&] {
44 // Note that CBlock caches its checked state, so we need to recreate it
45 // here.
46 CBlock block;
47 stream >> block;
48 bool rewound = stream.Rewind(benchmark::data::block413567.size());
50
52 bool checked = CheckBlock(block, validationState, params, options);
54 });
55}
56
#define BENCHMARK(n)
Definition bench.h:65
static void DeserializeAndCheckBlockTest(benchmark::Bench &bench)
static void DeserializeBlockTest(benchmark::Bench &bench)
Definition block.h:60
const Consensus::Params & GetConsensus() const
Definition chainparams.h:92
Double ended buffer combining vector and stream-like interfaces.
Definition streams.h:177
void write(Span< const value_type > src)
Definition streams.h:379
bool Rewind(std::optional< size_type > n=std::nullopt)
Definition streams.h:315
virtual const CChainParams & GetChainParams() const =0
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:616
const Config & GetConfig()
Definition config.cpp:40
const std::vector< uint8_t > block413567
Definition data.cpp:11
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
@ SER_NETWORK
Definition serialize.h:152
Parameters that influence chain consensus.
Definition params.h:34
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &params, BlockValidationOptions validationOptions)
Functions for validating blocks and updating the block tree.
assert(!tx.IsCoinBase())
static const int PROTOCOL_VERSION
network protocol versioning
Definition version.h:11