|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test node responses to invalid network messages."""
|
6 | 6 |
|
| 7 | +import random |
7 | 8 | import struct
|
8 | 9 | import time
|
9 | 10 |
|
@@ -75,6 +76,7 @@ def run_test(self):
|
75 | 76 | self.test_oversized_getdata_msg()
|
76 | 77 | self.test_oversized_headers_msg()
|
77 | 78 | self.test_invalid_pow_headers_msg()
|
| 79 | + self.test_noncontinuous_headers_msg() |
78 | 80 | self.test_resource_exhaustion()
|
79 | 81 |
|
80 | 82 | def test_buffer(self):
|
@@ -283,6 +285,25 @@ def test_invalid_pow_headers_msg(self):
|
283 | 285 | peer.send_message(msg_headers([blockheader]))
|
284 | 286 | peer.wait_for_disconnect()
|
285 | 287 |
|
| 288 | + def test_noncontinuous_headers_msg(self): |
| 289 | + self.log.info("Test headers message with non-continuous headers sequence is logged as misbehaving") |
| 290 | + block_hashes = self.generate(self.nodes[0], 10) |
| 291 | + block_headers = [] |
| 292 | + for block_hash in block_hashes: |
| 293 | + block_headers.append(from_hex(CBlockHeader(), self.nodes[0].getblockheader(block_hash, False))) |
| 294 | + |
| 295 | + # continuous headers sequence should be fine |
| 296 | + MISBEHAVING_NONCONTINUOUS_HEADERS_MSGS = ['Misbehaving', 'non-continuous headers sequence'] |
| 297 | + peer = self.nodes[0].add_p2p_connection(P2PInterface()) |
| 298 | + with self.nodes[0].assert_debug_log([], unexpected_msgs=MISBEHAVING_NONCONTINUOUS_HEADERS_MSGS): |
| 299 | + peer.send_and_ping(msg_headers(block_headers)) |
| 300 | + |
| 301 | + # delete arbitrary block header somewhere in the middle to break link |
| 302 | + del block_headers[random.randrange(1, len(block_headers)-1)] |
| 303 | + with self.nodes[0].assert_debug_log(expected_msgs=MISBEHAVING_NONCONTINUOUS_HEADERS_MSGS): |
| 304 | + peer.send_and_ping(msg_headers(block_headers)) |
| 305 | + self.nodes[0].disconnect_p2ps() |
| 306 | + |
286 | 307 | def test_resource_exhaustion(self):
|
287 | 308 | self.log.info("Test node stays up despite many large junk messages")
|
288 | 309 | conn = self.nodes[0].add_p2p_connection(P2PDataStore())
|
|
0 commit comments