Skip to content

Commit ce5c1f4

Browse files
committed
Merge #9252: Release cs_main before calling ProcessNewBlock, or processing headers (cmpctblock handling)
bd02bdd Release cs_main before processing cmpctblock as header (Suhas Daftuar) 680b0c0 Release cs_main before calling ProcessNewBlock (cmpctblock handling) (Suhas Daftuar)
2 parents 6dc4c43 + bd02bdd commit ce5c1f4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/net_processing.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,11 +1782,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
17821782
}
17831783
}
17841784

1785+
// When we succeed in decoding a block's txids from a cmpctblock
1786+
// message we typically jump to the BLOCKTXN handling code, with a
1787+
// dummy (empty) BLOCKTXN message, to re-use the logic there in
1788+
// completing processing of the putative block (without cs_main).
1789+
bool fProcessBLOCKTXN = false;
1790+
CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION);
1791+
1792+
// If we end up treating this as a plain headers message, call that as well
1793+
// without cs_main.
1794+
bool fRevertToHeaderProcessing = false;
1795+
CDataStream vHeadersMsg(SER_NETWORK, PROTOCOL_VERSION);
1796+
17851797
// Keep a CBlock for "optimistic" compactblock reconstructions (see
17861798
// below)
17871799
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
17881800
bool fBlockReconstructed = false;
17891801

1802+
{
17901803
LOCK(cs_main);
17911804
// If AcceptBlockHeader returned true, it set pindex
17921805
assert(pindex);
@@ -1868,9 +1881,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
18681881
// Dirty hack to jump to BLOCKTXN code (TODO: move message handling into their own functions)
18691882
BlockTransactions txn;
18701883
txn.blockhash = cmpctblock.header.GetHash();
1871-
CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION);
18721884
blockTxnMsg << txn;
1873-
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman);
1885+
fProcessBLOCKTXN = true;
18741886
} else {
18751887
req.blockhash = pindex->GetBlockHash();
18761888
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKTXN, req));
@@ -1906,11 +1918,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
19061918
// Dirty hack to process as if it were just a headers message (TODO: move message handling into their own functions)
19071919
std::vector<CBlock> headers;
19081920
headers.push_back(cmpctblock.header);
1909-
CDataStream vHeadersMsg(SER_NETWORK, PROTOCOL_VERSION);
19101921
vHeadersMsg << headers;
1911-
return ProcessMessage(pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams, connman);
1922+
fRevertToHeaderProcessing = true;
19121923
}
19131924
}
1925+
} // cs_main
1926+
1927+
if (fProcessBLOCKTXN)
1928+
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman);
1929+
1930+
if (fRevertToHeaderProcessing)
1931+
return ProcessMessage(pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams, connman);
19141932

19151933
if (fBlockReconstructed) {
19161934
// If we got here, we were able to optimistically reconstruct a

0 commit comments

Comments
 (0)