Skip to content

Commit 63fd101

Browse files
committed
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.
1 parent 4a6b1f3 commit 63fd101

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,14 +5982,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
59825982
ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
59835983
}
59845984

5985-
{
5986-
LOCK(cs_main);
5987-
59885985
if (nCount == 0) {
59895986
// Nothing interesting. Stop asking this peers for more headers.
59905987
return true;
59915988
}
59925989

5990+
CBlockIndex *pindexLast = NULL;
5991+
{
5992+
LOCK(cs_main);
59935993
CNodeState *nodestate = State(pfrom->GetId());
59945994

59955995
// If this looks like it could be a block announcement (nCount <
@@ -6019,7 +6019,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60196019
return true;
60206020
}
60216021

6022-
CBlockIndex *pindexLast = NULL;
60236022
BOOST_FOREACH(const CBlockHeader& header, headers) {
60246023
CValidationState state;
60256024
if (pindexLast != NULL && header.hashPrevBlock != pindexLast->GetBlockHash()) {
@@ -6035,7 +6034,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60356034
}
60366035
}
60376036
}
6037+
}
60386038

6039+
{
6040+
LOCK(cs_main);
6041+
CNodeState *nodestate = State(pfrom->GetId());
60396042
if (nodestate->nUnconnectingHeaders > 0) {
60406043
LogPrint("net", "peer=%d: resetting nUnconnectingHeaders (%d -> 0)\n", pfrom->id, nodestate->nUnconnectingHeaders);
60416044
}

0 commit comments

Comments
 (0)