24
24
check_json_precision ,
25
25
connect_nodes_bi ,
26
26
disconnect_nodes ,
27
+ get_datadir_path ,
27
28
initialize_datadir ,
28
- log_filename ,
29
29
p2p_port ,
30
30
set_node_times ,
31
31
sync_blocks ,
@@ -382,7 +382,7 @@ def _initialize_chain(self):
382
382
assert self .num_nodes <= MAX_NODES
383
383
create_cache = False
384
384
for i in range (MAX_NODES ):
385
- if not os .path .isdir (os . path . join (self .options .cachedir , 'node' + str ( i ) )):
385
+ if not os .path .isdir (get_datadir_path (self .options .cachedir , i )):
386
386
create_cache = True
387
387
break
388
388
@@ -391,8 +391,8 @@ def _initialize_chain(self):
391
391
392
392
# find and delete old cache directories if any exist
393
393
for i in range (MAX_NODES ):
394
- if os .path .isdir (os . path . join (self .options .cachedir , "node" + str ( i ) )):
395
- shutil .rmtree (os . path . join (self .options .cachedir , "node" + str ( i ) ))
394
+ if os .path .isdir (get_datadir_path (self .options .cachedir , i )):
395
+ shutil .rmtree (get_datadir_path (self .options .cachedir , i ))
396
396
397
397
# Create cache directories, run bitcoinds:
398
398
for i in range (MAX_NODES ):
@@ -430,15 +430,18 @@ def _initialize_chain(self):
430
430
self .stop_nodes ()
431
431
self .nodes = []
432
432
self .disable_mocktime ()
433
+
434
+ def cache_path (n , * paths ):
435
+ return os .path .join (get_datadir_path (self .options .cachedir , n ), "regtest" , * paths )
436
+
433
437
for i in range (MAX_NODES ):
434
- os .remove (log_filename (self .options .cachedir , i , "debug.log" ))
435
- os .remove (log_filename (self .options .cachedir , i , "wallets/db.log" ))
436
- os .remove (log_filename (self .options .cachedir , i , "peers.dat" ))
437
- os .remove (log_filename (self .options .cachedir , i , "fee_estimates.dat" ))
438
+ for entry in os .listdir (cache_path (i )):
439
+ if entry not in ['wallets' , 'chainstate' , 'blocks' ]:
440
+ os .remove (cache_path (i , entry ))
438
441
439
442
for i in range (self .num_nodes ):
440
- from_dir = os . path . join (self .options .cachedir , "node" + str ( i ) )
441
- to_dir = os . path . join (self .options .tmpdir , "node" + str ( i ) )
443
+ from_dir = get_datadir_path (self .options .cachedir , i )
444
+ to_dir = get_datadir_path (self .options .tmpdir , i )
442
445
shutil .copytree (from_dir , to_dir )
443
446
initialize_datadir (self .options .tmpdir , i ) # Overwrite port/rpcport in bitcoin.conf
444
447
0 commit comments