Skip to content

Commit faaad1b

Browse files
author
MarcoFalke
committed
p2p: Ignore version msgs after initial version msg
Sending a version message after the intial version message is peer misbehavior. Though, it seems arbitrary and confusing to disconnect only after exactly 100 version messages. Duplicate version messages affect us no different than any other unknown message. So remove the Misbehaving and ignore the redundant msgs.
1 parent fad68af commit faaad1b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,10 +2286,8 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
22862286
if (peer == nullptr) return;
22872287

22882288
if (msg_type == NetMsgType::VERSION) {
2289-
// Each connection can only send one version message
2290-
if (pfrom.nVersion != 0)
2291-
{
2292-
Misbehaving(pfrom.GetId(), 1, "redundant version message");
2289+
if (pfrom.nVersion != 0) {
2290+
LogPrint(BCLog::NET, "redundant version message from peer=%d\n", pfrom.GetId());
22932291
return;
22942292
}
22952293

test/functional/p2p_invalid_messages.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
msg_inv,
1919
msg_ping,
2020
MSG_TX,
21+
msg_version,
2122
ser_string,
2223
)
2324
from test_framework.p2p import (
@@ -60,6 +61,7 @@ def set_test_params(self):
6061

6162
def run_test(self):
6263
self.test_buffer()
64+
self.test_duplicate_version_msg()
6365
self.test_magic_bytes()
6466
self.test_checksum()
6567
self.test_size()
@@ -92,6 +94,13 @@ def test_buffer(self):
9294
conn.sync_with_ping(timeout=1)
9395
self.nodes[0].disconnect_p2ps()
9496

97+
def test_duplicate_version_msg(self):
98+
self.log.info("Test duplicate version message is ignored")
99+
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
100+
with self.nodes[0].assert_debug_log(['redundant version message from peer']):
101+
conn.send_and_ping(msg_version())
102+
self.nodes[0].disconnect_p2ps()
103+
95104
def test_magic_bytes(self):
96105
self.log.info("Test message with invalid magic bytes disconnects peer")
97106
conn = self.nodes[0].add_p2p_connection(P2PDataStore())

0 commit comments

Comments
 (0)