Skip to content

Commit 45cf55c

Browse files
committed
test: remove CNodeNoVersionMisbehavior from p2p_leak.py
It's also clearer to have `no_version_disconnect_node` send a message other than version or verack in order to reach the peer discouragement threshold.
1 parent 7e31ea9 commit 45cf55c

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

test/functional/p2p_leak.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from test_framework.messages import (
1616
msg_getaddr,
1717
msg_ping,
18-
msg_verack,
1918
msg_version,
2019
)
2120
from test_framework.mininode import mininode_lock, P2PInterface
@@ -42,6 +41,7 @@ def bad_message(self, message):
4241
def on_open(self):
4342
self.ever_connected = True
4443

44+
# Does not respond to "version" with "verack"
4545
def on_version(self, message): self.bad_message(message)
4646
def on_verack(self, message): self.bad_message(message)
4747
def on_inv(self, message): self.bad_message(message)
@@ -64,12 +64,6 @@ def on_getblocktxn(self, message): self.bad_message(message)
6464
def on_blocktxn(self, message): self.bad_message(message)
6565

6666

67-
# Node that never sends a version. We'll use this to send a bunch of messages
68-
# anyway, and eventually get disconnected.
69-
class CNodeNoVersionMisbehavior(CLazyNode):
70-
pass
71-
72-
7367
# Node that never sends a version. This one just sits idle and hopes to receive
7468
# any message (it shouldn't!)
7569
class CNodeNoVersionIdle(CLazyNode):
@@ -97,6 +91,7 @@ class P2PVersionStore(P2PInterface):
9791
version_received = None
9892

9993
def on_version(self, msg):
94+
# Responds with an appropriate verack
10095
super().on_version(msg)
10196
self.version_received = msg
10297

@@ -106,15 +101,17 @@ def set_test_params(self):
106101
self.num_nodes = 1
107102

108103
def run_test(self):
104+
# Peer that never sends a version. We will send a bunch of messages
105+
# from this node anyway and verify eventual disconnection.
109106
no_version_disconnect_node = self.nodes[0].add_p2p_connection(
110-
CNodeNoVersionMisbehavior(), send_version=False, wait_for_verack=False)
107+
CLazyNode(), send_version=False, wait_for_verack=False)
111108
no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False)
112109
no_verack_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVerackIdle(), wait_for_verack=False)
113110

114-
# Send enough veracks without a message to reach the peer discouragement
115-
# threshold. This should get us disconnected.
111+
# Send enough ping messages (any non-version message will do) prior to sending
112+
# version to reach the peer discouragement threshold. This should get us disconnected.
116113
for _ in range(DISCOURAGEMENT_THRESHOLD):
117-
no_version_disconnect_node.send_message(msg_verack())
114+
no_version_disconnect_node.send_message(msg_ping())
118115

119116
# Wait until we got the verack in response to the version. Though, don't wait for the other node to receive the
120117
# verack, since we never sent one
@@ -125,7 +122,7 @@ def run_test(self):
125122
wait_until(lambda: no_verack_idlenode.version_received, timeout=10, lock=mininode_lock)
126123

127124
# Mine a block and make sure that it's not sent to the connected nodes
128-
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
125+
self.nodes[0].generate(nblocks=1)
129126

130127
#Give the node enough time to possibly leak out a message
131128
time.sleep(5)

0 commit comments

Comments
 (0)