Skip to content

Commit 680b0c0

Browse files
committed
Release cs_main before calling ProcessNewBlock (cmpctblock handling)
1 parent 041331e commit 680b0c0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/net_processing.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,11 +1782,19 @@ 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+
17851792
// Keep a CBlock for "optimistic" compactblock reconstructions (see
17861793
// below)
17871794
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
17881795
bool fBlockReconstructed = false;
17891796

1797+
{
17901798
LOCK(cs_main);
17911799
// If AcceptBlockHeader returned true, it set pindex
17921800
assert(pindex);
@@ -1868,9 +1876,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
18681876
// Dirty hack to jump to BLOCKTXN code (TODO: move message handling into their own functions)
18691877
BlockTransactions txn;
18701878
txn.blockhash = cmpctblock.header.GetHash();
1871-
CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION);
18721879
blockTxnMsg << txn;
1873-
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman);
1880+
fProcessBLOCKTXN = true;
18741881
} else {
18751882
req.blockhash = pindex->GetBlockHash();
18761883
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKTXN, req));
@@ -1911,6 +1918,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
19111918
return ProcessMessage(pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams, connman);
19121919
}
19131920
}
1921+
} // cs_main
1922+
1923+
if (fProcessBLOCKTXN)
1924+
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman);
19141925

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

0 commit comments

Comments
 (0)