mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Includes a memory leak in the checkqueue unit test (but not in the actual code). WE really need to switch our checkqueue to use std::unique_pointer rather than bare pointers. But this would be invasive enough that I want to do it in a followup PR. Also pretty-much disable the validation_flush_cache unit test. This is a stupid and irritating test which tries to unit-test exact memory usage of std containers. It already has at least one "remove wrong assumptions" update upstream and after many tries I was unable to change all the magic numbers in a way that'd consistently pass CI for Elements. Also adds a couple ubsan suppressions about perfectly-legitimate conversions of integer types.
64 lines
2 KiB
C++
64 lines
2 KiB
C++
// Copyright (c) 2011-2019 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 <consensus/validation.h>
|
|
#include <crypto/sha256.h>
|
|
#include <test/util/mining.h>
|
|
#include <test/util/setup_common.h>
|
|
#include <test/util/wallet.h>
|
|
#include <txmempool.h>
|
|
#include <validation.h>
|
|
|
|
|
|
#include <vector>
|
|
|
|
static void AssembleBlock(benchmark::Bench& bench)
|
|
{
|
|
TestingSetup test_setup{
|
|
CBaseChainParams::REGTEST,
|
|
/* fedpegscript */ "",
|
|
/* extra_args */ {
|
|
"-nodebuglogfile",
|
|
"-nodebug",
|
|
},
|
|
};
|
|
|
|
const std::vector<unsigned char> op_true{OP_TRUE};
|
|
CScriptWitness witness;
|
|
witness.stack.push_back(op_true);
|
|
|
|
uint256 witness_program;
|
|
CSHA256().Write(&op_true[0], op_true.size()).Finalize(witness_program.begin());
|
|
|
|
const CScript SCRIPT_PUB{CScript(OP_0) << std::vector<unsigned char>{witness_program.begin(), witness_program.end()}};
|
|
|
|
// Collect some loose transactions that spend the coinbases of our mined blocks
|
|
constexpr size_t NUM_BLOCKS{200};
|
|
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
|
|
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
|
|
CMutableTransaction tx;
|
|
tx.vin.push_back(MineBlock(test_setup.m_node, SCRIPT_PUB));
|
|
tx.witness.vtxinwit.resize(1);
|
|
tx.witness.vtxinwit.back().scriptWitness = witness;
|
|
tx.vout.emplace_back(CTxOut(CAsset(), 1337, SCRIPT_PUB));
|
|
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
|
|
txs.at(b) = MakeTransactionRef(tx);
|
|
}
|
|
{
|
|
LOCK(::cs_main); // Required for ::AcceptToMemoryPool.
|
|
|
|
for (const auto& txr : txs) {
|
|
TxValidationState state;
|
|
bool ret{::AcceptToMemoryPool(*test_setup.m_node.mempool, state, txr, nullptr /* plTxnReplaced */, false /* bypass_limits */)};
|
|
assert(ret);
|
|
}
|
|
}
|
|
|
|
bench.run([&] {
|
|
PrepareBlock(test_setup.m_node, SCRIPT_PUB);
|
|
});
|
|
}
|
|
|
|
BENCHMARK(AssembleBlock);
|