diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index 4005701cae..00102aefe2 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -20,19 +20,23 @@ #include #include +using node::BlockAssembler; + static void AssembleBlock(benchmark::Bench& bench) { const auto test_setup = MakeNoLogFileContext(); CScriptWitness witness; witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE); + BlockAssembler::Options options; + options.coinbase_output_script = P2WSH_OP_TRUE; // 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.emplace_back(MineBlock(test_setup->m_node, P2WSH_OP_TRUE)); + tx.vin.emplace_back(MineBlock(test_setup->m_node, options)); tx.vin.back().scriptWitness = witness; tx.vout.emplace_back(1337, P2WSH_OP_TRUE); if (NUM_BLOCKS - b >= COINBASE_MATURITY) @@ -48,7 +52,7 @@ static void AssembleBlock(benchmark::Bench& bench) } bench.run([&] { - PrepareBlock(test_setup->m_node, P2WSH_OP_TRUE); + PrepareBlock(test_setup->m_node, options); }); } static void BlockAssemblerAddPackageTxns(benchmark::Bench& bench) @@ -56,11 +60,12 @@ static void BlockAssemblerAddPackageTxns(benchmark::Bench& bench) FastRandomContext det_rand{true}; auto testing_setup{MakeNoLogFileContext()}; testing_setup->PopulateMempool(det_rand, /*num_transactions=*/1000, /*submit=*/true); - node::BlockAssembler::Options assembler_options; + BlockAssembler::Options assembler_options; assembler_options.test_block_validity = false; + assembler_options.coinbase_output_script = P2WSH_OP_TRUE; bench.run([&] { - PrepareBlock(testing_setup->m_node, P2WSH_OP_TRUE, assembler_options); + PrepareBlock(testing_setup->m_node, assembler_options); }); } diff --git a/src/interfaces/mining.h b/src/interfaces/mining.h index 6f23bf3bb5..9c32e999a5 100644 --- a/src/interfaces/mining.h +++ b/src/interfaces/mining.h @@ -88,11 +88,10 @@ public: /** * Construct a new block template * - * @param[in] script_pub_key the coinbase output * @param[in] options options for creating the block * @returns a block template */ - virtual std::unique_ptr createNewBlock(const CScript& script_pub_key, const node::BlockCreateOptions& options = {}) = 0; + virtual std::unique_ptr createNewBlock(const node::BlockCreateOptions& options = {}) = 0; /** * Processes new block. A valid new block is automatically relayed to peers. diff --git a/src/ipc/capnp/mining.capnp b/src/ipc/capnp/mining.capnp index f8faaa0c42..5af37b725a 100644 --- a/src/ipc/capnp/mining.capnp +++ b/src/ipc/capnp/mining.capnp @@ -17,7 +17,7 @@ interface Mining $Proxy.wrap("interfaces::Mining") { isInitialBlockDownload @1 (context :Proxy.Context) -> (result: Bool); getTip @2 (context :Proxy.Context) -> (result: Common.BlockRef, hasResult: Bool); waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64) -> (result: Common.BlockRef); - createNewBlock @4 (scriptPubKey: Data, options: BlockCreateOptions) -> (result: BlockTemplate); + createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate); processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool); getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32); testBlockValidity @7 (context :Proxy.Context, block: Data, checkMerkleRoot: Bool) -> (state: BlockValidationState, result: Bool); diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index e4ae9400e3..45c9208727 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -1004,11 +1004,11 @@ public: return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root); } - std::unique_ptr createNewBlock(const CScript& script_pub_key, const BlockCreateOptions& options) override + std::unique_ptr createNewBlock(const BlockCreateOptions& options) override { BlockAssembler::Options assemble_options{options}; ApplyArgsManOptions(*Assert(m_node.args), assemble_options); - return std::make_unique(BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key), m_node); + return std::make_unique(BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(), m_node); } NodeContext* context() override { return &m_node; } diff --git a/src/node/miner.cpp b/src/node/miner.cpp index 790ee1c146..5d7304b597 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -106,7 +106,7 @@ void BlockAssembler::resetBlock() nFees = 0; } -std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn) +std::unique_ptr BlockAssembler::CreateNewBlock() { const auto time_start{SteadyClock::now()}; @@ -151,7 +151,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc coinbaseTx.vin.resize(1); coinbaseTx.vin[0].prevout.SetNull(); coinbaseTx.vout.resize(1); - coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; + coinbaseTx.vout[0].scriptPubKey = m_options.coinbase_output_script; coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx)); diff --git a/src/node/miner.h b/src/node/miner.h index 25ce110b34..f6461a8d55 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -169,8 +169,8 @@ public: explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options); - /** Construct a new block template with coinbase to scriptPubKeyIn */ - std::unique_ptr CreateNewBlock(const CScript& scriptPubKeyIn); + /** Construct a new block template */ + std::unique_ptr CreateNewBlock(); inline static std::optional m_last_block_num_txs{}; inline static std::optional m_last_block_weight{}; diff --git a/src/node/types.h b/src/node/types.h index 1302f1b127..2fc66b892b 100644 --- a/src/node/types.h +++ b/src/node/types.h @@ -3,8 +3,8 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. //! @file node/types.h is a home for public enum and struct type definitions -//! that are used by internally by node code, but also used externally by wallet -//! or GUI code. +//! that are used by internally by node code, but also used externally by wallet, +//! mining or GUI code. //! //! This file is intended to define only simple types that do not have external //! dependencies. More complicated types should be defined in dedicated header @@ -14,6 +14,7 @@ #define BITCOIN_NODE_TYPES_H #include +#include