|
1 | 1 | // Copyright (c) 2010 Satoshi Nakamoto |
2 | | -// Copyright (c) 2009-2022 The Bitcoin Core developers |
| 2 | +// Copyright (c) 2009-present The Bitcoin Core developers |
3 | 3 | // Distributed under the MIT software license, see the accompanying |
4 | 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | 5 |
|
@@ -371,22 +371,22 @@ static RPCHelpMan generateblock() |
371 | 371 |
|
372 | 372 | ChainstateManager& chainman = EnsureChainman(node); |
373 | 373 | { |
374 | | - std::unique_ptr<BlockTemplate> block_template{miner.createNewBlock({.use_mempool = false, .coinbase_output_script = coinbase_output_script})}; |
375 | | - CHECK_NONFATAL(block_template); |
| 374 | + LOCK(chainman.GetMutex()); |
| 375 | + { |
| 376 | + std::unique_ptr<BlockTemplate> block_template{miner.createNewBlock({.use_mempool = false, .coinbase_output_script = coinbase_output_script})}; |
| 377 | + CHECK_NONFATAL(block_template); |
376 | 378 |
|
377 | | - block = block_template->getBlock(); |
378 | | - } |
| 379 | + block = block_template->getBlock(); |
| 380 | + } |
379 | 381 |
|
380 | | - CHECK_NONFATAL(block.vtx.size() == 1); |
| 382 | + CHECK_NONFATAL(block.vtx.size() == 1); |
381 | 383 |
|
382 | | - // Add transactions |
383 | | - block.vtx.insert(block.vtx.end(), txs.begin(), txs.end()); |
384 | | - RegenerateCommitments(block, chainman); |
| 384 | + // Add transactions |
| 385 | + block.vtx.insert(block.vtx.end(), txs.begin(), txs.end()); |
| 386 | + RegenerateCommitments(block, chainman); |
385 | 387 |
|
386 | | - { |
387 | | - LOCK(::cs_main); |
388 | 388 | BlockValidationState state; |
389 | | - if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) { |
| 389 | + if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) { |
390 | 390 | throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.ToString())); |
391 | 391 | } |
392 | 392 | } |
|
0 commit comments