mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
53 lines
1.7 KiB
C++
53 lines
1.7 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/bench.h>
|
|
#include <bench/data.h>
|
|
|
|
#include <chainparams.h>
|
|
#include <validation.h>
|
|
#include <streams.h>
|
|
#include <consensus/validation.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::Bench& bench)
|
|
{
|
|
CDataStream stream(benchmark::data::block813851, SER_NETWORK, PROTOCOL_VERSION);
|
|
char a = '\0';
|
|
stream.write(&a, 1); // Prevent compaction
|
|
|
|
bench.unit("block").run([&] {
|
|
CBlock block;
|
|
stream >> block;
|
|
bool rewound = stream.Rewind(benchmark::data::block813851.size());
|
|
assert(rewound);
|
|
});
|
|
}
|
|
|
|
static void DeserializeAndCheckBlockTest(benchmark::Bench& bench)
|
|
{
|
|
CDataStream stream(benchmark::data::block813851, SER_NETWORK, PROTOCOL_VERSION);
|
|
char a = '\0';
|
|
stream.write(&a, 1); // Prevent compaction
|
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
|
|
|
bench.unit("block").run([&] {
|
|
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
|
stream >> block;
|
|
bool rewound = stream.Rewind(benchmark::data::block813851.size());
|
|
assert(rewound);
|
|
|
|
CValidationState validationState;
|
|
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime());
|
|
assert(checked);
|
|
});
|
|
}
|
|
|
|
BENCHMARK(DeserializeBlockTest);
|
|
BENCHMARK(DeserializeAndCheckBlockTest);
|