aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorSjors Provoost <sjors@sprovoost.nl>2024-07-16 10:13:28 +0200
committerSjors Provoost <sjors@sprovoost.nl>2024-07-16 10:27:57 +0200
commit6b4c817d4b978adf69738677c74855ef0675f333 (patch)
treeb4cc50a4e3491ad419f9e0865fd0a31c49ecc714 /src/node
parent323cfed5959b25c98235ec988b408fc5e3391e3c (diff)
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>
Diffstat (limited to 'src/node')
-rw-r--r--src/node/interfaces.cpp9
-rw-r--r--src/node/miner.cpp2
-rw-r--r--src/node/miner.h3
-rw-r--r--src/node/types.h9
4 files changed, 16 insertions, 7 deletions
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index ef12ffe34b..46d36f83f8 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -884,12 +884,11 @@ public:
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;
- ApplyArgsManOptions(gArgs, options);
-
- return BlockAssembler{chainman().ActiveChainstate(), use_mempool ? context()->mempool.get() : nullptr, options}.CreateNewBlock(script_pub_key);
+ BlockAssembler::Options assemble_options{options};
+ ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
+ return BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key);
}
NodeContext* context() override { return &m_node; }
diff --git a/src/node/miner.cpp b/src/node/miner.cpp
index 291f1d5fc7..67465b1e70 100644
--- a/src/node/miner.cpp
+++ b/src/node/miner.cpp
@@ -66,7 +66,7 @@ static BlockAssembler::Options ClampOptions(BlockAssembler::Options options)
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
: chainparams{chainstate.m_chainman.GetParams()},
- m_mempool{mempool},
+ m_mempool{options.use_mempool ? mempool : nullptr},
m_chainstate{chainstate},
m_options{ClampOptions(options)}
{
diff --git a/src/node/miner.h b/src/node/miner.h
index 622ca16c8f..efd773eb31 100644
--- a/src/node/miner.h
+++ b/src/node/miner.h
@@ -6,6 +6,7 @@
#ifndef BITCOIN_NODE_MINER_H
#define BITCOIN_NODE_MINER_H
+#include <node/types.h>
#include <policy/policy.h>
#include <primitives/block.h>
#include <txmempool.h>
@@ -153,7 +154,7 @@ private:
Chainstate& m_chainstate;
public:
- struct Options {
+ struct Options : BlockCreateOptions {
// Configuration parameters for the block size
size_t nBlockMaxWeight{DEFAULT_BLOCK_MAX_WEIGHT};
CFeeRate blockMinFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
diff --git a/src/node/types.h b/src/node/types.h
index 0461e85f43..d4e7d93015 100644
--- a/src/node/types.h
+++ b/src/node/types.h
@@ -13,6 +13,8 @@
#ifndef BITCOIN_NODE_TYPES_H
#define BITCOIN_NODE_TYPES_H
+#include <cstddef>
+
namespace node {
enum class TransactionError {
OK, //!< No error
@@ -24,6 +26,13 @@ enum class TransactionError {
MAX_BURN_EXCEEDED,
INVALID_PACKAGE,
};
+
+struct BlockCreateOptions {
+ /**
+ * Set false to omit mempool transactions
+ */
+ bool use_mempool{true};
+};
} // namespace node
#endif // BITCOIN_NODE_TYPES_H