From 82e89b25b4e6fd7e0d1f5d4f2dfcbccfbbab7b41 Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 17 Sep 2025 14:28:24 +0200 Subject: [PATCH 1/2] add temp key to validator config one more time --- mytoncore/mytoncore.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 7cbf29c3..5da880c9 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -13,6 +13,7 @@ from modules import MODES from modules.btc_teleport import BtcTeleportModule +from mytoncore import b642hex from mytoncore.utils import xhex2hex, ng2g from mytoncore.liteclient import LiteClient from mytoncore.validator_console import ValidatorConsole @@ -1456,6 +1457,7 @@ def ElectionEntry(self, args=None): # Create keys validatorKey = self.GetValidatorKeyByTime(startWorkTime, endWorkTime) + self.AddKeyToTemp(validatorKey, endWorkTime) # add one more time to ensure it is in temp keys validatorPubkey_b64 = self.GetPubKeyBase64(validatorKey) # Attach ADNL addr to validator From 820a1951476dbb967a53ce420c9a55721cd53cbb Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 17 Sep 2025 16:20:19 +0200 Subject: [PATCH 2/2] add mytoncore logs saving, add mytoncore db checking --- mytoncore/functions.py | 31 +++++++++++++++++++++++++++++++ mytoncore/mytoncore.py | 1 - 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/mytoncore/functions.py b/mytoncore/functions.py index 4526dc79..903268b7 100755 --- a/mytoncore/functions.py +++ b/mytoncore/functions.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf_8 -*-l +import datetime import os import sys import psutil @@ -9,6 +10,7 @@ import requests import subprocess +from mypylib import MyPyClass from mytoncore.mytoncore import MyTonCore from mytonctrl.utils import fix_git_config from mytoninstaller.config import GetConfig @@ -667,6 +669,32 @@ def gc_import(local, ton): local.add_log(f"Removed {removed} import files up to {node_seqno} seqno", "debug") +def backup_mytoncore_logs(local: MyPyClass, ton: MyTonCore): + logs_path = os.path.join(ton.tempDir, 'old_logs') + os.makedirs(logs_path, exist_ok=True) + for file in os.listdir(logs_path): + file_path = os.path.join(logs_path, file) + if time.time() - os.path.getmtime(file_path) < 3600: # check that last file was created not less than an hour ago + return + now = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") + log_backup_tmp_path = os.path.join(logs_path, 'mytoncore_log_' + now + '.log') + subprocess.run(["cp", local.buffer.log_file_name, log_backup_tmp_path]) + ton.clear_dir(logs_path) + + +def check_mytoncore_db(local: MyPyClass, ton: MyTonCore): + try: + local.read_db(local.buffer.db_path) + backup_path = local.buffer.db_path + ".backup" + if not os.path.isfile(backup_path) or time.time() - os.path.getmtime(backup_path) > 3600*6: + ton.create_self_db_backup() + return + except Exception as e: + print(f'Failed to read mytoncore db: {e}') + local.add_log(f"Failed to read mytoncore db: {e}", "error") + ton.CheckConfigFile(None, None) # get mytoncore db from backup + + def General(local): local.add_log("start General function", "debug") ton = MyTonCore(local) @@ -677,6 +705,9 @@ def General(local): local.start_cycle(Statistics, sec=10, args=(local, )) local.start_cycle(Telemetry, sec=60, args=(local, ton, )) local.start_cycle(OverlayTelemetry, sec=7200, args=(local, ton, )) + local.start_cycle(backup_mytoncore_logs, sec=3600*4, args=(local, ton, )) + local.start_cycle(check_mytoncore_db, sec=600, args=(local, ton, )) + if local.db.get("onlyNode"): # mytoncore service works only for telemetry thr_sleep() return diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 5da880c9..04b98d89 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -13,7 +13,6 @@ from modules import MODES from modules.btc_teleport import BtcTeleportModule -from mytoncore import b642hex from mytoncore.utils import xhex2hex, ng2g from mytoncore.liteclient import LiteClient from mytoncore.validator_console import ValidatorConsole