Changeset View
Changeset View
Standalone View
Standalone View
src/bench/duplicate_inputs.cpp
// Copyright (c) 2011-2019 The Bitcoin Core developers | // Copyright (c) 2011-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/merkle.h> | #include <consensus/merkle.h> | ||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <miner.h> | #include <miner.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <pow.h> | #include <pow.h> | ||||
#include <scheduler.h> | |||||
#include <script/scriptcache.h> | #include <script/scriptcache.h> | ||||
#include <txdb.h> | |||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <util/time.h> | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <boost/thread.hpp> | |||||
#include <list> | #include <list> | ||||
#include <vector> | #include <vector> | ||||
static void DuplicateInputs(benchmark::State &state) { | static void DuplicateInputs(benchmark::State &state) { | ||||
const CScript SCRIPT_PUB{CScript(OP_TRUE)}; | const CScript SCRIPT_PUB{CScript(OP_TRUE)}; | ||||
// Switch to regtest so we can mine faster | const CChainParams &chainparams = Params(); | ||||
SelectParams(CBaseChainParams::REGTEST); | |||||
const Config &config = GetConfig(); | |||||
InitScriptExecutionCache(); | |||||
boost::thread_group thread_group; | |||||
CScheduler scheduler; | |||||
const CChainParams &chainparams = config.GetChainParams(); | |||||
{ | |||||
LOCK(cs_main); | |||||
::pblocktree.reset(new CBlockTreeDB(1 << 20, true)); | |||||
::pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true)); | |||||
::pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get())); | |||||
} | |||||
{ | |||||
thread_group.create_thread( | |||||
std::bind(&CScheduler::serviceQueue, &scheduler)); | |||||
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); | |||||
LoadGenesisBlock(chainparams); | |||||
CValidationState cvstate; | |||||
ActivateBestChain(config, cvstate); | |||||
assert(::ChainActive().Tip() != nullptr); | |||||
} | |||||
CBlock block{}; | CBlock block{}; | ||||
CMutableTransaction coinbaseTx{}; | CMutableTransaction coinbaseTx{}; | ||||
CMutableTransaction naughtyTx{}; | CMutableTransaction naughtyTx{}; | ||||
CBlockIndex *pindexPrev = ::ChainActive().Tip(); | CBlockIndex *pindexPrev = ::ChainActive().Tip(); | ||||
assert(pindexPrev != nullptr); | assert(pindexPrev != nullptr); | ||||
block.nBits = | block.nBits = | ||||
Show All 24 Lines | static void DuplicateInputs(benchmark::State &state) { | ||||
block.vtx.push_back(MakeTransactionRef(std::move(coinbaseTx))); | block.vtx.push_back(MakeTransactionRef(std::move(coinbaseTx))); | ||||
block.vtx.push_back(MakeTransactionRef(std::move(naughtyTx))); | block.vtx.push_back(MakeTransactionRef(std::move(naughtyTx))); | ||||
block.hashMerkleRoot = BlockMerkleRoot(block); | block.hashMerkleRoot = BlockMerkleRoot(block); | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
CValidationState cvstate{}; | CValidationState cvstate{}; | ||||
assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), | assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), | ||||
BlockValidationOptions(config) | BlockValidationOptions(GetConfig()) | ||||
.withCheckPoW(false) | .withCheckPoW(false) | ||||
.withCheckMerkleRoot(false))); | .withCheckMerkleRoot(false))); | ||||
assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate"); | assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate"); | ||||
} | } | ||||
thread_group.interrupt_all(); | |||||
thread_group.join_all(); | |||||
GetMainSignals().FlushBackgroundCallbacks(); | |||||
GetMainSignals().UnregisterBackgroundSignalScheduler(); | |||||
} | } | ||||
BENCHMARK(DuplicateInputs, 10); | BENCHMARK(DuplicateInputs, 10); |