@@ -1782,11 +1782,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1782
1782
}
1783
1783
}
1784
1784
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
+
1785
1797
// Keep a CBlock for "optimistic" compactblock reconstructions (see
1786
1798
// below)
1787
1799
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
1788
1800
bool fBlockReconstructed = false ;
1789
1801
1802
+ {
1790
1803
LOCK (cs_main);
1791
1804
// If AcceptBlockHeader returned true, it set pindex
1792
1805
assert (pindex);
@@ -1868,9 +1881,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1868
1881
// Dirty hack to jump to BLOCKTXN code (TODO: move message handling into their own functions)
1869
1882
BlockTransactions txn;
1870
1883
txn.blockhash = cmpctblock.header .GetHash ();
1871
- CDataStream blockTxnMsg (SER_NETWORK, PROTOCOL_VERSION);
1872
1884
blockTxnMsg << txn;
1873
- return ProcessMessage (pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman) ;
1885
+ fProcessBLOCKTXN = true ;
1874
1886
} else {
1875
1887
req.blockhash = pindex->GetBlockHash ();
1876
1888
connman.PushMessage (pfrom, msgMaker.Make (NetMsgType::GETBLOCKTXN, req));
@@ -1906,11 +1918,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1906
1918
// Dirty hack to process as if it were just a headers message (TODO: move message handling into their own functions)
1907
1919
std::vector<CBlock> headers;
1908
1920
headers.push_back (cmpctblock.header );
1909
- CDataStream vHeadersMsg (SER_NETWORK, PROTOCOL_VERSION);
1910
1921
vHeadersMsg << headers;
1911
- return ProcessMessage (pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams, connman) ;
1922
+ fRevertToHeaderProcessing = true ;
1912
1923
}
1913
1924
}
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);
1914
1932
1915
1933
if (fBlockReconstructed ) {
1916
1934
// If we got here, we were able to optimistically reconstruct a
0 commit comments