mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
test: check that mempool msgs lead to disconnect if uploadtarget is reached
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`.
This commit is contained in:
parent
dd5cf38818
commit
b58f009d95
1 changed files with 12 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
||||||
if uploadtarget has been reached.
|
if uploadtarget has been reached.
|
||||||
* Verify that getdata requests for recent blocks are respected even
|
* Verify that getdata requests for recent blocks are respected even
|
||||||
if uploadtarget has been reached.
|
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.
|
* Verify that the upload counters are reset after 24 hours.
|
||||||
"""
|
"""
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
@ -17,6 +18,7 @@ from test_framework.messages import (
|
||||||
CInv,
|
CInv,
|
||||||
MSG_BLOCK,
|
MSG_BLOCK,
|
||||||
msg_getdata,
|
msg_getdata,
|
||||||
|
msg_mempool,
|
||||||
)
|
)
|
||||||
from test_framework.p2p import P2PInterface
|
from test_framework.p2p import P2PInterface
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
@ -165,14 +167,17 @@ class MaxUploadTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.nodes[0].disconnect_p2ps()
|
self.nodes[0].disconnect_p2ps()
|
||||||
|
|
||||||
self.log.info("Restarting node 0 with download permission and 1MB maxuploadtarget")
|
self.log.info("Restarting node 0 with download permission, bloom filter support and 1MB maxuploadtarget")
|
||||||
self.restart_node(0, ["-whitelist=download@127.0.0.1", "-maxuploadtarget=1"])
|
self.restart_node(0, ["-whitelist=download@127.0.0.1", "-peerbloomfilters", "-maxuploadtarget=1"])
|
||||||
# Total limit isn't reached after restart, but 1 MB is too small to serve historical blocks
|
# 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)
|
self.assert_uploadtarget_state(target_reached=False, serve_historical_blocks=False)
|
||||||
|
|
||||||
# Reconnect to self.nodes[0]
|
# Reconnect to self.nodes[0]
|
||||||
peer = self.nodes[0].add_p2p_connection(TestP2PConn())
|
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
|
#retrieve 20 blocks which should be enough to break the 1MB limit
|
||||||
getdata_request.inv = [CInv(MSG_BLOCK, big_new_block)]
|
getdata_request.inv = [CInv(MSG_BLOCK, big_new_block)]
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
|
@ -190,6 +195,11 @@ class MaxUploadTest(BitcoinTestFramework):
|
||||||
assert_equal(len(peer_info), 1) # node is still connected
|
assert_equal(len(peer_info), 1) # node is still connected
|
||||||
assert_equal(peer_info[0]['permissions'], ['download'])
|
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.log.info("Test passing an unparsable value to -maxuploadtarget throws an error")
|
||||||
self.stop_node(0)
|
self.stop_node(0)
|
||||||
self.nodes[0].assert_start_raises_init_error(extra_args=["-maxuploadtarget=abc"], expected_msg="Error: Unable to parse -maxuploadtarget: 'abc'")
|
self.nodes[0].assert_start_raises_init_error(extra_args=["-maxuploadtarget=abc"], expected_msg="Error: Unable to parse -maxuploadtarget: 'abc'")
|
||||||
|
|
Loading…
Add table
Reference in a new issue