Skip to content

Commit 3bbd843

Browse files
committed
Improve comments/logging in p2p-versionbits-warning.py
1 parent ef2beb2 commit 3bbd843

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

test/functional/feature_versionbits_warning.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
VB_THRESHOLD = 108 # versionbits activation threshold for regtest
2020
VB_TOP_BITS = 0x20000000
2121
VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
22+
VB_UNKNOWN_VERSION = VB_TOP_BITS | (1 << VB_UNKNOWN_BIT)
2223

2324
WARN_UNKNOWN_RULES_MINED = "Unknown block versions being mined! It's possible unknown rules are in effect"
2425
WARN_UNKNOWN_RULES_ACTIVE = "unknown new rules activated (versionbit {})".format(VB_UNKNOWN_BIT)
@@ -41,8 +42,8 @@ def setup_network(self):
4142
self.extra_args = [["-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
4243
self.setup_nodes()
4344

44-
# Send numblocks blocks via peer with version set.
4545
def send_blocks_with_version(self, peer, numblocks, version):
46+
"""Send numblocks blocks to peer with version set"""
4647
tip = self.nodes[0].getbestblockhash()
4748
height = self.nodes[0].getblockcount()
4849
block_time = self.nodes[0].getblockheader(tip)["time"] + 1
@@ -59,47 +60,42 @@ def send_blocks_with_version(self, peer, numblocks, version):
5960
peer.sync_with_ping()
6061

6162
def test_versionbits_in_alert_file(self):
63+
"""Test that the versionbits warning has been written to the alert file.
64+
65+
Note that this is only called after the node is shutdown, so doesn't need
66+
a wait_until wrapper."""
6267
with open(self.alert_filename, 'r', encoding='utf8') as f:
6368
alert_text = f.read()
6469
assert(VB_PATTERN.match(alert_text))
6570

6671
def run_test(self):
67-
# Setup the p2p connection and start up the network thread.
6872
self.nodes[0].add_p2p_connection(TestNode())
69-
7073
network_thread_start()
71-
72-
# Test logic begins here
7374
self.nodes[0].p2p.wait_for_verack()
7475

75-
# 1. Have the node mine one period worth of blocks
76+
# Mine one period worth of blocks
7677
self.nodes[0].generate(VB_PERIOD)
7778

78-
# 2. Now build one period of blocks on the tip, with < VB_THRESHOLD
79-
# blocks signaling some unknown bit.
80-
version = VB_TOP_BITS | (1 << VB_UNKNOWN_BIT)
81-
self.send_blocks_with_version(self.nodes[0].p2p, VB_THRESHOLD - 1, version)
82-
83-
# Fill rest of period with regular version blocks
79+
self.log.info("Check that there is no warning if previous VB_BLOCKS have <VB_THRESHOLD blocks with unknown versionbits version.")
80+
# Build one period of blocks with < VB_THRESHOLD blocks signaling some unknown bit
81+
self.send_blocks_with_version(self.nodes[0].p2p, VB_THRESHOLD - 1, VB_UNKNOWN_VERSION)
8482
self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD + 1)
85-
# Check that we're not getting any versionbit-related errors in
86-
# get*info()
83+
84+
# Check that we're not getting any versionbit-related errors in get*info()
8785
assert(not VB_PATTERN.match(self.nodes[0].getmininginfo()["warnings"]))
8886
assert(not VB_PATTERN.match(self.nodes[0].getnetworkinfo()["warnings"]))
8987

90-
# 3. Now build one period of blocks with >= VB_THRESHOLD blocks signaling
91-
# some unknown bit
92-
self.send_blocks_with_version(self.nodes[0].p2p, VB_THRESHOLD, version)
88+
# Build one period of blocks with VB_THRESHOLD blocks signaling some unknown bit
89+
self.send_blocks_with_version(self.nodes[0].p2p, VB_THRESHOLD, VB_UNKNOWN_VERSION)
9390
self.nodes[0].generate(VB_PERIOD - VB_THRESHOLD)
94-
# Might not get a versionbits-related alert yet, as we should
95-
# have gotten a different alert due to more than 51/100 blocks
96-
# being of unexpected version.
97-
# Check that get*info() shows some kind of error.
91+
92+
self.log.info("Check that there is a warning if <50 blocks in the last 100 were an unknown version")
93+
# Check that get*info() shows the 51/100 unknown block version error.
9894
assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getmininginfo()["warnings"])
9995
assert(WARN_UNKNOWN_RULES_MINED in self.nodes[0].getnetworkinfo()["warnings"])
10096

10197
# Mine a period worth of expected blocks so the generic block-version warning
102-
# is cleared, and restart the node. This should move the versionbit state
98+
# is cleared, and restart the node. This will move the versionbit state
10399
# to ACTIVE.
104100
self.nodes[0].generate(VB_PERIOD)
105101
self.stop_nodes()
@@ -108,6 +104,7 @@ def run_test(self):
108104
pass
109105
self.start_nodes()
110106

107+
self.log.info("Check that there is a warning if previous VB_BLOCKS have >=VB_THRESHOLD blocks with unknown versionbits version.")
111108
# Connecting one block should be enough to generate an error.
112109
self.nodes[0].generate(1)
113110
assert(WARN_UNKNOWN_RULES_ACTIVE in self.nodes[0].getmininginfo()["warnings"])

0 commit comments

Comments
 (0)