Skip to content

Commit 64ebb0f

Browse files
committed
Always pass options to BlockAssembler constructor
This makes the options argument for BlockAssembler constructor mandatory, dropping implicit use of ArgsManager. The caller i.e. the Mining interface implementation now handles this. In a future Stratum v2 change the Options object needs to be mofified after arguments have been processed. Specifically the pool communicates how many extra bytes it needs for its own outputs (payouts, extra commitments, etc). This will need to be substracted from what the user set as -blockmaxweight. Such a change can be implemented in createNewBlock, after ApplyArgsManOptions.
1 parent 4bf2e36 commit 64ebb0f

File tree

7 files changed

+15
-16
lines changed

7 files changed

+15
-16
lines changed

src/node/interfaces.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ using interfaces::MakeSignalHandler;
7575
using interfaces::Mining;
7676
using interfaces::Node;
7777
using interfaces::WalletLoader;
78+
using node::BlockAssembler;
7879
using util::Join;
7980

8081
namespace node {
@@ -862,8 +863,11 @@ class MinerImpl : public Mining
862863

863864
std::unique_ptr<CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool) override
864865
{
866+
BlockAssembler::Options options;
867+
ApplyArgsManOptions(gArgs, options);
868+
865869
LOCK(::cs_main);
866-
return BlockAssembler{chainman().ActiveChainstate(), use_mempool ? context()->mempool.get() : nullptr}.CreateNewBlock(script_pub_key);
870+
return BlockAssembler{chainman().ActiveChainstate(), use_mempool ? context()->mempool.get() : nullptr, options}.CreateNewBlock(script_pub_key);
867871
}
868872

869873
NodeContext* context() override { return &m_node; }

src/node/miner.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ void ApplyArgsManOptions(const ArgsManager& args, BlockAssembler::Options& optio
8080
if (const auto parsed{ParseMoney(*blockmintxfee)}) options.blockMinFeeRate = CFeeRate{*parsed};
8181
}
8282
}
83-
static BlockAssembler::Options ConfiguredOptions()
84-
{
85-
BlockAssembler::Options options;
86-
ApplyArgsManOptions(gArgs, options);
87-
return options;
88-
}
89-
90-
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool)
91-
: BlockAssembler(chainstate, mempool, ConfiguredOptions()) {}
9283

9384
void BlockAssembler::resetBlock()
9485
{

src/node/miner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class BlockAssembler
161161
bool test_block_validity{true};
162162
};
163163

164-
explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool);
165164
explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options);
166165

167166
/** Construct a new block template with coinbase to scriptPubKeyIn */

src/test/blockfilter_index_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
6767
const std::vector<CMutableTransaction>& txns,
6868
const CScript& scriptPubKey)
6969
{
70-
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get()}.CreateNewBlock(scriptPubKey);
70+
BlockAssembler::Options options;
71+
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get(), options}.CreateNewBlock(scriptPubKey);
7172
CBlock& block = pblocktemplate->block;
7273
block.hashPrevBlock = prev->GetBlockHash();
7374
block.nTime = prev->nTime + 1;

src/test/peerman_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ static void mineBlock(const node::NodeContext& node, std::chrono::seconds block_
2020
{
2121
auto curr_time = GetTime<std::chrono::seconds>();
2222
SetMockTime(block_time); // update time so the block is created with it
23-
CBlock block = node::BlockAssembler{node.chainman->ActiveChainstate(), nullptr}.CreateNewBlock(CScript() << OP_TRUE)->block;
23+
node::BlockAssembler::Options options;
24+
CBlock block = node::BlockAssembler{node.chainman->ActiveChainstate(), nullptr, options}.CreateNewBlock(CScript() << OP_TRUE)->block;
2425
while (!CheckProofOfWork(block.GetHash(), block.nBits, node.chainman->GetConsensus())) ++block.nNonce;
2526
block.fChecked = true; // little speedup
2627
SetMockTime(curr_time); // process block at current time

src/test/util/setup_common.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ CBlock TestChain100Setup::CreateBlock(
374374
const CScript& scriptPubKey,
375375
Chainstate& chainstate)
376376
{
377-
CBlock block = BlockAssembler{chainstate, nullptr}.CreateNewBlock(scriptPubKey)->block;
377+
BlockAssembler::Options options;
378+
CBlock block = BlockAssembler{chainstate, nullptr, options}.CreateNewBlock(scriptPubKey)->block;
378379

379380
Assert(block.vtx.size() == 1);
380381
for (const CMutableTransaction& tx : txns) {

src/test/validation_block_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
6565
static int i = 0;
6666
static uint64_t time = Params().GenesisBlock().nTime;
6767

68-
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get()}.CreateNewBlock(CScript{} << i++ << OP_TRUE);
68+
BlockAssembler::Options options;
69+
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get(), options}.CreateNewBlock(CScript{} << i++ << OP_TRUE);
6970
auto pblock = std::make_shared<CBlock>(ptemplate->block);
7071
pblock->hashPrevBlock = prev_hash;
7172
pblock->nTime = ++time;
@@ -329,7 +330,8 @@ BOOST_AUTO_TEST_CASE(witness_commitment_index)
329330
LOCK(Assert(m_node.chainman)->GetMutex());
330331
CScript pubKey;
331332
pubKey << 1 << OP_TRUE;
332-
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get()}.CreateNewBlock(pubKey);
333+
BlockAssembler::Options options;
334+
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get(), options}.CreateNewBlock(pubKey);
333335
CBlock pblock = ptemplate->block;
334336

335337
CTxOut witness;

0 commit comments

Comments
 (0)