diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-04-14 10:49:13 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-04-14 10:51:30 +0200 |
commit | d3eb5ae46a4cc05a0b1dfdba66e704cb5e7886f1 (patch) | |
tree | 488727fec0231a10501e62ae541e6d55236b3a4e | |
parent | 9125c08f3468928eba004636bd95494a94e1a82b (diff) | |
parent | eb63bf86cf6dc99f150574463df6ffb013a34493 (diff) |
Merge pull request #6007
eb63bf8 Fix missing lock in submitblock (Matt Corallo)
-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 1e6531f68a..949fe3ed52 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -629,14 +629,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; @@ -644,7 +649,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"; |