mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-05 10:17:30 -05:00
2f6a8e5e02
04528054fc
[bench] BlockAssembler with mempool packages (glozow)6ce265acf4
[test util] lock cs_main before pool.cs in PopulateMempool (glozow)8791410662
[test util] randomize fee in PopulateMempool (glozow)cba5934eb6
[miner] allow bypassing TestBlockValidity (glozow)c058852308
[refactor] parameterize BlockAssembler::Options in PrepareBlock (glozow)a2de971ba1
[refactor] add helper to apply ArgsManager to BlockAssembler::Options (glozow) Pull request description: Performance of block template building matters as miners likely want to be able to start mining on a block with transactions asap after a block is found. We would want to know if a mempool PR accidentally caused, for example, a 100x slowdown. An `AssembleBlock()` bench exists, but it operates on a mempool with 101 transactions, each with 0 ancestors or descendants and with the same fee. Adding a bench with a more complex mempool is useful because (1) it's more realistic (2) updating packages can potentially cause the algorithm to take a long time. ACKs for top commit: kevkevinpal: Tested ACK [0452805
](04528054fc
) achow101: ACK04528054fc
stickies-v: ACK04528054f
Tree-SHA512: 38c138d6a75616651f9b1faf4e3a1cd833437a486f4e84308fbee958e8462bb570582c88f7ba7ab99d80191e97855ac2cf27c43cc21585d3e4b0e227effe2fb5
63 lines
2.1 KiB
C++
63 lines
2.1 KiB
C++
// Copyright (c) 2011-2022 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 <node/miner.h>
|
|
#include <test/util/mining.h>
|
|
#include <test/util/script.h>
|
|
#include <test/util/setup_common.h>
|
|
#include <txmempool.h>
|
|
#include <validation.h>
|
|
|
|
|
|
#include <vector>
|
|
|
|
static void AssembleBlock(benchmark::Bench& bench)
|
|
{
|
|
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
|
|
|
CScriptWitness witness;
|
|
witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE);
|
|
|
|
// 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, P2WSH_OP_TRUE));
|
|
tx.vin.back().scriptWitness = witness;
|
|
tx.vout.emplace_back(1337, P2WSH_OP_TRUE);
|
|
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
|
|
txs.at(b) = MakeTransactionRef(tx);
|
|
}
|
|
{
|
|
LOCK(::cs_main);
|
|
|
|
for (const auto& txr : txs) {
|
|
const MempoolAcceptResult res = test_setup->m_node.chainman->ProcessTransaction(txr);
|
|
assert(res.m_result_type == MempoolAcceptResult::ResultType::VALID);
|
|
}
|
|
}
|
|
|
|
bench.run([&] {
|
|
PrepareBlock(test_setup->m_node, P2WSH_OP_TRUE);
|
|
});
|
|
}
|
|
static void BlockAssemblerAddPackageTxns(benchmark::Bench& bench)
|
|
{
|
|
FastRandomContext det_rand{true};
|
|
auto testing_setup{MakeNoLogFileContext<TestChain100Setup>()};
|
|
testing_setup->PopulateMempool(det_rand, /*num_transactions=*/1000, /*submit=*/true);
|
|
node::BlockAssembler::Options assembler_options;
|
|
assembler_options.test_block_validity = false;
|
|
|
|
bench.run([&] {
|
|
PrepareBlock(testing_setup->m_node, P2WSH_OP_TRUE, assembler_options);
|
|
});
|
|
}
|
|
|
|
BENCHMARK(AssembleBlock, benchmark::PriorityLevel::HIGH);
|
|
BENCHMARK(BlockAssemblerAddPackageTxns, benchmark::PriorityLevel::LOW);
|