88import time
99
1010from test_framework import messages
11+ from test_framework .messages import CTxIn , COutPoint , msg_mnping
1112from test_framework .mininode import (
1213 P2PDataStore ,
1314 P2PInterface ,
1415)
1516from test_framework .test_framework import PivxTestFramework
1617from test_framework .util import (
18+ assert_equal ,
1719 hex_str_to_bytes ,
1820 wait_until ,
1921)
22+ from random import getrandbits
2023
2124MSG_LIMIT = 2 * 1024 * 1024 # 2MB, per MAX_PROTOCOL_MESSAGE_LENGTH
2225VALID_DATA_LIMIT = MSG_LIMIT - 5 # Account for the 5-byte length prefix
@@ -52,7 +55,6 @@ def on_getdata(self, message):
5255 if inv .type == 15 : # MNPING
5356 self .send_message (self .vec_mnp [inv .hash ])
5457 self .getdata_count += 1
55- print (self .getdata_count )
5658
5759 def wait_for_p2p_messages (self , n_messages ):
5860 wait_until (lambda : self .getdata_count == n_messages , timeout = 60 )
@@ -74,6 +76,7 @@ def run_test(self):
7476 self .test_addrv2_unrecognized_network ()
7577 self .test_large_inv ()
7678 self .test_resource_exhaustion ()
79+ self .test_fill_askfor ()
7780
7881 def test_magic_bytes (self ):
7982 conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
@@ -206,6 +209,31 @@ def test_large_inv(self):
206209 conn .send_and_ping (msg )
207210 self .nodes [0 ].disconnect_p2ps ()
208211
212+ def test_fill_askfor (self ):
213+ self .nodes [0 ].generate (1 ) # IBD
214+ conn = self .nodes [0 ].add_p2p_connection (InvReceiver ())
215+ self .disable_mocktime ()
216+ invs = []
217+ blockhash = int (self .nodes [0 ].getbestblockhash (), 16 )
218+ total_requests = 100
219+ for _ in range (total_requests ):
220+ mnp = msg_mnping (CTxIn (COutPoint (getrandbits (256 ))), blockhash , int (time .time ()))
221+ hash = mnp .get_hash ()
222+ conn .vec_mnp [hash ] = mnp
223+ invs .append (messages .CInv (15 , hash ))
224+ assert_equal (len (conn .vec_mnp ), total_requests )
225+ assert_equal (len (invs ), total_requests )
226+ msg = messages .msg_inv (invs )
227+ conn .send_message (msg )
228+ conn .wait_for_p2p_messages (total_requests )
229+ # Prior #2611 the node was blocking any follow-up request.
230+ mnp = msg_mnping (CTxIn (COutPoint (getrandbits (256 ))), getrandbits (256 ), int (time .time ()))
231+ conn .vec_mnp [mnp .get_hash ()] = mnp
232+ msg = messages .msg_inv ([messages .CInv (15 , mnp .get_hash ())])
233+ conn .send_and_ping (msg )
234+ conn .wait_for_p2p_messages (total_requests + 1 )
235+ self .nodes [0 ].disconnect_p2ps ()
236+
209237 def test_resource_exhaustion (self ):
210238 conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
211239 conn2 = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
0 commit comments