Skip to content

Commit b3f8228

Browse files
committed
Merge #15597: net: Generate log entry when blocks messages are received unexpectedly
ef0019e Generate log entry when blocks messages are received unexpectedly. (Patrick Strateman) Pull request description: Currently these are incorrectly logged as an unknown command. Tree-SHA512: dd272388a90b79897f8c1ea6d4c949323fcf75493f3a5b2ec9a26a2cf6a8ee743b497941702f21df8fae0f5b9481444363643379832dbd5053b0cc0b0363de04
2 parents bbc436e + ef0019e commit b3f8228

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/net_processing.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,8 +2541,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
25412541
return true;
25422542
}
25432543

2544-
if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex) // Ignore blocks received while importing
2544+
if (strCommand == NetMsgType::CMPCTBLOCK)
25452545
{
2546+
// Ignore cmpctblock received while importing
2547+
if (fImporting || fReindex) {
2548+
LogPrint(BCLog::NET, "Unexpected cmpctblock message received from peer %d\n", pfrom->GetId());
2549+
return true;
2550+
}
2551+
25462552
CBlockHeaderAndShortTxIDs cmpctblock;
25472553
vRecv >> cmpctblock;
25482554

@@ -2762,8 +2768,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
27622768
return true;
27632769
}
27642770

2765-
if (strCommand == NetMsgType::BLOCKTXN && !fImporting && !fReindex) // Ignore blocks received while importing
2771+
if (strCommand == NetMsgType::BLOCKTXN)
27662772
{
2773+
// Ignore blocktxn received while importing
2774+
if (fImporting || fReindex) {
2775+
LogPrint(BCLog::NET, "Unexpected blocktxn message received from peer %d\n", pfrom->GetId());
2776+
return true;
2777+
}
2778+
27672779
BlockTransactions resp;
27682780
vRecv >> resp;
27692781

@@ -2837,8 +2849,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
28372849
return true;
28382850
}
28392851

2840-
if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) // Ignore headers received while importing
2852+
if (strCommand == NetMsgType::HEADERS)
28412853
{
2854+
// Ignore headers received while importing
2855+
if (fImporting || fReindex) {
2856+
LogPrint(BCLog::NET, "Unexpected headers message received from peer %d\n", pfrom->GetId());
2857+
return true;
2858+
}
2859+
28422860
std::vector<CBlockHeader> headers;
28432861

28442862
// Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks.
@@ -2862,8 +2880,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
28622880
return ProcessHeadersMessage(pfrom, connman, headers, chainparams, should_punish);
28632881
}
28642882

2865-
if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex) // Ignore blocks received while importing
2883+
if (strCommand == NetMsgType::BLOCK)
28662884
{
2885+
// Ignore block received while importing
2886+
if (fImporting || fReindex) {
2887+
LogPrint(BCLog::NET, "Unexpected block message received from peer %d\n", pfrom->GetId());
2888+
return true;
2889+
}
2890+
28672891
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
28682892
vRecv >> *pblock;
28692893

0 commit comments

Comments
 (0)