88if uploadtarget has been reached.
99* Verify that getdata requests for recent blocks are respected even
1010if uploadtarget has been reached.
11+ * Verify that mempool requests lead to a disconnect if uploadtarget has been reached.
1112* Verify that the upload counters are reset after 24 hours.
1213"""
1314from collections import defaultdict
1718 CInv ,
1819 MSG_BLOCK ,
1920 msg_getdata ,
21+ msg_mempool ,
2022)
2123from test_framework .p2p import P2PInterface
2224from test_framework .test_framework import BitcoinTestFramework
@@ -165,14 +167,17 @@ def run_test(self):
165167
166168 self .nodes [0 ].disconnect_p2ps ()
167169
168- self .log .info ("Restarting node 0 with download permission and 1MB maxuploadtarget" )
169- self .
restart_node (
0 , [
"[email protected] " ,
"-maxuploadtarget=1" ])
170+ self .log .info ("Restarting node 0 with download permission, bloom filter support and 1MB maxuploadtarget" )
171+ self .
restart_node (
0 , [
"[email protected] " ,
"-peerbloomfilters" , "- maxuploadtarget=1"])
170172 # Total limit isn't reached after restart, but 1 MB is too small to serve historical blocks
171173 self .assert_uploadtarget_state (target_reached = False , serve_historical_blocks = False )
172174
173175 # Reconnect to self.nodes[0]
174176 peer = self .nodes [0 ].add_p2p_connection (TestP2PConn ())
175177
178+ # Sending mempool message shouldn't disconnect peer, as total limit isn't reached yet
179+ peer .send_and_ping (msg_mempool ())
180+
176181 #retrieve 20 blocks which should be enough to break the 1MB limit
177182 getdata_request .inv = [CInv (MSG_BLOCK , big_new_block )]
178183 for i in range (20 ):
@@ -190,6 +195,11 @@ def run_test(self):
190195 assert_equal (len (peer_info ), 1 ) # node is still connected
191196 assert_equal (peer_info [0 ]['permissions' ], ['download' ])
192197
198+ self .log .info ("Peer gets disconnected for a mempool request after limit is reached" )
199+ with self .nodes [0 ].assert_debug_log (expected_msgs = ["mempool request with bandwidth limit reached, disconnect peer" ]):
200+ peer .send_message (msg_mempool ())
201+ peer .wait_for_disconnect ()
202+
193203 self .log .info ("Test passing an unparsable value to -maxuploadtarget throws an error" )
194204 self .stop_node (0 )
195205 self .nodes [0 ].assert_start_raises_init_error (extra_args = ["-maxuploadtarget=abc" ], expected_msg = "Error: Unable to parse -maxuploadtarget: 'abc'" )
0 commit comments