Skip to content

Commit ef0019e

Browse files
committed
Generate log entry when blocks messages are received unexpectedly.
1 parent 8e1704c commit ef0019e

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
@@ -2540,8 +2540,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
25402540
return true;
25412541
}
25422542

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)