Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
duplicate_inputs.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2019 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <bench/bench.h>
6#include <chain.h>
7#include <chainparams.h>
8#include <config.h>
9#include <consensus/amount.h>
10#include <consensus/merkle.h>
12#include <pow/pow.h>
13#include <random.h>
14#include <script/scriptcache.h>
15#include <test/util/setup_common.h>
16#include <txmempool.h>
17#include <validation.h>
18
20 const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
21
23
24 const Config &config = testing_setup->m_node.chainman->GetConfig();
25 const CChainParams &chainParams = config.GetChainParams();
26 const Consensus::Params &consensusParams = chainParams.GetConsensus();
27
28 CBlock block{};
31
34 testing_setup->m_node.chainman->ActiveChain().Tip();
35 assert(pindexPrev != nullptr);
36 block.nBits = GetNextWorkRequired(pindexPrev, &block, chainParams);
37 block.nNonce = 0;
38 auto nHeight = pindexPrev->nHeight + 1;
39
40 // Make a coinbase TX
41 coinbaseTx.vin.resize(1);
42 coinbaseTx.vin[0].prevout = COutPoint();
43 coinbaseTx.vout.resize(1);
44 coinbaseTx.vout[0].scriptPubKey = SCRIPT_PUB;
46 coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
47
48 naughtyTx.vout.resize(1);
49 naughtyTx.vout[0].nValue = Amount::zero();
50 naughtyTx.vout[0].scriptPubKey = SCRIPT_PUB;
51
54 for (uint64_t x = 0; x < (n_inputs - 1); ++x) {
55 naughtyTx.vin.emplace_back(TxId(GetRandHash()), 0, CScript(), 0);
56 }
57 naughtyTx.vin.emplace_back(naughtyTx.vin.back());
58
59 block.vtx.push_back(MakeTransactionRef(std::move(coinbaseTx)));
60 block.vtx.push_back(MakeTransactionRef(std::move(naughtyTx)));
61
62 block.hashMerkleRoot = BlockMerkleRoot(block);
63
64 bench.run([&] {
68 .withCheckPoW(false)
69 .withCheckMerkleRoot(false)));
70 assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate");
71 });
72}
73
#define BENCHMARK(n)
Definition bench.h:65
Definition block.h:60
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition blockindex.h:25
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition chainparams.h:80
const Consensus::Params & GetConsensus() const
Definition chainparams.h:92
A mutable version of CTransaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:20
Serialized script, used inside transaction inputs and outputs.
Definition script.h:431
The basic transaction that is broadcasted on the network and contained in blocks.
unsigned int GetTotalSize() const
Get the total transaction size in bytes.
virtual const CChainParams & GetChainParams() const =0
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:616
void resize(size_type new_size)
Definition prevector.h:424
static const uint64_t MAX_TX_SIZE
The maximum allowed size for a transaction, in bytes.
Definition consensus.h:14
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:7
static void DuplicateInputs(benchmark::Bench &bench)
unsigned int nHeight
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
Compute the Merkle root of the transactions in a block.
Definition merkle.cpp:69
uint32_t GetNextWorkRequired(const CBlockIndex *pindexPrev, const CBlockHeader *pblock, const CChainParams &chainParams)
Definition pow.cpp:21
static CTransactionRef MakeTransactionRef()
uint256 GetRandHash() noexcept
Definition random.cpp:659
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
@ OP_TRUE
Definition script.h:57
@ OP_0
Definition script.h:49
static constexpr Amount zero() noexcept
Definition amount.h:32
Parameters that influence chain consensus.
Definition params.h:34
A TxId is the identifier of a transaction.
Definition txid.h:14
#define LOCK(cs)
Definition sync.h:306
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &params, BlockValidationOptions validationOptions)
Functions for validating blocks and updating the block tree.
assert(!tx.IsCoinBase())