diff options
author | Matt Corallo <git@bluematt.me> | 2015-04-13 17:55:41 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-04-14 10:52:03 +0200 |
commit | eae305f4c4a42e82e932403b5b6544dd85880ec1 (patch) | |
tree | d776f07b2e50640ea45109daf888b1f8854a6a02 | |
parent | 34127c77cbdc0c177945ccfbc4e4eb9c8e8a2c9c (diff) |
Fix missing lock in submitblock
Rebased-From: eb63bf86cf6dc99f150574463df6ffb013a34493
Github-Pull: #6007
-rw-r--r-- | src/rpcmining.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 86230521ce..37465eedd0 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -637,14 +637,19 @@ Value submitblock(const Array& params, bool fHelp) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); uint256 hash = block.GetHash(); - BlockMap::iterator mi = mapBlockIndex.find(hash); - if (mi != mapBlockIndex.end()) { - CBlockIndex *pindex = mi->second; - if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) - return "duplicate"; - if (pindex->nStatus & BLOCK_FAILED_MASK) - return "duplicate-invalid"; - // Otherwise, we might only have the header - process the block before returning + bool fBlockPresent = false; + { + LOCK(cs_main); + BlockMap::iterator mi = mapBlockIndex.find(hash); + if (mi != mapBlockIndex.end()) { + CBlockIndex *pindex = mi->second; + if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) + return "duplicate"; + if (pindex->nStatus & BLOCK_FAILED_MASK) + return "duplicate-invalid"; + // Otherwise, we might only have the header - process the block before returning + fBlockPresent = true; + } } CValidationState state; @@ -652,7 +657,7 @@ Value submitblock(const Array& params, bool fHelp) RegisterValidationInterface(&sc); bool fAccepted = ProcessNewBlock(state, NULL, &block); UnregisterValidationInterface(&sc); - if (mi != mapBlockIndex.end()) + if (fBlockPresent) { if (fAccepted && !sc.found) return "duplicate-inconclusive"; |