From faaad1bbac46cfeb22654b4c59f0aac7a680c03a Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 5 Oct 2020 16:21:59 +0200 Subject: [PATCH] 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. --- src/net_processing.cpp | 6 ++---- test/functional/p2p_invalid_messages.py | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index df97d0e2e7e..f21fb8a49bf 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2286,10 +2286,8 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat if (peer == nullptr) return; if (msg_type == NetMsgType::VERSION) { - // Each connection can only send one version message - if (pfrom.nVersion != 0) - { - Misbehaving(pfrom.GetId(), 1, "redundant version message"); + if (pfrom.nVersion != 0) { + LogPrint(BCLog::NET, "redundant version message from peer=%d\n", pfrom.GetId()); return; } diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py index db72a361d98..c0b3c2cb12e 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -18,6 +18,7 @@ from test_framework.messages import ( msg_inv, msg_ping, MSG_TX, + msg_version, ser_string, ) from test_framework.p2p import ( @@ -60,6 +61,7 @@ class InvalidMessagesTest(BitcoinTestFramework): def run_test(self): self.test_buffer() + self.test_duplicate_version_msg() self.test_magic_bytes() self.test_checksum() self.test_size() @@ -92,6 +94,13 @@ class InvalidMessagesTest(BitcoinTestFramework): conn.sync_with_ping(timeout=1) self.nodes[0].disconnect_p2ps() + def test_duplicate_version_msg(self): + self.log.info("Test duplicate version message is ignored") + conn = self.nodes[0].add_p2p_connection(P2PDataStore()) + with self.nodes[0].assert_debug_log(['redundant version message from peer']): + conn.send_and_ping(msg_version()) + self.nodes[0].disconnect_p2ps() + def test_magic_bytes(self): self.log.info("Test message with invalid magic bytes disconnects peer") conn = self.nodes[0].add_p2p_connection(P2PDataStore())