Skip to content

Commit f324772

Browse files
achow101vijaydasmp
authored andcommitted
Merge bitcoin#27712: test: p2p: check misbehavior for non-continuous headers messages
a97c59f test: p2p: check misbehavior for non-continuous headers messages (Sebastian Falbesoner) Pull request description: This PR adds missing test coverage for a peer sending a `headers` message where the headers don't connect to each other, which should be treated as misbehaving (not disconnecting though, as the score increase is only 20). The relevant code path is `PeerManagerImpl::ProcessHeadersMessage` -> `PeerManagerImpl::CheckHeadersPoW` -> `PeerManagerImpl::CheckHeadersAreContinuous`: https://github.com/bitcoin/bitcoin/blob/17acb2782a66f033238340e4fb81009e7f79e97a/src/net_processing.cpp#L2415-L2419 https://github.com/bitcoin/bitcoin/blob/17acb2782a66f033238340e4fb81009e7f79e97a/src/net_processing.cpp#L2474-L2484 ACKs for top commit: sr-gi: ACK bitcoin@a97c59f achow101: ACK a97c59f instagibbs: ACK a97c59f Tree-SHA512: 3f8d6a2492e5c8b63c7b11be2e4ec455f83581b2c58f2d4e705baadfe8d7c6377296d6cd0eda679d291a13d8930b09443f8e3d183795df34b780c703d5d3aeb3
1 parent 6bc15bc commit f324772

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test node responses to invalid network messages."""
66

7+
import random
8+
79

810
from test_framework.messages import (
911
CBlockHeader,
@@ -61,7 +63,7 @@ def run_test(self):
6163
self.test_oversized_inv_msg()
6264
self.test_oversized_getdata_msg()
6365
self.test_oversized_headers_msg()
64-
self.test_resource_exhaustion()
66+
self.test_noncontinuous_headers_msg()
6567

6668
def test_buffer(self):
6769
self.log.info("Test message with header split across two buffers is received")
@@ -186,6 +188,25 @@ def test_oversized_headers2_msg(self):
186188
size = MAX_HEADERS_COMPRESSED_RESULT + 1
187189
self.test_oversized_msg(msg_headers2([CBlockHeader()] * size), size)
188190

191+
def test_noncontinuous_headers_msg(self):
192+
self.log.info("Test headers message with non-continuous headers sequence is logged as misbehaving")
193+
block_hashes = self.generate(self.nodes[0], 10)
194+
block_headers = []
195+
for block_hash in block_hashes:
196+
block_headers.append(from_hex(CBlockHeader(), self.nodes[0].getblockheader(block_hash, False)))
197+
198+
# continuous headers sequence should be fine
199+
MISBEHAVING_NONCONTINUOUS_HEADERS_MSGS = ['Misbehaving', 'non-continuous headers sequence']
200+
peer = self.nodes[0].add_p2p_connection(P2PInterface())
201+
with self.nodes[0].assert_debug_log([], unexpected_msgs=MISBEHAVING_NONCONTINUOUS_HEADERS_MSGS):
202+
peer.send_and_ping(msg_headers(block_headers))
203+
204+
# delete arbitrary block header somewhere in the middle to break link
205+
del block_headers[random.randrange(1, len(block_headers)-1)]
206+
with self.nodes[0].assert_debug_log(expected_msgs=MISBEHAVING_NONCONTINUOUS_HEADERS_MSGS):
207+
peer.send_and_ping(msg_headers(block_headers))
208+
self.nodes[0].disconnect_p2ps()
209+
189210
def test_resource_exhaustion(self):
190211
self.log.info("Test node stays up despite many large junk messages")
191212
# Don't use v2 here - the non-optimised encryption would take too long to encrypt

0 commit comments

Comments
 (0)