@@ -156,11 +156,11 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t&
156156 return true ;
157157}
158158
159- static UniValue generateBlocks (ChainstateManager& chainman, const CTxMemPool& mempool , const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries)
159+ static UniValue generateBlocks (ChainstateManager& chainman, Mining& miner , const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries)
160160{
161161 UniValue blockHashes (UniValue::VARR);
162162 while (nGenerate > 0 && !chainman.m_interrupt ) {
163- std::unique_ptr<CBlockTemplate> pblocktemplate (BlockAssembler{chainman. ActiveChainstate (), &mempool}. CreateNewBlock (coinbase_script));
163+ std::unique_ptr<CBlockTemplate> pblocktemplate (miner. createNewBlock (coinbase_script));
164164 if (!pblocktemplate.get ())
165165 throw JSONRPCError (RPC_INTERNAL_ERROR, " Couldn't create new block" );
166166
@@ -241,10 +241,10 @@ static RPCHelpMan generatetodescriptor()
241241 }
242242
243243 NodeContext& node = EnsureAnyNodeContext (request.context );
244- const CTxMemPool& mempool = EnsureMemPool (node);
244+ Mining& miner = EnsureMining (node);
245245 ChainstateManager& chainman = EnsureChainman (node);
246246
247- return generateBlocks (chainman, mempool , coinbase_script, num_blocks, max_tries);
247+ return generateBlocks (chainman, miner , coinbase_script, num_blocks, max_tries);
248248},
249249 };
250250}
@@ -287,12 +287,12 @@ static RPCHelpMan generatetoaddress()
287287 }
288288
289289 NodeContext& node = EnsureAnyNodeContext (request.context );
290- const CTxMemPool& mempool = EnsureMemPool (node);
290+ Mining& miner = EnsureMining (node);
291291 ChainstateManager& chainman = EnsureChainman (node);
292292
293293 CScript coinbase_script = GetScriptForDestination (destination);
294294
295- return generateBlocks (chainman, mempool , coinbase_script, num_blocks, max_tries);
295+ return generateBlocks (chainman, miner , coinbase_script, num_blocks, max_tries);
296296},
297297 };
298298}
@@ -373,7 +373,7 @@ static RPCHelpMan generateblock()
373373 {
374374 LOCK (cs_main);
375375
376- std::unique_ptr<CBlockTemplate> blocktemplate (BlockAssembler{chainman. ActiveChainstate (), nullptr }. CreateNewBlock (coinbase_script)) ;
376+ std::unique_ptr<CBlockTemplate> blocktemplate{miner. createNewBlock (coinbase_script, /* use_mempool= */ false )} ;
377377 if (!blocktemplate) {
378378 throw JSONRPCError (RPC_INTERNAL_ERROR, " Couldn't create new block" );
379379 }
@@ -671,7 +671,6 @@ static RPCHelpMan getblocktemplate()
671671 std::string strMode = " template" ;
672672 UniValue lpval = NullUniValue;
673673 std::set<std::string> setClientRules;
674- Chainstate& active_chainstate = chainman.ActiveChainstate ();
675674 if (!request.params [0 ].isNull ())
676675 {
677676 const UniValue& oparam = request.params [0 ].get_obj ();
@@ -810,18 +809,19 @@ static RPCHelpMan getblocktemplate()
810809 // Clear pindexPrev so future calls make a new block, despite any failures from here on
811810 pindexPrev = nullptr ;
812811
813- // Store the pindexBest used before CreateNewBlock , to avoid races
812+ // Store the pindexBest used before createNewBlock , to avoid races
814813 nTransactionsUpdatedLast = mempool.GetTransactionsUpdated ();
815814 CBlockIndex* pindexPrevNew = chainman.m_blockman .LookupBlockIndex (miner.getTipHash ());
816815 time_start = GetTime ();
817816
818817 // Create new block
819818 CScript scriptDummy = CScript () << OP_TRUE;
820- pblocktemplate = BlockAssembler{active_chainstate, &mempool}. CreateNewBlock (scriptDummy);
821- if (!pblocktemplate)
819+ pblocktemplate = miner. createNewBlock (scriptDummy);
820+ if (!pblocktemplate) {
822821 throw JSONRPCError (RPC_OUT_OF_MEMORY, " Out of memory" );
822+ }
823823
824- // Need to update only after we know CreateNewBlock succeeded
824+ // Need to update only after we know createNewBlock succeeded
825825 pindexPrev = pindexPrevNew;
826826 }
827827 CHECK_NONFATAL (pindexPrev);
0 commit comments