// 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 #include #include #include #include #include #include #include static void AssembleBlock(benchmark::State& state) { const std::vector 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{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 txs; for (size_t b{0}; b < NUM_BLOCKS; ++b) { CMutableTransaction tx; tx.vin.push_back(MineBlock(SCRIPT_PUB)); tx.vin.back().scriptWitness = witness; tx.vout.emplace_back(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) { CValidationState state; bool ret{::AcceptToMemoryPool(::mempool, state, txr, nullptr /* pfMissingInputs */, nullptr /* plTxnReplaced */, false /* bypass_limits */, /* nAbsurdFee */ 0)}; assert(ret); } } while (state.KeepRunning()) { PrepareBlock(SCRIPT_PUB); } } BENCHMARK(AssembleBlock, 700);