@@ -47,9 +47,9 @@ def sigterm_node():
4747 node .process .terminate ()
4848 node .process .wait ()
4949
50- def start_expecting_error (err_fragment ):
50+ def start_expecting_error (err_fragment , args ):
5151 node .assert_start_raises_init_error (
52- extra_args = [ '-txindex=1' , '-blockfilterindex=1' , '-coinstatsindex=1' , '-checkblocks=200' , '-checklevel=4' ] ,
52+ extra_args = args ,
5353 expected_msg = err_fragment ,
5454 match = ErrorMatch .PARTIAL_REGEX ,
5555 )
@@ -102,37 +102,84 @@ def check_clean_start():
102102
103103 self .log .info ("Test startup errors after removing certain essential files" )
104104
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+ },
110126 # Removing these files does not result in a startup error:
111127 # 'indexes/blockfilter/basic/*.dat', 'indexes/blockfilter/basic/db/*.*', 'indexes/coinstats/db/*.*',
112128 # '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+ },
123167 # Perturbing these files does not result in a startup error:
124168 # 'indexes/blockfilter/basic/*.dat', 'indexes/txindex/MANIFEST*', 'indexes/txindex/LOCK'
125- }
169+ ]
126170
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' ]
128175 target_files = list (node .chain_path .glob (file_patt ))
129176
130177 for target_file in target_files :
131178 self .log .info (f"Deleting file to ensure failure { target_file } " )
132179 bak_path = str (target_file ) + ".bak"
133180 target_file .rename (bak_path )
134181
135- start_expecting_error (err_fragment )
182+ start_expecting_error (err_fragment , startup_args )
136183
137184 for target_file in target_files :
138185 bak_path = str (target_file ) + ".bak"
@@ -144,7 +191,11 @@ def check_clean_start():
144191
145192 self .log .info ("Test startup errors after perturbing certain essential files" )
146193 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+
148199 for dir in dirs :
149200 shutil .copytree (node .chain_path / dir , node .chain_path / f"{ dir } _bak" )
150201 target_files = list (node .chain_path .glob (file_patt ))
@@ -158,7 +209,7 @@ def check_clean_start():
158209 tf .seek (150 )
159210 tf .write (b"1" * 200 )
160211
161- start_expecting_error (err_fragment )
212+ start_expecting_error (err_fragment , startup_args )
162213
163214 for dir in dirs :
164215 shutil .rmtree (node .chain_path / dir )
0 commit comments