Skip to content

Commit

Permalink
net_processing: missing cs_main lock for chainActive.GetLocator() call
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Apr 7, 2021
1 parent 959936f commit 21646d8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,16 +1599,17 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
CInv inv(MSG_BLOCK, hashBlock);
LogPrint(BCLog::NET, "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id);

//sometimes we will be sent their most recent block and its not the one we want, in that case tell where we are
// sometimes we will be sent their most recent block and its not the one we want, in that case tell where we are
if (!mapBlockIndex.count(pblock->hashPrevBlock)) {
CBlockLocator locator = WITH_LOCK(cs_main, return chainActive.GetLocator(););
if (find(pfrom->vBlockRequested.begin(), pfrom->vBlockRequested.end(), hashBlock) != pfrom->vBlockRequested.end()) {
//we already asked for this block, so lets work backwards and ask for the previous block
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKS, chainActive.GetLocator(), pblock->hashPrevBlock));
pfrom->vBlockRequested.push_back(pblock->hashPrevBlock);
// we already asked for this block, so lets work backwards and ask for the previous block
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKS, locator, pblock->hashPrevBlock));
pfrom->vBlockRequested.emplace_back(pblock->hashPrevBlock);
} else {
//ask to sync to this block
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKS, chainActive.GetLocator(), hashBlock));
pfrom->vBlockRequested.push_back(hashBlock);
// ask to sync to this block
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKS, locator, hashBlock));
pfrom->vBlockRequested.emplace_back(hashBlock);
}
} else {
pfrom->AddInventoryKnown(inv);
Expand Down

0 comments on commit 21646d8

Please sign in to comment.