We already disconnect on invalid netmagic (which might also be due to a bit-flip), so disconnecting here is probably fine. However, I think for cleaner code, the two seem related enough to be treated in the same way (either both in net_processing or both in net). No strong opinion where, but for example this is the diff if they are kept in net_processing:
diff --git a/src/net.cpp b/src/net.cpp
index 9950b9aea4..9e213547fa 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -597,6 +597,11 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
vRecvMsg.push_back(std::move(msg));
complete = true;
+
+ if (!msg.m_valid_checksum) {
+ // return early and notify net processing
+ return true;
+ }
}
}
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 6d85b46831..a5606dfe66 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -3499,6 +3499,13 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
}
CNetMessage& msg(msgs.front());
+ if (!msg.m_valid_checksum) {
+ LogPrint(BCLog::NET, "%s(%s, %u bytes): CHECKSUM ERROR peer=%d\n",
+ __func__, SanitizeString(msg.m_command), msg.m_message_size, pfrom->GetId());
+ pfrom->fDisconnect = true;
+ return false;
+ }
+
msg.SetVersion(pfrom->GetRecvVersion());
// Check network magic
if (!msg.m_valid_netmagic) {
@@ -3518,15 +3525,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
// Message size
unsigned int nMessageSize = msg.m_message_size;
- // Checksum
CDataStream& vRecv = msg.m_recv;
- if (!msg.m_valid_checksum)
- {
- LogPrint(BCLog::NET, "%s(%s, %u bytes): CHECKSUM ERROR peer=%d\n", __func__,
- SanitizeString(msg_type), nMessageSize, pfrom->GetId());
- return fMoreWork;
- }
-
// Process message
bool fRet = false;
try