aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorstratospher <44024636+stratospher@users.noreply.github.com>2022-12-10 20:12:51 +0530
committerstratospher <44024636+stratospher@users.noreply.github.com>2024-01-25 11:10:50 +0530
commit4115cf995647d1a513caecb54a4ff3f51927aa8e (patch)
tree5bde335930337e137daac46b4d22c7e9e602f0a2 /test/functional
parent8c054aa04d33b247744b3747cd5bf3005a013e90 (diff)
[test] Ignore BIP324 decoy messages
Also allow P2PConnection::send_message() to send decoy messages for writing tests.
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/test_framework/p2p.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py
index aa9c093b65..1194c7c88d 100755
--- a/test/functional/test_framework/p2p.py
+++ b/test/functional/test_framework/p2p.py
@@ -315,6 +315,8 @@ class P2PConnection(asyncio.Protocol):
return
self.recvbuf = self.recvbuf[msglen:]
+ if msg is None: # ignore decoy messages
+ return
assert msg # application layer messages (which aren't decoy messages) are non-empty
shortid = msg[0] # 1-byte short message type ID
if shortid == 0:
@@ -364,13 +366,13 @@ class P2PConnection(asyncio.Protocol):
# Socket write methods
- def send_message(self, message):
+ def send_message(self, message, is_decoy=False):
"""Send a P2P message over the socket.
This method takes a P2P payload, builds the P2P header and adds
the message to the send buffer to be sent over the socket."""
with self._send_lock:
- tmsg = self.build_message(message)
+ tmsg = self.build_message(message, is_decoy)
self._log_message("send", message)
return self.send_raw_message(tmsg)
@@ -388,7 +390,7 @@ class P2PConnection(asyncio.Protocol):
# Class utility methods
- def build_message(self, message):
+ def build_message(self, message, is_decoy=False):
"""Build a serialized P2P message"""
msgtype = message.msgtype
data = message.serialize()
@@ -400,7 +402,7 @@ class P2PConnection(asyncio.Protocol):
tmsg += msgtype
tmsg += b"\x00" * (12 - len(msgtype))
tmsg += data
- return self.v2_state.v2_enc_packet(tmsg)
+ return self.v2_state.v2_enc_packet(tmsg, ignore=is_decoy)
else:
tmsg = self.magic_bytes
tmsg += msgtype
@@ -825,7 +827,7 @@ class P2PDataStore(P2PInterface):
if response is not None:
self.send_message(response)
- def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False, reject_reason=None, expect_disconnect=False, timeout=60):
+ def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False, reject_reason=None, expect_disconnect=False, timeout=60, is_decoy=False):
"""Send blocks to test node and test whether the tip advances.
- add all blocks to our block_store
@@ -844,9 +846,11 @@ class P2PDataStore(P2PInterface):
reject_reason = [reject_reason] if reject_reason else []
with node.assert_debug_log(expected_msgs=reject_reason):
+ if is_decoy: # since decoy messages are ignored by the recipient - no need to wait for response
+ force_send = True
if force_send:
for b in blocks:
- self.send_message(msg_block(block=b))
+ self.send_message(msg_block(block=b), is_decoy)
else:
self.send_message(msg_headers([CBlockHeader(block) for block in blocks]))
self.wait_until(