2019-12-30 06:39:22 -03:00
|
|
|
// Copyright (c) 2016-2019 The Bitcoin Core developers
|
2016-06-01 04:39:56 -04:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <bench/bench.h>
|
2019-07-01 16:42:22 -04:00
|
|
|
#include <bench/data.h>
|
2016-06-01 04:39:56 -04:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <chainparams.h>
|
|
|
|
#include <consensus/validation.h>
|
2020-04-16 13:11:54 -04:00
|
|
|
#include <streams.h>
|
|
|
|
#include <validation.h>
|
2016-06-01 04:39:56 -04:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2019-07-01 16:42:22 -04:00
|
|
|
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
|
2017-03-08 12:40:12 -03:00
|
|
|
char a = '\0';
|
2016-06-01 04:39:56 -04:00
|
|
|
stream.write(&a, 1); // Prevent compaction
|
|
|
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
CBlock block;
|
|
|
|
stream >> block;
|
2019-07-01 16:42:22 -04:00
|
|
|
bool rewound = stream.Rewind(benchmark::data::block413567.size());
|
2018-06-26 11:19:31 -04:00
|
|
|
assert(rewound);
|
2016-06-01 04:39:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DeserializeAndCheckBlockTest(benchmark::State& state)
|
|
|
|
{
|
2019-07-01 16:42:22 -04:00
|
|
|
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
|
2017-03-08 12:40:12 -03:00
|
|
|
char a = '\0';
|
2016-06-01 04:39:56 -04:00
|
|
|
stream.write(&a, 1); // Prevent compaction
|
|
|
|
|
2015-11-28 11:04:35 -03:00
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
2016-06-01 04:39:56 -04:00
|
|
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
|
|
|
stream >> block;
|
2019-07-01 16:42:22 -04:00
|
|
|
bool rewound = stream.Rewind(benchmark::data::block413567.size());
|
2018-06-26 11:19:31 -04:00
|
|
|
assert(rewound);
|
2016-06-01 04:39:56 -04:00
|
|
|
|
2019-10-24 12:35:42 -03:00
|
|
|
BlockValidationState validationState;
|
2018-06-26 11:19:31 -04:00
|
|
|
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
|
|
|
|
assert(checked);
|
2016-06-01 04:39:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 11:48:02 -03:00
|
|
|
BENCHMARK(DeserializeBlockTest, 130);
|
|
|
|
BENCHMARK(DeserializeAndCheckBlockTest, 160);
|