mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-27 20:42:33 +02:00
refactor: pass BlockCreateOptions to createNewBlock
Rather than pass options individually to createNewBlock and then combining them into BlockAssembler::Options, this commit introduces BlockCreateOptions and passes that instead. Currently there's only one option (use_mempool) but the next commit adds more. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
parent
323cfed595
commit
6b4c817d4b
@ -5,9 +5,11 @@
|
|||||||
#ifndef BITCOIN_INTERFACES_MINING_H
|
#ifndef BITCOIN_INTERFACES_MINING_H
|
||||||
#define BITCOIN_INTERFACES_MINING_H
|
#define BITCOIN_INTERFACES_MINING_H
|
||||||
|
|
||||||
|
#include <node/types.h>
|
||||||
|
#include <uint256.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <uint256.h>
|
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
struct CBlockTemplate;
|
struct CBlockTemplate;
|
||||||
@ -41,10 +43,10 @@ public:
|
|||||||
* Construct a new block template
|
* Construct a new block template
|
||||||
*
|
*
|
||||||
* @param[in] script_pub_key the coinbase output
|
* @param[in] script_pub_key the coinbase output
|
||||||
* @param[in] use_mempool set false to omit mempool transactions
|
* @param[in] options options for creating the block
|
||||||
* @returns a block template
|
* @returns a block template
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool = true) = 0;
|
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, const node::BlockCreateOptions& options={}) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes new block. A valid new block is automatically relayed to peers.
|
* Processes new block. A valid new block is automatically relayed to peers.
|
||||||
|
@ -884,12 +884,11 @@ public:
|
|||||||
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root);
|
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool) override
|
std::unique_ptr<CBlockTemplate> createNewBlock(const CScript& script_pub_key, const BlockCreateOptions& options) override
|
||||||
{
|
{
|
||||||
BlockAssembler::Options options;
|
BlockAssembler::Options assemble_options{options};
|
||||||
ApplyArgsManOptions(gArgs, options);
|
ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
|
||||||
|
return BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key);
|
||||||
return BlockAssembler{chainman().ActiveChainstate(), use_mempool ? context()->mempool.get() : nullptr, options}.CreateNewBlock(script_pub_key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeContext* context() override { return &m_node; }
|
NodeContext* context() override { return &m_node; }
|
||||||
|
@ -66,7 +66,7 @@ static BlockAssembler::Options ClampOptions(BlockAssembler::Options options)
|
|||||||
|
|
||||||
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
|
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
|
||||||
: chainparams{chainstate.m_chainman.GetParams()},
|
: chainparams{chainstate.m_chainman.GetParams()},
|
||||||
m_mempool{mempool},
|
m_mempool{options.use_mempool ? mempool : nullptr},
|
||||||
m_chainstate{chainstate},
|
m_chainstate{chainstate},
|
||||||
m_options{ClampOptions(options)}
|
m_options{ClampOptions(options)}
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#ifndef BITCOIN_NODE_MINER_H
|
#ifndef BITCOIN_NODE_MINER_H
|
||||||
#define BITCOIN_NODE_MINER_H
|
#define BITCOIN_NODE_MINER_H
|
||||||
|
|
||||||
|
#include <node/types.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
@ -153,7 +154,7 @@ private:
|
|||||||
Chainstate& m_chainstate;
|
Chainstate& m_chainstate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Options {
|
struct Options : BlockCreateOptions {
|
||||||
// Configuration parameters for the block size
|
// Configuration parameters for the block size
|
||||||
size_t nBlockMaxWeight{DEFAULT_BLOCK_MAX_WEIGHT};
|
size_t nBlockMaxWeight{DEFAULT_BLOCK_MAX_WEIGHT};
|
||||||
CFeeRate blockMinFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
|
CFeeRate blockMinFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#ifndef BITCOIN_NODE_TYPES_H
|
#ifndef BITCOIN_NODE_TYPES_H
|
||||||
#define BITCOIN_NODE_TYPES_H
|
#define BITCOIN_NODE_TYPES_H
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
enum class TransactionError {
|
enum class TransactionError {
|
||||||
OK, //!< No error
|
OK, //!< No error
|
||||||
@ -24,6 +26,13 @@ enum class TransactionError {
|
|||||||
MAX_BURN_EXCEEDED,
|
MAX_BURN_EXCEEDED,
|
||||||
INVALID_PACKAGE,
|
INVALID_PACKAGE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BlockCreateOptions {
|
||||||
|
/**
|
||||||
|
* Set false to omit mempool transactions
|
||||||
|
*/
|
||||||
|
bool use_mempool{true};
|
||||||
|
};
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
#endif // BITCOIN_NODE_TYPES_H
|
#endif // BITCOIN_NODE_TYPES_H
|
||||||
|
@ -371,7 +371,7 @@ static RPCHelpMan generateblock()
|
|||||||
|
|
||||||
ChainstateManager& chainman = EnsureChainman(node);
|
ChainstateManager& chainman = EnsureChainman(node);
|
||||||
{
|
{
|
||||||
std::unique_ptr<CBlockTemplate> blocktemplate{miner.createNewBlock(coinbase_script, /*use_mempool=*/false)};
|
std::unique_ptr<CBlockTemplate> blocktemplate{miner.createNewBlock(coinbase_script, {.use_mempool = false})};
|
||||||
if (!blocktemplate) {
|
if (!blocktemplate) {
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user