Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing bench/checkblock.cpp benchmark test (#722) #788

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BENCH_SRCDIR = bench
BENCH_BINARY = bench/bench_unite$(EXEEXT)

RAW_BENCH_FILES = \
bench/data/block413567.raw
bench/data/test_block.raw
GENERATED_BENCH_FILES = $(RAW_BENCH_FILES:.raw=.raw.h)

bench_bench_unite_SOURCES = \
Expand Down Expand Up @@ -70,7 +70,7 @@ CLEAN_UNITE_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)

CLEANFILES += $(CLEAN_UNITE_BENCH)

bench/checkblock.cpp: bench/data/block413567.raw.h
bench/checkblock.cpp: bench/data/test_block.raw.h

unite_bench: $(BENCH_BINARY)

Expand Down
17 changes: 9 additions & 8 deletions src/bench/checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <consensus/validation.h>

namespace block_bench {
#include <bench/data/block413567.raw.h>
#include <bench/data/test_block.raw.h>
} // namespace block_bench

// These are the two major time-sinks which happen after we have fully received
Expand All @@ -19,33 +19,34 @@ namespace block_bench {

static void DeserializeBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)block_bench::block413567,
(const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
CDataStream stream((const char*)block_bench::test_block,
(const char*)&block_bench::test_block[sizeof(block_bench::test_block)],
SER_NETWORK, PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction

while (state.KeepRunning()) {
CBlock block;
stream >> block;
assert(stream.Rewind(sizeof(block_bench::block413567)));
assert(stream.Rewind(sizeof(block_bench::test_block)));
}
}

static void DeserializeAndCheckBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)block_bench::block413567,
(const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
// UNIT-E TODO: This is a synthetic block, it makes sense to change it to a real block later on.
CDataStream stream((const char*)block_bench::test_block,
(const char*)&block_bench::test_block[sizeof(block_bench::test_block)],
SER_NETWORK, PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction

const auto chainParams = CreateChainParams(CBaseChainParams::TESTNET);
const auto chainParams = CreateChainParams(CBaseChainParams::REGTEST);

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(block_bench::block413567)));
assert(stream.Rewind(sizeof(block_bench::test_block)));

CValidationState validationState;
assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
Expand Down
Binary file added src/bench/data/test_block.raw
Binary file not shown.