@@ -47,9 +47,9 @@ def sigterm_node():
47
47
node .process .terminate ()
48
48
node .process .wait ()
49
49
50
- def start_expecting_error (err_fragment ):
50
+ def start_expecting_error (err_fragment , args ):
51
51
node .assert_start_raises_init_error (
52
- extra_args = [ '-txindex=1' , '-blockfilterindex=1' , '-coinstatsindex=1' , '-checkblocks=200' , '-checklevel=4' ] ,
52
+ extra_args = args ,
53
53
expected_msg = err_fragment ,
54
54
match = ErrorMatch .PARTIAL_REGEX ,
55
55
)
@@ -102,37 +102,84 @@ def check_clean_start():
102
102
103
103
self .log .info ("Test startup errors after removing certain essential files" )
104
104
105
- files_to_delete = {
106
- 'blocks/index/*.ldb' : 'Error opening block database.' ,
107
- 'chainstate/*.ldb' : 'Error opening coins database.' ,
108
- 'blocks/blk*.dat' : 'Error loading block database.' ,
109
- 'indexes/txindex/MANIFEST*' : 'LevelDB error: Corruption: CURRENT points to a non-existent file' ,
105
+ deletion_rounds = [
106
+ {
107
+ 'filepath_glob' : 'blocks/index/*.ldb' ,
108
+ 'error_message' : 'Error opening block database.' ,
109
+ 'startup_args' : [],
110
+ },
111
+ {
112
+ 'filepath_glob' : 'chainstate/*.ldb' ,
113
+ 'error_message' : 'Error opening coins database.' ,
114
+ 'startup_args' : ['-checklevel=4' ],
115
+ },
116
+ {
117
+ 'filepath_glob' : 'blocks/blk*.dat' ,
118
+ 'error_message' : 'Error loading block database.' ,
119
+ 'startup_args' : ['-checkblocks=200' , '-checklevel=4' ],
120
+ },
121
+ {
122
+ 'filepath_glob' : 'indexes/txindex/MANIFEST*' ,
123
+ 'error_message' : 'LevelDB error: Corruption: CURRENT points to a non-existent file' ,
124
+ 'startup_args' : ['-txindex=1' ],
125
+ },
110
126
# Removing these files does not result in a startup error:
111
127
# 'indexes/blockfilter/basic/*.dat', 'indexes/blockfilter/basic/db/*.*', 'indexes/coinstats/db/*.*',
112
128
# 'indexes/txindex/*.log', 'indexes/txindex/CURRENT', 'indexes/txindex/LOCK'
113
- }
114
-
115
- files_to_perturb = {
116
- 'blocks/index/*.ldb' : 'Error loading block database.' ,
117
- 'chainstate/*.ldb' : 'Error opening coins database.' ,
118
- 'blocks/blk*.dat' : 'Corrupted block database detected.' ,
119
- 'indexes/blockfilter/basic/db/*.*' : 'LevelDB error: Corruption' ,
120
- 'indexes/coinstats/db/*.*' : 'LevelDB error: Corruption' ,
121
- 'indexes/txindex/*.log' : 'LevelDB error: Corruption' ,
122
- 'indexes/txindex/CURRENT' : 'LevelDB error: Corruption' ,
129
+ ]
130
+
131
+ perturbation_rounds = [
132
+ {
133
+ 'filepath_glob' : 'blocks/index/*.ldb' ,
134
+ 'error_message' : 'Error loading block database.' ,
135
+ 'startup_args' : [],
136
+ },
137
+ {
138
+ 'filepath_glob' : 'chainstate/*.ldb' ,
139
+ 'error_message' : 'Error opening coins database.' ,
140
+ 'startup_args' : [],
141
+ },
142
+ {
143
+ 'filepath_glob' : 'blocks/blk*.dat' ,
144
+ 'error_message' : 'Corrupted block database detected.' ,
145
+ 'startup_args' : ['-checkblocks=200' , '-checklevel=4' ],
146
+ },
147
+ {
148
+ 'filepath_glob' : 'indexes/blockfilter/basic/db/*.*' ,
149
+ 'error_message' : 'LevelDB error: Corruption' ,
150
+ 'startup_args' : ['-blockfilterindex=1' ],
151
+ },
152
+ {
153
+ 'filepath_glob' : 'indexes/coinstats/db/*.*' ,
154
+ 'error_message' : 'LevelDB error: Corruption' ,
155
+ 'startup_args' : ['-coinstatsindex=1' ],
156
+ },
157
+ {
158
+ 'filepath_glob' : 'indexes/txindex/*.log' ,
159
+ 'error_message' : 'LevelDB error: Corruption' ,
160
+ 'startup_args' : ['-txindex=1' ],
161
+ },
162
+ {
163
+ 'filepath_glob' : 'indexes/txindex/CURRENT' ,
164
+ 'error_message' : 'LevelDB error: Corruption' ,
165
+ 'startup_args' : ['-txindex=1' ],
166
+ },
123
167
# Perturbing these files does not result in a startup error:
124
168
# 'indexes/blockfilter/basic/*.dat', 'indexes/txindex/MANIFEST*', 'indexes/txindex/LOCK'
125
- }
169
+ ]
126
170
127
- for file_patt , err_fragment in files_to_delete .items ():
171
+ for round_info in deletion_rounds :
172
+ file_patt = round_info ['filepath_glob' ]
173
+ err_fragment = round_info ['error_message' ]
174
+ startup_args = round_info ['startup_args' ]
128
175
target_files = list (node .chain_path .glob (file_patt ))
129
176
130
177
for target_file in target_files :
131
178
self .log .info (f"Deleting file to ensure failure { target_file } " )
132
179
bak_path = str (target_file ) + ".bak"
133
180
target_file .rename (bak_path )
134
181
135
- start_expecting_error (err_fragment )
182
+ start_expecting_error (err_fragment , startup_args )
136
183
137
184
for target_file in target_files :
138
185
bak_path = str (target_file ) + ".bak"
@@ -144,7 +191,11 @@ def check_clean_start():
144
191
145
192
self .log .info ("Test startup errors after perturbing certain essential files" )
146
193
dirs = ["blocks" , "chainstate" , "indexes" ]
147
- for file_patt , err_fragment in files_to_perturb .items ():
194
+ for round_info in perturbation_rounds :
195
+ file_patt = round_info ['filepath_glob' ]
196
+ err_fragment = round_info ['error_message' ]
197
+ startup_args = round_info ['startup_args' ]
198
+
148
199
for dir in dirs :
149
200
shutil .copytree (node .chain_path / dir , node .chain_path / f"{ dir } _bak" )
150
201
target_files = list (node .chain_path .glob (file_patt ))
@@ -158,7 +209,7 @@ def check_clean_start():
158
209
tf .seek (150 )
159
210
tf .write (b"1" * 200 )
160
211
161
- start_expecting_error (err_fragment )
212
+ start_expecting_error (err_fragment , startup_args )
162
213
163
214
for dir in dirs :
164
215
shutil .rmtree (node .chain_path / dir )
0 commit comments