@@ -57,7 +57,7 @@ def run_test(self):
57
57
self .test_resource_exhaustion ()
58
58
59
59
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" )
61
61
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
62
62
# Create valid message
63
63
msg = conn .build_message (msg_ping (nonce = 12345 ))
@@ -76,6 +76,7 @@ def test_buffer(self):
76
76
self .nodes [0 ].disconnect_p2ps ()
77
77
78
78
def test_magic_bytes (self ):
79
+ self .log .info ("Test message with invalid magic bytes disconnects peer" )
79
80
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
80
81
with self .nodes [0 ].assert_debug_log (['PROCESSMESSAGE: INVALID MESSAGESTART badmsg' ]):
81
82
msg = conn .build_message (msg_unrecognized (str_data = "d" ))
@@ -86,6 +87,7 @@ def test_magic_bytes(self):
86
87
self .nodes [0 ].disconnect_p2ps ()
87
88
88
89
def test_checksum (self ):
90
+ self .log .info ("Test message with invalid checksum logs an error" )
89
91
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
90
92
with self .nodes [0 ].assert_debug_log (['CHECKSUM ERROR (badmsg, 2 bytes), expected 78df0a04 was ffffffff' ]):
91
93
msg = conn .build_message (msg_unrecognized (str_data = "d" ))
@@ -98,16 +100,17 @@ def test_checksum(self):
98
100
self .nodes [0 ].disconnect_p2ps ()
99
101
100
102
def test_size (self ):
103
+ self .log .info ("Test message with oversized payload disconnects peer" )
101
104
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
102
105
with self .nodes [0 ].assert_debug_log (['' ]):
103
- # Create a message with oversized payload
104
106
msg = msg_unrecognized (str_data = "d" * (VALID_DATA_LIMIT + 1 ))
105
107
msg = conn .build_message (msg )
106
108
self .nodes [0 ].p2p .send_raw_message (msg )
107
109
conn .wait_for_disconnect (timeout = 1 )
108
110
self .nodes [0 ].disconnect_p2ps ()
109
111
110
112
def test_msgtype (self ):
113
+ self .log .info ("Test message with invalid message type logs an error" )
111
114
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
112
115
with self .nodes [0 ].assert_debug_log (['PROCESSMESSAGE: ERRORS IN HEADER' ]):
113
116
msg = msg_unrecognized (str_data = "d" )
@@ -120,6 +123,7 @@ def test_msgtype(self):
120
123
self .nodes [0 ].disconnect_p2ps ()
121
124
122
125
def test_large_inv (self ):
126
+ self .log .info ("Test oversized inv/getdata/headers messages are logged as misbehaving" )
123
127
conn = self .nodes [0 ].add_p2p_connection (P2PInterface ())
124
128
with self .nodes [0 ].assert_debug_log (['Misbehaving' , '(0 -> 20): inv message size = 50001' ]):
125
129
msg = msg_inv ([CInv (MSG_TX , 1 )] * 50001 )
@@ -133,25 +137,26 @@ def test_large_inv(self):
133
137
self .nodes [0 ].disconnect_p2ps ()
134
138
135
139
def test_resource_exhaustion (self ):
140
+ self .log .info ("Test node stays up despite many large junk messages" )
136
141
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
137
142
conn2 = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
138
143
msg_at_size = msg_unrecognized (str_data = "b" * VALID_DATA_LIMIT )
139
144
assert len (msg_at_size .serialize ()) == MSG_LIMIT
140
145
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)" )
144
147
for _ in range (80 ):
145
148
conn .send_message (msg_at_size )
146
149
147
150
# Check that, even though the node is being hammered by nonsense from one
148
151
# 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" )
149
153
for _ in range (20 ):
150
154
conn2 .sync_with_ping (timeout = 2 )
151
155
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" )
154
157
conn .sync_with_ping (timeout = 400 )
158
+
159
+ # Peer 1, despite being served up a bunch of nonsense, should still be connected.
155
160
assert conn .is_connected
156
161
self .nodes [0 ].disconnect_p2ps ()
157
162
0 commit comments