|
8 | 8 | #include <chainparams.h> |
9 | 9 | #include <consensus/amount.h> |
10 | 10 | #include <consensus/consensus.h> |
| 11 | +#include <consensus/merkle.h> |
11 | 12 | #include <consensus/params.h> |
12 | 13 | #include <consensus/validation.h> |
13 | 14 | #include <core_io.h> |
@@ -121,14 +122,10 @@ static RPCHelpMan getnetworkhashps() |
121 | 122 | } |
122 | 123 |
|
123 | 124 | #if ENABLE_MINER |
124 | | -static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, unsigned int& extra_nonce, uint256& block_hash) |
| 125 | +static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, uint256& block_hash) |
125 | 126 | { |
126 | 127 | block_hash.SetNull(); |
127 | | - |
128 | | - { |
129 | | - LOCK(cs_main); |
130 | | - IncrementExtraNonce(&block, chainman.ActiveChain().Tip(), extra_nonce); |
131 | | - } |
| 128 | + block.hashMerkleRoot = BlockMerkleRoot(block); |
132 | 129 |
|
133 | 130 | CChainParams chainparams(Params()); |
134 | 131 |
|
@@ -157,30 +154,20 @@ static UniValue generateBlocks(ChainstateManager& chainman, const NodeContext& n |
157 | 154 | { |
158 | 155 | EnsureLLMQContext(node); |
159 | 156 |
|
160 | | - int nHeightEnd = 0; |
161 | | - int nHeight = 0; |
162 | | - |
163 | | - { // Don't keep cs_main locked |
164 | | - LOCK(cs_main); |
165 | | - nHeight = chainman.ActiveChain().Height(); |
166 | | - nHeightEnd = nHeight+nGenerate; |
167 | | - } |
168 | | - unsigned int nExtraNonce = 0; |
169 | 157 | UniValue blockHashes(UniValue::VARR); |
170 | | - while (nHeight < nHeightEnd && !ShutdownRequested()) |
171 | | - { |
| 158 | + while (nGenerate > 0 && !ShutdownRequested()) { |
172 | 159 | std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainman.ActiveChainstate(), node, &mempool, Params()).CreateNewBlock(coinbase_script)); |
173 | 160 | if (!pblocktemplate.get()) |
174 | 161 | throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); |
175 | 162 | CBlock *pblock = &pblocktemplate->block; |
176 | 163 |
|
177 | 164 | uint256 block_hash; |
178 | | - if (!GenerateBlock(chainman, *pblock, nMaxTries, nExtraNonce, block_hash)) { |
| 165 | + if (!GenerateBlock(chainman, *pblock, nMaxTries, block_hash)) { |
179 | 166 | break; |
180 | 167 | } |
181 | 168 |
|
182 | 169 | if (!block_hash.IsNull()) { |
183 | | - ++nHeight; |
| 170 | + --nGenerate; |
184 | 171 | blockHashes.push_back(block_hash.GetHex()); |
185 | 172 | } |
186 | 173 | } |
@@ -400,9 +387,8 @@ static RPCHelpMan generateblock() |
400 | 387 |
|
401 | 388 | uint256 block_hash; |
402 | 389 | uint64_t max_tries{DEFAULT_MAX_TRIES}; |
403 | | - unsigned int extra_nonce{0}; |
404 | 390 |
|
405 | | - if (!GenerateBlock(chainman, block, max_tries, extra_nonce, block_hash) || block_hash.IsNull()) { |
| 391 | + if (!GenerateBlock(chainman, block, max_tries, block_hash) || block_hash.IsNull()) { |
406 | 392 | throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block."); |
407 | 393 | } |
408 | 394 |
|
|
0 commit comments