Skip to content

Commit

Permalink
test: check that mempool msgs lead to disconnect if uploadtarget is r…
Browse files Browse the repository at this point in the history
…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
theStack committed Feb 5, 2024
1 parent dd5cf38 commit b58f009
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/functional/feature_maxuploadtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +18,7 @@
CInv,
MSG_BLOCK,
msg_getdata,
msg_mempool,
)
from test_framework.p2p import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
Expand Down Expand Up @@ -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):
Expand All @@ -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'")
Expand Down

0 comments on commit b58f009

Please sign in to comment.