Skip to content

Commit

Permalink
simplify clean logic and make sure it deletes archived log files
Browse files Browse the repository at this point in the history
  • Loading branch information
norswap committed Jan 15, 2024
1 parent a61509e commit 038f488
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 68 deletions.
15 changes: 4 additions & 11 deletions account_abstraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,16 @@ def clean(config: Config):
"""
Deletes the account abstraction deployment outputs and build logs.
"""
paths = [
lib.remove_paths(config, [
os.path.join(config.logs_dir, "build_aa_contracts.log"),
os.path.join(config.logs_dir, "install_bundler.log"),
os.path.join(config.logs_dir, "build_paymaster.log"),
os.path.join(config.logs_dir, config.deploy_aa_log_file_name),
config.stackup_bundler_log_file,
config.paymaster_log_file,
]

for path in paths:
if os.path.exists(path):
lib.debug(f"Removing {path}")
os.remove(path)

path = "account-abstraction/deployments/opstack"
lib.debug(f"Removing {path}")
shutil.rmtree(path, ignore_errors=True)
# dirs
"account-abstraction/deployments/opstack",
])


####################################################################################################
16 changes: 4 additions & 12 deletions block_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,14 @@ def clean(config: Config):
"""
Deletes the block explorer databases, logs, and containers.
"""

dir_paths = [
lib.remove_paths(config, [
config.blockscout_log_file,
# dirs
"blockscout/docker-compose/services/blockscout-db-data",
"blockscout/docker-compose/services/logs",
"blockscout/docker-compose/services/redis-data",
"blockscout/docker-compose/services/stats-db-data",
]

for path in dir_paths:
lib.debug(f"Removing {path}")
shutil.rmtree(path, ignore_errors=True)

path = config.blockscout_log_file
if os.path.exists(path):
lib.debug(f"Removing {path}")
os.remove(path)
])

lib.run("remove blockscout containers",
f"docker compose --project-name {_COMPOSE_PROJECT_NAME} rm --stop --force")
Expand Down
24 changes: 7 additions & 17 deletions l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,16 @@ def clean(config: Config):
"""
Cleans up L1 deployment outputs.
"""
paths = [
os.path.join(config.logs_dir, "l1_node.log"),
lib.remove_paths(config, [
config.l1_node_log_file,
os.path.join(config.logs_dir, "temp_geth.log"),
config.l1_genesis_path,
config.l1_allocs_path,
config.op_deploy_config_path
]

for path in paths:
if os.path.exists(path):
lib.debug(f"Removing {path}")
os.remove(path)

if os.path.exists(config.l1_data_dir):
lib.debug(f"Removing {config.l1_data_dir}")
shutil.rmtree(config.l1_data_dir, ignore_errors=True)

if os.path.exists(config.op_deployment_artifacts_dir):
lib.debug(f"Removing {config.op_deployment_artifacts_dir}")
shutil.rmtree(config.op_deployment_artifacts_dir, ignore_errors=True)
config.op_deploy_config_path,
# dirs
config.l1_data_dir,
config.op_deployment_artifacts_dir,
])

if config.l1_contracts_in_genesis:
print(
Expand Down
31 changes: 11 additions & 20 deletions l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def clean(config: Config):
"""
Cleans up L2 deployment outputs.
"""
paths = [
lib.remove_paths(config, [
config.addresses_path,
config.l2_genesis_path,
config.rollup_config_path,
Expand All @@ -80,27 +80,18 @@ def clean(config: Config):
config.op_deploy_config_path,
os.path.join(config.logs_dir, "deploy_l1_contracts.log"),
os.path.join(config.logs_dir, "create_l1_artifacts.log"),
os.path.join(config.logs_dir, "l2_batcher.log"),
os.path.join(config.logs_dir, "l2_engine.log"),
os.path.join(config.logs_dir, "l2_node.log"),
os.path.join(config.logs_dir, "l2_proposer.log")
]

for path in paths:
if os.path.exists(path):
lib.debug(f"Removing {path}")
os.remove(path)
os.path.join(config.logs_dir, "init_l2_genesis.log"),
config.l2_batcher_log_file,
config.l2_engine_log_file,
config.l2_node_log_file,
config.l2_proposer_log_file,
# dirs
config.op_deployment_artifacts_dir,
config.abi_dir,
])

l2_engine.clean(config)
l2_node.clean()

if os.path.exists(config.op_deployment_artifacts_dir):
lib.debug(f"Removing {config.op_deployment_artifacts_dir}")
shutil.rmtree(config.op_deployment_artifacts_dir, ignore_errors=True)

if os.path.exists(config.abi_dir):
lib.debug(f"Removing {config.abi_dir}")
shutil.rmtree(config.abi_dir, ignore_errors=True)
l2_node.clean(config)


####################################################################################################
4 changes: 1 addition & 3 deletions l2_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ def clean(config: Config):
"""
Cleans up L2 execution engine's databases.
"""
if os.path.exists(config.l2_engine_data_dir):
lib.debug(f"Removing {config.l2_engine_data_dir}")
shutil.rmtree(config.l2_engine_data_dir, ignore_errors=True)
lib.remove_paths(config, [config.l2_engine_data_dir])

####################################################################################################
9 changes: 5 additions & 4 deletions l2_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ def on_exit():

####################################################################################################

def clean():
def clean(config: Config):
"""
Delete the L2 node's p2p databases.
"""
lib.debug("Removing L2 node's p2p databases")
shutil.rmtree("opnode_discovery_db", ignore_errors=True)
shutil.rmtree("opnode_peerstore_db", ignore_errors=True)
lib.remove_paths(config, [
"opnode_discovery_db",
"opnode_peerstore_db",
])


####################################################################################################
25 changes: 25 additions & 0 deletions libroll/libroll.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import glob
import http.client
import os
import shutil
import socket
import time
from dataclasses import dataclass
from typing import Callable

import state
from config import Config
from .cmd import run_roll_log


Expand Down Expand Up @@ -284,4 +287,26 @@ def append_to_file(file_path: str, text: str):
with open(file_path, "a") as file:
file.write(text)


####################################################################################################

def remove_paths(config: Config, paths: list[str]):
"""
Removes the given paths, if they exist, as well as archived logs if one of the passed path is
a logfile.
"""
for path in paths:
if os.path.isfile(path):
debug(f"Removing {path}")
os.remove(path)
if path.startswith(config.logs_dir):
basename = os.path.basename(path)
debug(f"Removing archived logs for {basename}")
archived_logs = glob.glob(os.path.join(config.logrotate_old_dir, basename) + "*")
for log in archived_logs:
os.remove(log)
elif os.path.isdir(path):
debug(f"Removing {path}")
shutil.rmtree(path, ignore_errors=True)

####################################################################################################
2 changes: 1 addition & 1 deletion roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def main():

elif state.args.command == "l2-sequencer":
if state.args.clean_first:
l2_node.clean()
l2_node.clean(config)

l2_node.start(config, sequencer=True)
wait(config)
Expand Down

0 comments on commit 038f488

Please sign in to comment.