8
8
if uploadtarget has been reached.
9
9
* Verify that getdata requests for recent blocks are respected even
10
10
if uploadtarget has been reached.
11
+ * Verify that mempool requests lead to a disconnect if uploadtarget has been reached.
11
12
* Verify that the upload counters are reset after 24 hours.
12
13
"""
13
14
from collections import defaultdict
17
18
CInv ,
18
19
MSG_BLOCK ,
19
20
msg_getdata ,
21
+ msg_mempool ,
20
22
)
21
23
from test_framework .p2p import P2PInterface
22
24
from test_framework .test_framework import BitcoinTestFramework
@@ -165,14 +167,17 @@ def run_test(self):
165
167
166
168
self .nodes [0 ].disconnect_p2ps ()
167
169
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"])
170
172
# Total limit isn't reached after restart, but 1 MB is too small to serve historical blocks
171
173
self .assert_uploadtarget_state (target_reached = False , serve_historical_blocks = False )
172
174
173
175
# Reconnect to self.nodes[0]
174
176
peer = self .nodes [0 ].add_p2p_connection (TestP2PConn ())
175
177
178
+ # Sending mempool message shouldn't disconnect peer, as total limit isn't reached yet
179
+ peer .send_and_ping (msg_mempool ())
180
+
176
181
#retrieve 20 blocks which should be enough to break the 1MB limit
177
182
getdata_request .inv = [CInv (MSG_BLOCK , big_new_block )]
178
183
for i in range (20 ):
@@ -190,6 +195,11 @@ def run_test(self):
190
195
assert_equal (len (peer_info ), 1 ) # node is still connected
191
196
assert_equal (peer_info [0 ]['permissions' ], ['download' ])
192
197
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
+
193
203
self .log .info ("Test passing an unparsable value to -maxuploadtarget throws an error" )
194
204
self .stop_node (0 )
195
205
self .nodes [0 ].assert_start_raises_init_error (extra_args = ["-maxuploadtarget=abc" ], expected_msg = "Error: Unable to parse -maxuploadtarget: 'abc'" )
0 commit comments