Skip to content

Commit

Permalink
Move size limits to module-global
Browse files Browse the repository at this point in the history
As well, this renames those variables to match PEP8 and this clears up
the comment relating to VALID_DATA_LIMIT.

Admittedly, this commit is mainly to make the following ones cleaner.
  • Loading branch information
troygiorshev committed Jun 8, 2020
1 parent 57890ab commit ff1e7b8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/functional/p2p_invalid_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
)
from test_framework.test_framework import BitcoinTestFramework

MSG_LIMIT = 4 * 1000 * 1000 # 4MB, per MAX_PROTOCOL_MESSAGE_LENGTH
VALID_DATA_LIMIT = MSG_LIMIT - 5 # Account for the 5-byte length prefix

class msg_unrecognized:
"""Nonsensical message. Modeled after similar types in test_framework.messages."""
Expand Down Expand Up @@ -61,17 +63,15 @@ def run_test(self):
node.add_p2p_connection(P2PDataStore())
conn2 = node.add_p2p_connection(P2PDataStore())

msg_limit = 4 * 1000 * 1000 # 4MB, per MAX_PROTOCOL_MESSAGE_LENGTH
valid_data_limit = msg_limit - 5 # Account for the 4-byte length prefix

#
# 0.
#
# Send as large a message as is valid, ensure we aren't disconnected but
# also can't exhaust resources.
#
msg_at_size = msg_unrecognized(str_data="b" * valid_data_limit)
assert len(msg_at_size.serialize()) == msg_limit
msg_at_size = msg_unrecognized(str_data="b" * VALID_DATA_LIMIT)
assert len(msg_at_size.serialize()) == MSG_LIMIT

self.log.info("Sending a bunch of large, junk messages to test memory exhaustion. May take a bit...")

Expand Down

0 comments on commit ff1e7b8

Please sign in to comment.