Skip to content

Commit

Permalink
validation: missing cs_main lock for CheckBlock in ProcessNewBlock
Browse files Browse the repository at this point in the history
Github-Pull: #2295
Rebased-From: ce1781e
  • Loading branch information
furszy committed Apr 9, 2021
1 parent 1f38b90 commit c44b431
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3266,25 +3266,23 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, const std::shared_pt
const Consensus::Params& consensus = Params().GetConsensus();
int newHeight = 0;

// check block
bool checked = CheckBlock(*pblock, state);

if (pblock->GetHash() != consensus.hashGenesisBlock && pfrom != NULL) {
//if we get this far, check if the prev block is our prev block, if not then request sync and return false
BlockMap::iterator mi = mapBlockIndex.find(pblock->hashPrevBlock);
if (mi == mapBlockIndex.end()) {
g_connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::GETBLOCKS, chainActive.GetLocator(), UINT256_ZERO));
return false;
}
}

{
// CheckBlock requires cs_main lock
LOCK(cs_main);

if (!checked) {
if (!CheckBlock(*pblock, state)) {
return error ("%s : CheckBlock FAILED for block %s, %s", __func__, pblock->GetHash().GetHex(), FormatStateMessage(state));
}

// Request sync if needed
if (pblock->GetHash() != consensus.hashGenesisBlock && !pfrom) {
// if we get this far, check if the prev block is our prev block, if not then request sync and return false
BlockMap::iterator mi = mapBlockIndex.find(pblock->hashPrevBlock);
if (mi == mapBlockIndex.end()) {
g_connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::GETBLOCKS, chainActive.GetLocator(), UINT256_ZERO));
return false;
}
}

// Store to disk
CBlockIndex* pindex = nullptr;
bool ret = AcceptBlock(*pblock, state, &pindex, dbp);
Expand Down

0 comments on commit c44b431

Please sign in to comment.