neobytes/src/bench/checkblock.cpp
Alexander Block 99b2789a73 Fix DeserializeAndCheckBlockTest benchmark and store hashDevnetGenesisBlock in consensus (#1888)
* Use Dash block for DeserializeAndCheckBlockTest

Replaced Bitcoin block with the largest Dash block I could find on mainnet.

* Store hashDevnetGenesisBlock in Consensus::Params

Remove the need for chainparams to be available when the devnetGenesis hash
is needed. Fixes a crash in CheckBlockHeader() when called from benchmarking
code, which does not initialize the Params() function.
2018-02-01 20:05:35 +03:00

55 lines
1.8 KiB
C++

// Copyright (c) 2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "bench.h"
#include "chainparams.h"
#include "validation.h"
#include "streams.h"
#include "consensus/validation.h"
#include "bench/data/block813851.raw.h"
// These are the two major time-sinks which happen after we have fully received
// a block off the wire, but before we can relay the block on to peers using
// compact block relay.
static void DeserializeBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)raw_bench::block813851,
(const char*)&raw_bench::block813851[sizeof(raw_bench::block813851)],
SER_NETWORK, PROTOCOL_VERSION);
char a;
stream.write(&a, 1); // Prevent compaction
while (state.KeepRunning()) {
CBlock block;
stream >> block;
assert(stream.Rewind(sizeof(raw_bench::block813851)));
}
}
static void DeserializeAndCheckBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)raw_bench::block813851,
(const char*)&raw_bench::block813851[sizeof(raw_bench::block813851)],
SER_NETWORK, PROTOCOL_VERSION);
char a;
stream.write(&a, 1); // Prevent compaction
Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus();
while (state.KeepRunning()) {
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
stream >> block;
assert(stream.Rewind(sizeof(raw_bench::block813851)));
CValidationState validationState;
assert(CheckBlock(block, validationState, params, block.GetBlockTime()));
}
}
BENCHMARK(DeserializeBlockTest);
BENCHMARK(DeserializeAndCheckBlockTest);