diff --git a/src/interfaces/mining.h b/src/interfaces/mining.h index 3b880eaf3ddb4..ae22342bc52e2 100644 --- a/src/interfaces/mining.h +++ b/src/interfaces/mining.h @@ -101,11 +101,10 @@ class Mining /** * 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 39296083beb63..84564617acb49 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 20abb6ef0e96a..1d0693dab3acb 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -871,7 +871,7 @@ class ChainImpl : public Chain class BlockTemplateImpl : public BlockTemplate { public: - explicit BlockTemplateImpl(CScript script_pub_key, BlockAssembler::Options assemble_options, std::unique_ptr block_template, NodeContext& node) : m_script_pub_key(script_pub_key), m_assemble_options(std::move(assemble_options)), m_block_template(std::move(block_template)), m_node(node) + explicit BlockTemplateImpl(BlockAssembler::Options assemble_options, std::unique_ptr block_template, NodeContext& node) : m_assemble_options(std::move(assemble_options)), m_block_template(std::move(block_template)), m_node(node) { assert(m_block_template); } @@ -977,7 +977,7 @@ class BlockTemplateImpl : public BlockTemplate * We'll also create a new template if the tip changed during the last tick. */ if (fee_threshold < MAX_MONEY || tip_changed) { - auto block_template{std::make_unique(m_script_pub_key, m_assemble_options, BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), m_assemble_options}.CreateNewBlock(m_script_pub_key), m_node)}; + auto block_template{std::make_unique(m_assemble_options, BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), m_assemble_options}.CreateNewBlock(), m_node)}; // If the tip changed, return the new template regardless of its fees. if (block_template->m_block_template->block.hashPrevBlock != m_block_template->block.hashPrevBlock) { @@ -1009,7 +1009,6 @@ class BlockTemplateImpl : public BlockTemplate return nullptr; } - const CScript m_script_pub_key; const BlockAssembler::Options m_assemble_options; const std::unique_ptr m_block_template; @@ -1083,11 +1082,11 @@ class MinerImpl : public Mining 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(script_pub_key, assemble_options, BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key), m_node); + return std::make_unique(assemble_options, 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 790ee1c146653..5d7304b597ea3 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 25ce110b34886..6b6079fa6ef2c 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -169,14 +169,22 @@ class BlockAssembler 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(); + + /** Temporary overload for tests */ + std::unique_ptr CreateNewBlock(const CScript& scriptPubKeyIn) + { + m_options.coinbase_output_script = scriptPubKeyIn; + return CreateNewBlock(); + }; inline static std::optional m_last_block_num_txs{}; inline static std::optional m_last_block_weight{}; private: - const Options m_options; + // TODO: make const again + Options m_options; // utility functions /** Clear the block's state and prepare for assembling a new block */ diff --git a/src/node/types.h b/src/node/types.h index 1302f1b127fa6..2fc66b892b53a 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