2023-08-16 19:27:31 +02:00
|
|
|
// Copyright (c) 2011-2020 The Bitcoin Core developers
|
2021-10-25 09:38:17 +02:00
|
|
|
// 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 <chainparams.h>
|
|
|
|
#include <consensus/merkle.h>
|
|
|
|
#include <consensus/validation.h>
|
|
|
|
#include <policy/policy.h>
|
|
|
|
#include <pow.h>
|
2020-04-09 17:47:32 +02:00
|
|
|
#include <test/util/setup_common.h>
|
2021-10-25 09:38:17 +02:00
|
|
|
#include <txmempool.h>
|
|
|
|
#include <validation.h>
|
|
|
|
|
|
|
|
|
|
|
|
static void DuplicateInputs(benchmark::Bench& bench)
|
|
|
|
{
|
2020-04-09 17:47:32 +02:00
|
|
|
RegTestingSetup test_setup;
|
|
|
|
|
2021-10-25 09:38:17 +02:00
|
|
|
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
|
|
|
|
|
|
|
|
const CChainParams& chainparams = Params();
|
|
|
|
|
|
|
|
CBlock block{};
|
|
|
|
CMutableTransaction coinbaseTx{};
|
|
|
|
CMutableTransaction naughtyTx{};
|
|
|
|
|
2023-07-30 13:56:33 +02:00
|
|
|
assert(std::addressof(::ChainActive()) == std::addressof(test_setup.m_node.chainman->ActiveChain()));
|
|
|
|
CBlockIndex* pindexPrev = test_setup.m_node.chainman->ActiveChain().Tip();
|
2021-10-25 09:38:17 +02:00
|
|
|
assert(pindexPrev != nullptr);
|
|
|
|
block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus());
|
|
|
|
block.nNonce = 0;
|
|
|
|
auto nHeight = pindexPrev->nHeight + 1;
|
|
|
|
|
|
|
|
// Make a coinbase TX
|
|
|
|
coinbaseTx.vin.resize(1);
|
|
|
|
coinbaseTx.vin[0].prevout.SetNull();
|
|
|
|
coinbaseTx.vout.resize(1);
|
|
|
|
coinbaseTx.vout[0].scriptPubKey = SCRIPT_PUB;
|
2023-10-17 22:50:23 +02:00
|
|
|
coinbaseTx.vout[0].nValue = GetBlockSubsidyInner(block.nBits, nHeight, chainparams.GetConsensus(), /*fV20Active=*/ false, /*fMNRewardReallocated=*/ false);
|
2021-10-25 09:38:17 +02:00
|
|
|
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
|
|
|
|
|
|
|
naughtyTx.vout.resize(1);
|
|
|
|
naughtyTx.vout[0].nValue = 0;
|
|
|
|
naughtyTx.vout[0].scriptPubKey = SCRIPT_PUB;
|
|
|
|
|
2018-09-11 09:09:57 +02:00
|
|
|
uint64_t n_inputs = (((MaxBlockSize() / ::GetSerializeSize(CTransaction(), PROTOCOL_VERSION)) - (CTransaction(coinbaseTx).GetTotalSize() + CTransaction(naughtyTx).GetTotalSize())) / 41) - 100;
|
2021-10-25 09:38:17 +02:00
|
|
|
for (uint64_t x = 0; x < (n_inputs - 1); ++x) {
|
|
|
|
naughtyTx.vin.emplace_back(GetRandHash(), 0, CScript(), 0);
|
|
|
|
}
|
|
|
|
naughtyTx.vin.emplace_back(naughtyTx.vin.back());
|
|
|
|
|
|
|
|
block.vtx.push_back(MakeTransactionRef(std::move(coinbaseTx)));
|
|
|
|
block.vtx.push_back(MakeTransactionRef(std::move(naughtyTx)));
|
|
|
|
|
|
|
|
block.hashMerkleRoot = BlockMerkleRoot(block);
|
|
|
|
|
|
|
|
bench.minEpochIterations(10).run([&] {
|
2019-10-30 15:27:22 +01:00
|
|
|
BlockValidationState cvstate{};
|
2021-10-25 09:38:17 +02:00
|
|
|
assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), false, false));
|
|
|
|
assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(DuplicateInputs);
|