@@ -315,6 +315,8 @@ def _on_data(self):
315
315
return
316
316
self .recvbuf = self .recvbuf [msglen :]
317
317
318
+ if msg is None : # ignore decoy messages
319
+ return
318
320
assert msg # application layer messages (which aren't decoy messages) are non-empty
319
321
shortid = msg [0 ] # 1-byte short message type ID
320
322
if shortid == 0 :
@@ -364,13 +366,13 @@ def on_message(self, message):
364
366
365
367
# Socket write methods
366
368
367
- def send_message (self , message ):
369
+ def send_message (self , message , is_decoy = False ):
368
370
"""Send a P2P message over the socket.
369
371
370
372
This method takes a P2P payload, builds the P2P header and adds
371
373
the message to the send buffer to be sent over the socket."""
372
374
with self ._send_lock :
373
- tmsg = self .build_message (message )
375
+ tmsg = self .build_message (message , is_decoy )
374
376
self ._log_message ("send" , message )
375
377
return self .send_raw_message (tmsg )
376
378
@@ -388,7 +390,7 @@ def maybe_write():
388
390
389
391
# Class utility methods
390
392
391
- def build_message (self , message ):
393
+ def build_message (self , message , is_decoy = False ):
392
394
"""Build a serialized P2P message"""
393
395
msgtype = message .msgtype
394
396
data = message .serialize ()
@@ -400,7 +402,7 @@ def build_message(self, message):
400
402
tmsg += msgtype
401
403
tmsg += b"\x00 " * (12 - len (msgtype ))
402
404
tmsg += data
403
- return self .v2_state .v2_enc_packet (tmsg )
405
+ return self .v2_state .v2_enc_packet (tmsg , ignore = is_decoy )
404
406
else :
405
407
tmsg = self .magic_bytes
406
408
tmsg += msgtype
@@ -825,7 +827,7 @@ def on_getheaders(self, message):
825
827
if response is not None :
826
828
self .send_message (response )
827
829
828
- def send_blocks_and_test (self , blocks , node , * , success = True , force_send = False , reject_reason = None , expect_disconnect = False , timeout = 60 ):
830
+ def send_blocks_and_test (self , blocks , node , * , success = True , force_send = False , reject_reason = None , expect_disconnect = False , timeout = 60 , is_decoy = False ):
829
831
"""Send blocks to test node and test whether the tip advances.
830
832
831
833
- add all blocks to our block_store
@@ -844,9 +846,11 @@ def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False,
844
846
845
847
reject_reason = [reject_reason ] if reject_reason else []
846
848
with node .assert_debug_log (expected_msgs = reject_reason ):
849
+ if is_decoy : # since decoy messages are ignored by the recipient - no need to wait for response
850
+ force_send = True
847
851
if force_send :
848
852
for b in blocks :
849
- self .send_message (msg_block (block = b ))
853
+ self .send_message (msg_block (block = b ), is_decoy )
850
854
else :
851
855
self .send_message (msg_headers ([CBlockHeader (block ) for block in blocks ]))
852
856
self .wait_until (
0 commit comments