|
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 |
|
@@ -370,20 +370,21 @@ static RPCHelpMan generateblock()
|
370 | 370 |
|
371 | 371 | ChainstateManager& chainman = EnsureChainman(node);
|
372 | 372 | {
|
373 |
| - std::unique_ptr<CBlockTemplate> blocktemplate{miner.createNewBlock(coinbase_script, {.use_mempool = false})}; |
374 |
| - if (!blocktemplate) { |
375 |
| - throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); |
| 373 | + LOCK(chainman.GetMutex()); |
| 374 | + { |
| 375 | + std::unique_ptr<CBlockTemplate> blocktemplate{miner.createNewBlock(coinbase_script, {.use_mempool = false})}; |
| 376 | + if (!blocktemplate) { |
| 377 | + throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); |
| 378 | + } |
| 379 | + block = blocktemplate->block; |
376 | 380 | }
|
377 |
| - block = blocktemplate->block; |
378 |
| - } |
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 | 388 | BlockValidationState state;
|
388 | 389 | if (!miner.testBlockValidity(block, /*check_merkle_root=*/false, state)) {
|
389 | 390 | throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("testBlockValidity failed: %s", state.ToString()));
|
|
0 commit comments