forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: check that mempool msgs lead to disconnect if uploadtarget is r…
…eached Note that another reason for disconnect after receiving a MEMPOOL msg of a peer is if bloom filters are disabled on the node. This case is covered in the functional test `p2p_nobloomfilter_messages.py`.
- Loading branch information
Showing
1 changed file
with
12 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
if uploadtarget has been reached. | ||
* Verify that getdata requests for recent blocks are respected even | ||
if uploadtarget has been reached. | ||
* Verify that mempool requests lead to a disconnect if uploadtarget has been reached. | ||
* Verify that the upload counters are reset after 24 hours. | ||
""" | ||
from collections import defaultdict | ||
|
@@ -17,6 +18,7 @@ | |
CInv, | ||
MSG_BLOCK, | ||
msg_getdata, | ||
msg_mempool, | ||
) | ||
from test_framework.p2p import P2PInterface | ||
from test_framework.test_framework import BitcoinTestFramework | ||
|
@@ -165,14 +167,17 @@ def run_test(self): | |
|
||
self.nodes[0].disconnect_p2ps() | ||
|
||
self.log.info("Restarting node 0 with download permission and 1MB maxuploadtarget") | ||
self.restart_node(0, ["[email protected]", "-maxuploadtarget=1"]) | ||
self.log.info("Restarting node 0 with download permission, bloom filter support and 1MB maxuploadtarget") | ||
self.restart_node(0, ["[email protected]", "-peerbloomfilters", "-maxuploadtarget=1"]) | ||
# Total limit isn't reached after restart, but 1 MB is too small to serve historical blocks | ||
self.assert_uploadtarget_state(target_reached=False, serve_historical_blocks=False) | ||
|
||
# Reconnect to self.nodes[0] | ||
peer = self.nodes[0].add_p2p_connection(TestP2PConn()) | ||
|
||
# Sending mempool message shouldn't disconnect peer, as total limit isn't reached yet | ||
peer.send_and_ping(msg_mempool()) | ||
|
||
#retrieve 20 blocks which should be enough to break the 1MB limit | ||
getdata_request.inv = [CInv(MSG_BLOCK, big_new_block)] | ||
for i in range(20): | ||
|
@@ -190,6 +195,11 @@ def run_test(self): | |
assert_equal(len(peer_info), 1) # node is still connected | ||
assert_equal(peer_info[0]['permissions'], ['download']) | ||
|
||
self.log.info("Peer gets disconnected for a mempool request after limit is reached") | ||
with self.nodes[0].assert_debug_log(expected_msgs=["mempool request with bandwidth limit reached, disconnect peer"]): | ||
peer.send_message(msg_mempool()) | ||
peer.wait_for_disconnect() | ||
|
||
self.log.info("Test passing an unparsable value to -maxuploadtarget throws an error") | ||
self.stop_node(0) | ||
self.nodes[0].assert_start_raises_init_error(extra_args=["-maxuploadtarget=abc"], expected_msg="Error: Unable to parse -maxuploadtarget: 'abc'") | ||
|