Skip to content

Commit ed5cd12

Browse files
committed
test: Distinguish between nodes(bitcoind) and peers(mininodes) in p2p_leak.py
Also, remove "C" prefix from class names to match new style
1 parent f6f082b commit ed5cd12

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

test/functional/p2p_leak.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
DISCOURAGEMENT_THRESHOLD = 100
2929

3030

31-
class CLazyNode(P2PInterface):
31+
class LazyPeer(P2PInterface):
3232
def __init__(self):
3333
super().__init__()
3434
self.unexpected_msg = False
@@ -64,8 +64,8 @@ def on_getblocktxn(self, message): self.bad_message(message)
6464
def on_blocktxn(self, message): self.bad_message(message)
6565

6666

67-
# Node that sends a version but not a verack.
68-
class CNodeNoVerackIdle(CLazyNode):
67+
# Peer that sends a version but not a verack.
68+
class NoVerackIdlePeer(LazyPeer):
6969
def __init__(self):
7070
self.version_received = False
7171
super().__init__()
@@ -95,45 +95,44 @@ def set_test_params(self):
9595

9696
def run_test(self):
9797
# Peer that never sends a version. We will send a bunch of messages
98-
# from this node anyway and verify eventual disconnection.
99-
no_version_disconnect_node = self.nodes[0].add_p2p_connection(
100-
CLazyNode(), send_version=False, wait_for_verack=False)
98+
# from this peer anyway and verify eventual disconnection.
99+
no_version_disconnect_peer = self.nodes[0].add_p2p_connection(
100+
LazyPeer(), send_version=False, wait_for_verack=False)
101101

102-
# Another peer that never sends a version. Just sits idle and hopes to receive
103-
# any message (it shouldn't!)
104-
no_version_idlenode = self.nodes[0].add_p2p_connection(CLazyNode(), send_version=False, wait_for_verack=False)
102+
# Another peer that never sends a version, nor any other messages. It shouldn't receive anything from the node.
103+
no_version_idle_peer = self.nodes[0].add_p2p_connection(LazyPeer(), send_version=False, wait_for_verack=False)
105104

106105
# Peer that sends a version but not a verack.
107-
no_verack_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVerackIdle(), wait_for_verack=False)
106+
no_verack_idle_peer = self.nodes[0].add_p2p_connection(NoVerackIdlePeer(), wait_for_verack=False)
108107

109108
# Send enough ping messages (any non-version message will do) prior to sending
110109
# version to reach the peer discouragement threshold. This should get us disconnected.
111110
for _ in range(DISCOURAGEMENT_THRESHOLD):
112-
no_version_disconnect_node.send_message(msg_ping())
111+
no_version_disconnect_peer.send_message(msg_ping())
113112

114-
# Wait until we got the verack in response to the version. Though, don't wait for self.nodes[0] to receive the
113+
# Wait until we got the verack in response to the version. Though, don't wait for the node to receive the
115114
# verack, since we never sent one
116-
no_verack_idlenode.wait_for_verack()
115+
no_verack_idle_peer.wait_for_verack()
117116

118-
wait_until(lambda: no_version_disconnect_node.ever_connected, timeout=10, lock=mininode_lock)
119-
wait_until(lambda: no_version_idlenode.ever_connected, timeout=10, lock=mininode_lock)
120-
wait_until(lambda: no_verack_idlenode.version_received, timeout=10, lock=mininode_lock)
117+
wait_until(lambda: no_version_disconnect_peer.ever_connected, timeout=10, lock=mininode_lock)
118+
wait_until(lambda: no_version_idle_peer.ever_connected, timeout=10, lock=mininode_lock)
119+
wait_until(lambda: no_verack_idle_peer.version_received, timeout=10, lock=mininode_lock)
121120

122-
# Mine a block and make sure that it's not sent to the connected nodes
121+
# Mine a block and make sure that it's not sent to the connected peers
123122
self.nodes[0].generate(nblocks=1)
124123

125124
#Give the node enough time to possibly leak out a message
126125
time.sleep(5)
127126

128-
# Expect this node to be disconnected for misbehavior
129-
assert not no_version_disconnect_node.is_connected
127+
# Expect this peer to be disconnected for misbehavior
128+
assert not no_version_disconnect_peer.is_connected
130129

131130
self.nodes[0].disconnect_p2ps()
132131

133132
# Make sure no unexpected messages came in
134-
assert no_version_disconnect_node.unexpected_msg == False
135-
assert no_version_idlenode.unexpected_msg == False
136-
assert no_verack_idlenode.unexpected_msg == False
133+
assert no_version_disconnect_peer.unexpected_msg == False
134+
assert no_version_idle_peer.unexpected_msg == False
135+
assert no_verack_idle_peer.unexpected_msg == False
137136

138137
self.log.info('Check that the version message does not leak the local address of the node')
139138
p2p_version_store = self.nodes[0].add_p2p_connection(P2PVersionStore())
@@ -146,13 +145,13 @@ def run_test(self):
146145
assert_equal(ver.nStartingHeight, 201)
147146
assert_equal(ver.nRelay, 1)
148147

149-
self.log.info('Check that old nodes are disconnected')
150-
p2p_old_node = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
148+
self.log.info('Check that old peers are disconnected')
149+
p2p_old_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
151150
old_version_msg = msg_version()
152151
old_version_msg.nVersion = 31799
153152
with self.nodes[0].assert_debug_log(['peer=4 using obsolete version 31799; disconnecting']):
154-
p2p_old_node.send_message(old_version_msg)
155-
p2p_old_node.wait_for_disconnect()
153+
p2p_old_peer.send_message(old_version_msg)
154+
p2p_old_peer.wait_for_disconnect()
156155

157156

158157
if __name__ == '__main__':

0 commit comments

Comments
 (0)