Split ::HEADERS processing into two separate cs_main locks

This will allow NotifyHeaderTip to be called from an
AcceptBlockHeader wrapper function without holding cs_main.
This commit is contained in:
Matt Corallo 2016-11-03 16:34:31 -04:00
parent 4a6b1f36b7
commit 63fd101c52

View file

@ -5982,14 +5982,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
ReadCompactSize(vRecv); // ignore tx count; assume it is 0. ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
} }
{
LOCK(cs_main);
if (nCount == 0) { if (nCount == 0) {
// Nothing interesting. Stop asking this peers for more headers. // Nothing interesting. Stop asking this peers for more headers.
return true; return true;
} }
CBlockIndex *pindexLast = NULL;
{
LOCK(cs_main);
CNodeState *nodestate = State(pfrom->GetId()); CNodeState *nodestate = State(pfrom->GetId());
// If this looks like it could be a block announcement (nCount < // If this looks like it could be a block announcement (nCount <
@ -6019,7 +6019,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return true; return true;
} }
CBlockIndex *pindexLast = NULL;
BOOST_FOREACH(const CBlockHeader& header, headers) { BOOST_FOREACH(const CBlockHeader& header, headers) {
CValidationState state; CValidationState state;
if (pindexLast != NULL && header.hashPrevBlock != pindexLast->GetBlockHash()) { if (pindexLast != NULL && header.hashPrevBlock != pindexLast->GetBlockHash()) {
@ -6035,7 +6034,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
} }
} }
} }
}
{
LOCK(cs_main);
CNodeState *nodestate = State(pfrom->GetId());
if (nodestate->nUnconnectingHeaders > 0) { if (nodestate->nUnconnectingHeaders > 0) {
LogPrint("net", "peer=%d: resetting nUnconnectingHeaders (%d -> 0)\n", pfrom->id, nodestate->nUnconnectingHeaders); LogPrint("net", "peer=%d: resetting nUnconnectingHeaders (%d -> 0)\n", pfrom->id, nodestate->nUnconnectingHeaders);
} }