From ba8d498559a4956e3bdefa395f9f3a3dd38eac77 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Fri, 28 Sep 2018 18:40:51 -0400 Subject: [PATCH] bitcoind rpc check should take main locks for mapBlockIndex, check for key --- src/validation.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 60eaad461c..f3425b77a4 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2220,9 +2220,12 @@ bool BitcoindRPCCheck(const bool init) pblocktree->ReadInvalidBlockQueue(vblocksToReconsider); std::vector vblocksToReconsiderAgain; BOOST_FOREACH(uint256& blockhash, vblocksToReconsider) { - CBlockIndex* pblockindex = mapBlockIndex[blockhash]; - if ((pblockindex->nStatus & BLOCK_FAILED_MASK)) { - vblocksToReconsiderAgain.push_back(blockhash); + LOCK(cs_main); + if (mapBlockIndex.count(blockhash)) { + CBlockIndex* pblockindex = mapBlockIndex[blockhash]; + if ((pblockindex->nStatus & BLOCK_FAILED_MASK)) { + vblocksToReconsiderAgain.push_back(blockhash); + } } } vblocksToReconsider = vblocksToReconsiderAgain; @@ -2312,11 +2315,14 @@ bool BitcoindRPCCheck(const bool init) //Now to clear out now-valid blocks BOOST_FOREACH(const uint256& blockhash, vblocksToReconsider) { - CBlockIndex* pblockindex = mapBlockIndex[blockhash]; + LOCK(cs_main); + if (mapBlockIndex.count(blockhash)) { + CBlockIndex* pblockindex = mapBlockIndex[blockhash]; - //Marked as invalid still, put back into queue - if((pblockindex->nStatus & BLOCK_FAILED_MASK)) { - vblocksToReconsiderAgain.push_back(blockhash); + //Marked as invalid still, put back into queue + if((pblockindex->nStatus & BLOCK_FAILED_MASK)) { + vblocksToReconsiderAgain.push_back(blockhash); + } } }