From 79e9bb574bcdc1b0219edd4a16a30547144c0367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Chodo=C5=82a?= <43241881+kamilchodola@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:26:34 +0100 Subject: [PATCH] Create waitForSync.py --- scripts/waitForSync.py | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 scripts/waitForSync.py diff --git a/scripts/waitForSync.py b/scripts/waitForSync.py new file mode 100644 index 00000000000..115581a8876 --- /dev/null +++ b/scripts/waitForSync.py @@ -0,0 +1,64 @@ +import os +import subprocess +import sys + +network = os.getenv("NETWORK") + +bad_logs = {"Exception": 1, "Missing node found!": 1} +good_logs = {"Processed": 0, "Stats after finishing state": 0} +required_count = {"Processed": 20, "Stats after finishing state": 1} + +if network not in {"joc-mainnet", "joc-testnet", "linea-mainnet", "linea-sepolia"}: + good_logs["Synced Chain Head"] = 0 + required_count["Synced Chain Head"] = 20 + +container_mapping = { + "base-": "sedge-execution-op-l2-client", + "op-": "sedge-execution-op-l2-client", +} +default_container_name = "sedge-execution-client" + +container_name = next( + (name for prefix, name in container_mapping.items() if network.startswith(prefix)), + default_container_name +) + +process = subprocess.Popen(["docker", "logs", "-f", container_name], stdout=subprocess.PIPE, text=True) + +found_bad_log = False +counter = 0 + +try: + for line in process.stdout: + print(line.strip()) + + if found_bad_log: + counter += 1 + if counter >= 100: + print("Exiting after capturing extra logs due to error.") + sys.exit(1) + continue + + if any(bad_log in line for bad_log in bad_logs): + print(f"Error: Found bad log in line: {line.strip()}") + found_bad_log = True + continue + + for good_log in good_logs: + if good_log in line: + good_logs[good_log] += 1 + + if all(good_logs[log] >= required_count[log] for log in required_count): + print("All required logs found.") + sys.exit(0) + +except Exception as e: + print(f"An error occurred: {e}") + sys.exit(1) +finally: + process.terminate() + print("Process terminated - exiting script.") + +# Final exit if we did not reach required lines after an error +print("Unhandled termination. Probably critical issue in client. Stopping...") +sys.exit(1)