Skip to content

Commit fa8a063

Browse files
author
MarcoFalke
committed
Merge #11001: [tests] Test disconnecting unsupported service bits logic.
5e35cd9 [tests] Test disconnecting unsupported service bits logic. (John Newbery) Pull request description: In v0.15, we disconnect nodes that send us version messages with unsupported service bits (1 << 5 and 1 << 7). This commit adds a test that bitcoind will disconnect those nodes before August 1st 2018, and won't disconnect those nodes after August 1st 2018. @sdaftuar @TheBlueMatt Tree-SHA512: cb1bf311f9edc4aa5acf621e392543fd92952b2462ae2a8c20339e5c41e67ece1a2a9ede38db5dcd16563faa9ee58318e118f54024dd282c580132202d2df01b
2 parents 318392c + 5e35cd9 commit fa8a063

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

test/functional/p2p-leaktests.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
1010
This test connects to a node and sends it a few messages, trying to intice it
1111
into sending us something it shouldn't.
12-
"""
12+
13+
Also test that nodes that send unsupported service bits to bitcoind are disconnected
14+
and don't receive a VERACK. Unsupported service bits are currently 1 << 5 and
15+
1 << 7 (until August 1st 2018)."""
1316

1417
from test_framework.mininode import *
1518
from test_framework.test_framework import BitcoinTestFramework
@@ -98,20 +101,29 @@ def run_test(self):
98101
no_version_bannode = CNodeNoVersionBan()
99102
no_version_idlenode = CNodeNoVersionIdle()
100103
no_verack_idlenode = CNodeNoVerackIdle()
104+
unsupported_service_bit5_node = CLazyNode()
105+
unsupported_service_bit7_node = CLazyNode()
101106

107+
self.nodes[0].setmocktime(1501545600) # August 1st 2017
102108
connections = []
103109
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], no_version_bannode, send_version=False))
104110
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], no_version_idlenode, send_version=False))
105111
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], no_verack_idlenode))
112+
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], unsupported_service_bit5_node, services=NODE_NETWORK|NODE_UNSUPPORTED_SERVICE_BIT_5))
113+
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], unsupported_service_bit7_node, services=NODE_NETWORK|NODE_UNSUPPORTED_SERVICE_BIT_7))
106114
no_version_bannode.add_connection(connections[0])
107115
no_version_idlenode.add_connection(connections[1])
108116
no_verack_idlenode.add_connection(connections[2])
117+
unsupported_service_bit5_node.add_connection(connections[3])
118+
unsupported_service_bit7_node.add_connection(connections[4])
109119

110120
NetworkThread().start() # Start up network handling in another thread
111121

112122
assert wait_until(lambda: no_version_bannode.ever_connected, timeout=10)
113123
assert wait_until(lambda: no_version_idlenode.ever_connected, timeout=10)
114124
assert wait_until(lambda: no_verack_idlenode.version_received, timeout=10)
125+
assert wait_until(lambda: unsupported_service_bit5_node.ever_connected, timeout=10)
126+
assert wait_until(lambda: unsupported_service_bit7_node.ever_connected, timeout=10)
115127

116128
# Mine a block and make sure that it's not sent to the connected nodes
117129
self.nodes[0].generate(1)
@@ -122,12 +134,32 @@ def run_test(self):
122134
#This node should have been banned
123135
assert not no_version_bannode.connected
124136

137+
# These nodes should have been disconnected
138+
assert not unsupported_service_bit5_node.connected
139+
assert not unsupported_service_bit7_node.connected
140+
125141
[conn.disconnect_node() for conn in connections]
126142

127143
# Make sure no unexpected messages came in
128144
assert(no_version_bannode.unexpected_msg == False)
129145
assert(no_version_idlenode.unexpected_msg == False)
130146
assert(no_verack_idlenode.unexpected_msg == False)
147+
assert not unsupported_service_bit5_node.unexpected_msg
148+
assert not unsupported_service_bit7_node.unexpected_msg
149+
150+
self.log.info("Service bits 5 and 7 are allowed after August 1st 2018")
151+
self.nodes[0].setmocktime(1533168000) # August 2nd 2018
152+
153+
allowed_service_bit5_node = NodeConnCB()
154+
allowed_service_bit7_node = NodeConnCB()
155+
156+
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], allowed_service_bit5_node, services=NODE_NETWORK|NODE_UNSUPPORTED_SERVICE_BIT_5))
157+
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], allowed_service_bit7_node, services=NODE_NETWORK|NODE_UNSUPPORTED_SERVICE_BIT_7))
158+
allowed_service_bit5_node.add_connection(connections[5])
159+
allowed_service_bit7_node.add_connection(connections[6])
160+
161+
assert wait_until(lambda: allowed_service_bit5_node.message_count["verack"], timeout=10)
162+
assert wait_until(lambda: allowed_service_bit7_node.message_count["verack"], timeout=10)
131163

132164
if __name__ == '__main__':
133165
P2PLeakTest().main()

test/functional/test_framework/mininode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
NODE_GETUTXO = (1 << 1)
5252
NODE_BLOOM = (1 << 2)
5353
NODE_WITNESS = (1 << 3)
54+
NODE_UNSUPPORTED_SERVICE_BIT_5 = (1 << 5)
55+
NODE_UNSUPPORTED_SERVICE_BIT_7 = (1 << 7)
5456

5557
logger = logging.getLogger("TestFramework.mininode")
5658

0 commit comments

Comments
 (0)