Skip to content

Commit d3eb5ae

Browse files
committed
Merge pull request #6007
eb63bf8 Fix missing lock in submitblock (Matt Corallo)
2 parents 9125c08 + eb63bf8 commit d3eb5ae

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/rpcmining.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,22 +629,27 @@ Value submitblock(const Array& params, bool fHelp)
629629
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
630630

631631
uint256 hash = block.GetHash();
632-
BlockMap::iterator mi = mapBlockIndex.find(hash);
633-
if (mi != mapBlockIndex.end()) {
634-
CBlockIndex *pindex = mi->second;
635-
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
636-
return "duplicate";
637-
if (pindex->nStatus & BLOCK_FAILED_MASK)
638-
return "duplicate-invalid";
639-
// Otherwise, we might only have the header - process the block before returning
632+
bool fBlockPresent = false;
633+
{
634+
LOCK(cs_main);
635+
BlockMap::iterator mi = mapBlockIndex.find(hash);
636+
if (mi != mapBlockIndex.end()) {
637+
CBlockIndex *pindex = mi->second;
638+
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
639+
return "duplicate";
640+
if (pindex->nStatus & BLOCK_FAILED_MASK)
641+
return "duplicate-invalid";
642+
// Otherwise, we might only have the header - process the block before returning
643+
fBlockPresent = true;
644+
}
640645
}
641646

642647
CValidationState state;
643648
submitblock_StateCatcher sc(block.GetHash());
644649
RegisterValidationInterface(&sc);
645650
bool fAccepted = ProcessNewBlock(state, NULL, &block);
646651
UnregisterValidationInterface(&sc);
647-
if (mi != mapBlockIndex.end())
652+
if (fBlockPresent)
648653
{
649654
if (fAccepted && !sc.found)
650655
return "duplicate-inconclusive";

0 commit comments

Comments
 (0)