7
7
Generate chains with block versions that appear to be signalling unknown
8
8
soft-forks, and test that warning alerts are generated.
9
9
"""
10
-
11
- from test_framework .mininode import *
12
- from test_framework .test_framework import BitcoinTestFramework
13
- from test_framework .util import *
10
+ import os
14
11
import re
12
+
15
13
from test_framework .blocktools import create_block , create_coinbase
14
+ from test_framework .messages import msg_block
15
+ from test_framework .mininode import P2PInterface , network_thread_start
16
+ from test_framework .test_framework import BitcoinTestFramework
16
17
17
- VB_PERIOD = 144 # versionbits period length for regtest
18
- VB_THRESHOLD = 108 # versionbits activation threshold for regtest
18
+ VB_PERIOD = 144 # versionbits period length for regtest
19
+ VB_THRESHOLD = 108 # versionbits activation threshold for regtest
19
20
VB_TOP_BITS = 0x20000000
20
- VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
21
+ VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
21
22
22
23
WARN_UNKNOWN_RULES_MINED = "Unknown block versions being mined! It's possible unknown rules are in effect"
23
24
WARN_UNKNOWN_RULES_ACTIVE = "unknown new rules activated (versionbit {})" .format (VB_UNKNOWN_BIT )
@@ -35,21 +36,21 @@ def set_test_params(self):
35
36
def setup_network (self ):
36
37
self .alert_filename = os .path .join (self .options .tmpdir , "alert.txt" )
37
38
# Open and close to create zero-length file
38
- with open (self .alert_filename , 'w' , encoding = 'utf8' ) as _ :
39
+ with open (self .alert_filename , 'w' , encoding = 'utf8' ):
39
40
pass
40
41
self .extra_args = [["-alertnotify=echo %s >> \" " + self .alert_filename + "\" " ]]
41
42
self .setup_nodes ()
42
43
43
- # Send numblocks blocks via peer with nVersionToUse set.
44
- def send_blocks_with_version (self , peer , numblocks , nVersionToUse ):
44
+ # Send numblocks blocks via peer with version set.
45
+ def send_blocks_with_version (self , peer , numblocks , version ):
45
46
tip = self .nodes [0 ].getbestblockhash ()
46
47
height = self .nodes [0 ].getblockcount ()
47
- block_time = self .nodes [0 ].getblockheader (tip )["time" ]+ 1
48
+ block_time = self .nodes [0 ].getblockheader (tip )["time" ] + 1
48
49
tip = int (tip , 16 )
49
50
50
51
for _ in range (numblocks ):
51
- block = create_block (tip , create_coinbase (height + 1 ), block_time )
52
- block .nVersion = nVersionToUse
52
+ block = create_block (tip , create_coinbase (height + 1 ), block_time )
53
+ block .nVersion = version
53
54
block .solve ()
54
55
peer .send_message (msg_block (block ))
55
56
block_time += 1
@@ -76,8 +77,8 @@ def run_test(self):
76
77
77
78
# 2. Now build one period of blocks on the tip, with < VB_THRESHOLD
78
79
# blocks signaling some unknown bit.
79
- nVersion = VB_TOP_BITS | (1 << VB_UNKNOWN_BIT )
80
- self .send_blocks_with_version (self .nodes [0 ].p2p , VB_THRESHOLD - 1 , nVersion )
80
+ version = VB_TOP_BITS | (1 << VB_UNKNOWN_BIT )
81
+ self .send_blocks_with_version (self .nodes [0 ].p2p , VB_THRESHOLD - 1 , version )
81
82
82
83
# Fill rest of period with regular version blocks
83
84
self .nodes [0 ].generate (VB_PERIOD - VB_THRESHOLD + 1 )
@@ -88,7 +89,7 @@ def run_test(self):
88
89
89
90
# 3. Now build one period of blocks with >= VB_THRESHOLD blocks signaling
90
91
# some unknown bit
91
- self .send_blocks_with_version (self .nodes [0 ].p2p , VB_THRESHOLD , nVersion )
92
+ self .send_blocks_with_version (self .nodes [0 ].p2p , VB_THRESHOLD , version )
92
93
self .nodes [0 ].generate (VB_PERIOD - VB_THRESHOLD )
93
94
# Might not get a versionbits-related alert yet, as we should
94
95
# have gotten a different alert due to more than 51/100 blocks
@@ -103,7 +104,7 @@ def run_test(self):
103
104
self .nodes [0 ].generate (VB_PERIOD )
104
105
self .stop_nodes ()
105
106
# Empty out the alert file
106
- with open (self .alert_filename , 'w' , encoding = 'utf8' ) as _ :
107
+ with open (self .alert_filename , 'w' , encoding = 'utf8' ):
107
108
pass
108
109
self .start_nodes ()
109
110
0 commit comments