Skip to content

Commit e2b21d8

Browse files
committed
test: add p2p_invalid_messages logging
1 parent 9fa494d commit e2b21d8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def run_test(self):
5757
self.test_resource_exhaustion()
5858

5959
def test_buffer(self):
60-
self.log.info("Test message with header split across two buffers, should be received")
60+
self.log.info("Test message with header split across two buffers is received")
6161
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
6262
# Create valid message
6363
msg = conn.build_message(msg_ping(nonce=12345))
@@ -76,6 +76,7 @@ def test_buffer(self):
7676
self.nodes[0].disconnect_p2ps()
7777

7878
def test_magic_bytes(self):
79+
self.log.info("Test message with invalid magic bytes disconnects peer")
7980
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
8081
with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART badmsg']):
8182
msg = conn.build_message(msg_unrecognized(str_data="d"))
@@ -86,6 +87,7 @@ def test_magic_bytes(self):
8687
self.nodes[0].disconnect_p2ps()
8788

8889
def test_checksum(self):
90+
self.log.info("Test message with invalid checksum logs an error")
8991
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
9092
with self.nodes[0].assert_debug_log(['CHECKSUM ERROR (badmsg, 2 bytes), expected 78df0a04 was ffffffff']):
9193
msg = conn.build_message(msg_unrecognized(str_data="d"))
@@ -98,16 +100,17 @@ def test_checksum(self):
98100
self.nodes[0].disconnect_p2ps()
99101

100102
def test_size(self):
103+
self.log.info("Test message with oversized payload disconnects peer")
101104
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
102105
with self.nodes[0].assert_debug_log(['']):
103-
# Create a message with oversized payload
104106
msg = msg_unrecognized(str_data="d" * (VALID_DATA_LIMIT + 1))
105107
msg = conn.build_message(msg)
106108
self.nodes[0].p2p.send_raw_message(msg)
107109
conn.wait_for_disconnect(timeout=1)
108110
self.nodes[0].disconnect_p2ps()
109111

110112
def test_msgtype(self):
113+
self.log.info("Test message with invalid message type logs an error")
111114
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
112115
with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: ERRORS IN HEADER']):
113116
msg = msg_unrecognized(str_data="d")
@@ -120,6 +123,7 @@ def test_msgtype(self):
120123
self.nodes[0].disconnect_p2ps()
121124

122125
def test_large_inv(self):
126+
self.log.info("Test oversized inv/getdata/headers messages are logged as misbehaving")
123127
conn = self.nodes[0].add_p2p_connection(P2PInterface())
124128
with self.nodes[0].assert_debug_log(['Misbehaving', '(0 -> 20): inv message size = 50001']):
125129
msg = msg_inv([CInv(MSG_TX, 1)] * 50001)
@@ -133,25 +137,26 @@ def test_large_inv(self):
133137
self.nodes[0].disconnect_p2ps()
134138

135139
def test_resource_exhaustion(self):
140+
self.log.info("Test node stays up despite many large junk messages")
136141
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
137142
conn2 = self.nodes[0].add_p2p_connection(P2PDataStore())
138143
msg_at_size = msg_unrecognized(str_data="b" * VALID_DATA_LIMIT)
139144
assert len(msg_at_size.serialize()) == MSG_LIMIT
140145

141-
self.log.info("Sending a bunch of large, junk messages to test memory exhaustion. May take a bit...")
142-
143-
# Run a bunch of times to test for memory exhaustion.
146+
self.log.info("(a) Send 80 messages, each of maximum valid data size (4MB)")
144147
for _ in range(80):
145148
conn.send_message(msg_at_size)
146149

147150
# Check that, even though the node is being hammered by nonsense from one
148151
# connection, it can still service other peers in a timely way.
152+
self.log.info("(b) Check node still services peers in a timely way")
149153
for _ in range(20):
150154
conn2.sync_with_ping(timeout=2)
151155

152-
# Peer 1, despite being served up a bunch of nonsense, should still be connected.
153-
self.log.info("Waiting for node to drop junk messages.")
156+
self.log.info("(c) Wait for node to drop junk messages, while remaining connected")
154157
conn.sync_with_ping(timeout=400)
158+
159+
# Peer 1, despite being served up a bunch of nonsense, should still be connected.
155160
assert conn.is_connected
156161
self.nodes[0].disconnect_p2ps()
157162

0 commit comments

Comments
 (0)