Skip to content

Commit fafe5c0

Browse files
author
MacroFake
committed
Do not pass CChainParams& to BlockAssembler constructor
1 parent faf012b commit fafe5c0

File tree

9 files changed

+16
-16
lines changed

9 files changed

+16
-16
lines changed

src/node/miner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ BlockAssembler::Options::Options()
6262
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
6363
}
6464

65-
BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params, const Options& options)
66-
: chainparams(params),
65+
BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const Options& options)
66+
: chainparams{chainstate.m_chainman.GetParams()},
6767
m_mempool(mempool),
6868
m_chainstate(chainstate)
6969
{
@@ -87,8 +87,8 @@ static BlockAssembler::Options DefaultOptions()
8787
return options;
8888
}
8989

90-
BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params)
91-
: BlockAssembler(chainstate, mempool, params, DefaultOptions()) {}
90+
BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool)
91+
: BlockAssembler(chainstate, mempool, DefaultOptions()) {}
9292

9393
void BlockAssembler::resetBlock()
9494
{

src/node/miner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class BlockAssembler
157157
CFeeRate blockMinFeeRate;
158158
};
159159

160-
explicit BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params);
161-
explicit BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params, const Options& options);
160+
explicit BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool);
161+
explicit BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const Options& options);
162162

163163
/** Construct a new block template with coinbase to scriptPubKeyIn */
164164
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn);

src/rpc/mining.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& me
145145
{
146146
UniValue blockHashes(UniValue::VARR);
147147
while (nGenerate > 0 && !ShutdownRequested()) {
148-
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainman.ActiveChainstate(), mempool, Params()).CreateNewBlock(coinbase_script));
148+
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler{chainman.ActiveChainstate(), mempool}.CreateNewBlock(coinbase_script));
149149
if (!pblocktemplate.get())
150150
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
151151
CBlock *pblock = &pblocktemplate->block;
@@ -357,7 +357,7 @@ static RPCHelpMan generateblock()
357357
LOCK(cs_main);
358358

359359
CTxMemPool empty_mempool;
360-
std::unique_ptr<CBlockTemplate> blocktemplate(BlockAssembler(chainman.ActiveChainstate(), empty_mempool, chainparams).CreateNewBlock(coinbase_script));
360+
std::unique_ptr<CBlockTemplate> blocktemplate(BlockAssembler{chainman.ActiveChainstate(), empty_mempool}.CreateNewBlock(coinbase_script));
361361
if (!blocktemplate) {
362362
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
363363
}
@@ -755,7 +755,7 @@ static RPCHelpMan getblocktemplate()
755755

756756
// Create new block
757757
CScript scriptDummy = CScript() << OP_TRUE;
758-
pblocktemplate = BlockAssembler(active_chainstate, mempool, Params()).CreateNewBlock(scriptDummy);
758+
pblocktemplate = BlockAssembler{active_chainstate, mempool}.CreateNewBlock(scriptDummy);
759759
if (!pblocktemplate)
760760
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
761761

src/test/blockfilter_index_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
6666
const CScript& scriptPubKey)
6767
{
6868
const CChainParams& chainparams = Params();
69-
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), *m_node.mempool, chainparams).CreateNewBlock(scriptPubKey);
69+
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), *m_node.mempool}.CreateNewBlock(scriptPubKey);
7070
CBlock& block = pblocktemplate->block;
7171
block.hashPrevBlock = prev->GetBlockHash();
7272
block.nTime = prev->nTime + 1;

src/test/fuzz/tx_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CCh
9797
BlockAssembler::Options options;
9898
options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
9999
options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
100-
auto assembler = BlockAssembler{chainstate, *static_cast<CTxMemPool*>(&tx_pool), chainstate.m_params, options};
100+
auto assembler = BlockAssembler{chainstate, *static_cast<CTxMemPool*>(&tx_pool), options};
101101
auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE);
102102
Assert(block_template->block.vtx.size() >= 1);
103103
}

src/test/miner_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ BlockAssembler MinerTestingSetup::AssemblerForTest(const CChainParams& params)
5151

5252
options.nBlockMaxWeight = MAX_BLOCK_WEIGHT;
5353
options.blockMinFeeRate = blockMinFeeRate;
54-
return BlockAssembler(m_node.chainman->ActiveChainstate(), *m_node.mempool, params, options);
54+
return BlockAssembler{m_node.chainman->ActiveChainstate(), *m_node.mempool, options};
5555
}
5656

5757
constexpr static struct {

src/test/util/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
7777
std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
7878
{
7979
auto block = std::make_shared<CBlock>(
80-
BlockAssembler{Assert(node.chainman)->ActiveChainstate(), *Assert(node.mempool), Params()}
80+
BlockAssembler{Assert(node.chainman)->ActiveChainstate(), *Assert(node.mempool)}
8181
.CreateNewBlock(coinbase_scriptPubKey)
8282
->block);
8383

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ CBlock TestChain100Setup::CreateBlock(
275275
{
276276
const CChainParams& chainparams = Params();
277277
CTxMemPool empty_pool;
278-
CBlock block = BlockAssembler(chainstate, empty_pool, chainparams).CreateNewBlock(scriptPubKey)->block;
278+
CBlock block = BlockAssembler{chainstate, empty_pool}.CreateNewBlock(scriptPubKey)->block;
279279

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

src/test/validation_block_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ 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, Params()).CreateNewBlock(CScript{} << i++ << OP_TRUE);
68+
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), *m_node.mempool}.CreateNewBlock(CScript{} << i++ << OP_TRUE);
6969
auto pblock = std::make_shared<CBlock>(ptemplate->block);
7070
pblock->hashPrevBlock = prev_hash;
7171
pblock->nTime = ++time;
@@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(witness_commitment_index)
327327
{
328328
CScript pubKey;
329329
pubKey << 1 << OP_TRUE;
330-
auto ptemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(pubKey);
330+
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), *m_node.mempool}.CreateNewBlock(pubKey);
331331
CBlock pblock = ptemplate->block;
332332

333333
CTxOut witness;

0 commit comments

Comments
 (0)