Skip to content

Commit

Permalink
interfaces/mining: Add createNewBlock2 that does not override or lose…
Browse files Browse the repository at this point in the history
… options
  • Loading branch information
luke-jr committed Jan 31, 2025
1 parent 4553884 commit 17e4942
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/interfaces/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef BITCOIN_INTERFACES_MINING_H
#define BITCOIN_INTERFACES_MINING_H

#include <node/miner.h>
#include <node/types.h>
#include <uint256.h>

Expand Down Expand Up @@ -40,13 +41,14 @@ class Mining
virtual std::optional<uint256> getTipHash() = 0;

/**
* Construct a new block template
* Construct a new block template. For the createNewBlock variant, subclass options (if any) are silently lost and overridden by any config args. For createNewBlock2, the options are assumed to be complete.
*
* @param[in] script_pub_key the coinbase output
* @param[in] options options for creating the block
* @returns a block template
*/
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, const node::BlockCreateOptions& options={}) = 0;
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock2(const CScript& script_pub_key, const node::BlockAssembler::Options& assemble_options) = 0;

/**
* Processes new block. A valid new block is automatically relayed to peers.
Expand Down
5 changes: 5 additions & 0 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@ class MinerImpl : public Mining
{
BlockAssembler::Options assemble_options{options};
ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
return createNewBlock2(script_pub_key, assemble_options);
}

std::unique_ptr<CBlockTemplate> createNewBlock2(const CScript& script_pub_key, const BlockAssembler::Options& assemble_options) override
{
return BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key);
}

Expand Down

0 comments on commit 17e4942

Please sign in to comment.