From aaa758ddf0a66a6b79643cd9f6c9a1b94a07958b Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 21:12:51 +0800 Subject: [PATCH 1/9] add custom overlays --- custom_overlays.py | 124 +++++++++++++++++++++++++++++++++++++++++++++ mytoncore.py | 2 + mytonctrl.py | 5 ++ 3 files changed, 131 insertions(+) create mode 100644 custom_overlays.py diff --git a/custom_overlays.py b/custom_overlays.py new file mode 100644 index 00000000..c6fbcdb3 --- /dev/null +++ b/custom_overlays.py @@ -0,0 +1,124 @@ +import json + +from mypylib.mypylib import color_print +from mytoncore import local as mytoncore_local, hex2base64, MyTonCore +from mytonctrl import ton + + +def parse_config(name: str, config: dict, vset: list = None): + """ + Converts config to validator-console friendly format + :param name: custom overlay name + :param config: config + :param vset: list of validators adnl addresses, can be None if `@validators` not in config + :return: + """ + result = { + "name": name, + "nodes": [] + } + for k, v in config.items(): + result["nodes"].append({ + "adnl_id": hex2base64(k), + "msg_sender": v["msg_sender"], + "msg_sender_priority": v["msg_sender_priority"], + }) + if k == '@validators' and v: + if vset is None: + raise Exception("Validators set is not defined but @validators is in config") + for v_adnl in vset: + result["nodes"].append({ + "adnl_id": hex2base64(v_adnl), + "msg_sender": False, + }) + return result + + +def add_custom_overlay(args): + if len(args) != 2: + color_print("{red}Bad args. Usage:{endc} add_custom_overlay ") + return + path = args[1] + with open(path, 'r') as f: + config = json.load(f) + mytoncore_local.db['custom_overlays'][args[0]] = config + + +def list_custom_overlays(args): + for k, v in mytoncore_local.db['custom_overlays'].items(): + color_print(f"Custom overlay {{bold}}{k}{{endc}}:") + print(json.dumps(v, indent=4)) + + +def delete_custom_overlay(args): + if len(args) != 1: + color_print("{red}Bad args. Usage:{endc} delete_custom_overlay ") + return + del mytoncore_local.db['custom_overlays'][args[0]] + + +def delete_custom_overlay_from_vc(name: str): + result = ton.validatorConsole.Run(f"delcustomoverlay {name}") + return 'success' in result + + +def add_custom_overlay_to_vc(config: dict): + mytoncore_local.add_log(f"Adding custom overlay {config['name']}", "debug") + path = ton.tempDir + f'/custom_overlay_{config["name"]}.json' + with open(path, 'w') as f: + json.dump(config, f) + result = ton.validatorConsole.Run(f"addcustomoverlay {path}") + return 'success' in result + + +def deploy_custom_overlays(): + result = ton.validatorConsole.Run("showcustomoverlays") + if 'unknown command' in result: + return # node old version + names = [] + for line in result.split('\n'): + if line.startswith('Overlay'): + names.append(line.split(' ')[1].replace('"', '')) + + config34 = ton.GetConfig34() + current_el_id = config34['startWorkTime'] + current_vset = [i["adnlAddr"] for i in config34['validators']] + + config36 = ton.GetConfig36() + next_el_id = config36['startWorkTime'] if config36['validators'] else 0 + next_vset = [i["adnlAddr"] for i in config36['validators']] + + for name in names: + # check that overlay still exists in mtc db + pure_name = name + suffix = name.split('_')[-1] + if suffix.startswith('elid') and suffix.split('elid')[-1].isdigit(): # probably election id + pure_name = '_'.join(name.split('_')[:-1]) + el_id = int(suffix.split('elid')[-1].isdigit()) + if el_id not in (current_el_id, next_el_id): + mytoncore_local.add_log(f"Overlay {name} is not in current or next election, deleting", "debug") + delete_custom_overlay_from_vc(name) # delete overlay if election id is not in current or next election + continue + + if pure_name not in mytoncore_local.db['custom_overlays']: + mytoncore_local.add_log(f"Overlay {name} is not in mtc db, deleting", "debug") + delete_custom_overlay_from_vc(name) # delete overlay if it's not in mtc db + + for name, config in mytoncore_local.db['custom_overlays'].items(): + if name in names: + continue + if '@validators' in config: + new_name = name + '_elid' + str(current_el_id) + if new_name not in names: + node_config = parse_config(new_name, config, current_vset) + add_custom_overlay_to_vc(node_config) + + if next_el_id != 0: + new_name = name + '_elid' + str(next_el_id) + if new_name not in names: + node_config = parse_config(new_name, config, next_vset) + add_custom_overlay_to_vc(node_config) + else: + + node_config = parse_config(name, config) + add_custom_overlay_to_vc(node_config) diff --git a/mytoncore.py b/mytoncore.py index 82572b5b..cf19e348 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -8,6 +8,7 @@ import requests import re from mypylib.mypylib import * +from custom_overlays import deploy_custom_overlays local = MyPyClass(__file__) @@ -4297,6 +4298,7 @@ def General(): local.start_cycle(Telemetry, sec=60, args=(ton, )) local.start_cycle(OverlayTelemetry, sec=7200, args=(ton, )) local.start_cycle(ScanLiteServers, sec=60, args=(ton,)) + local.start_cycle(deploy_custom_overlays, sec=60) thr_sleep() #end define diff --git a/mytonctrl.py b/mytonctrl.py index 09a91834..6549afcd 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -4,6 +4,7 @@ from mypylib.mypylib import * from mypyconsole.mypyconsole import * from mytoncore import * +from custom_overlays import add_custom_overlay, list_custom_overlays, delete_custom_overlay import sys, getopt, os local = MyPyClass(__file__) @@ -25,6 +26,10 @@ def Init(argv): console.AddItem("seqno", Seqno, local.translate("seqno_cmd")) console.AddItem("getconfig", GetConfig, local.translate("getconfig_cmd")) + console.AddItem("add_custom_overlay", add_custom_overlay, local.translate("add_custom_overlay_cmd")) + console.AddItem("list_custom_overlays", list_custom_overlays, local.translate("list_custom_overlays_cmd")) + console.AddItem("delete_custom_overlay", delete_custom_overlay, local.translate("delete_custom_overlay_cmd")) + console.AddItem("nw", CreatNewWallet, local.translate("nw_cmd")) console.AddItem("aw", ActivateWallet, local.translate("aw_cmd")) console.AddItem("wl", PrintWalletsList, local.translate("wl_cmd")) From fab1484971a95ce02aae4e109be9c7e1a212a4e5 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 21:19:30 +0800 Subject: [PATCH 2/9] fix config parsing --- custom_overlays.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/custom_overlays.py b/custom_overlays.py index c6fbcdb3..960629cb 100644 --- a/custom_overlays.py +++ b/custom_overlays.py @@ -1,7 +1,7 @@ import json from mypylib.mypylib import color_print -from mytoncore import local as mytoncore_local, hex2base64, MyTonCore +from mytoncore import local as mytoncore_local, hex2base64 from mytonctrl import ton @@ -18,11 +18,6 @@ def parse_config(name: str, config: dict, vset: list = None): "nodes": [] } for k, v in config.items(): - result["nodes"].append({ - "adnl_id": hex2base64(k), - "msg_sender": v["msg_sender"], - "msg_sender_priority": v["msg_sender_priority"], - }) if k == '@validators' and v: if vset is None: raise Exception("Validators set is not defined but @validators is in config") @@ -31,7 +26,14 @@ def parse_config(name: str, config: dict, vset: list = None): "adnl_id": hex2base64(v_adnl), "msg_sender": False, }) - return result + else: + result["nodes"].append({ + "adnl_id": hex2base64(k), + "msg_sender": v["msg_sender"], + }) + if v["msg_sender"]: + result["nodes"][-1]["msg_sender_priority"] = v["msg_sender_priority"] + return result def add_custom_overlay(args): From e935a4d1fcfbc34a094126867688a5123cef3331 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 21:21:57 +0800 Subject: [PATCH 3/9] fix circular import fix circular import --- mytoncore.py | 2 +- mytonctrl.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index cf19e348..b8971427 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -8,7 +8,6 @@ import requests import re from mypylib.mypylib import * -from custom_overlays import deploy_custom_overlays local = MyPyClass(__file__) @@ -4298,6 +4297,7 @@ def General(): local.start_cycle(Telemetry, sec=60, args=(ton, )) local.start_cycle(OverlayTelemetry, sec=7200, args=(ton, )) local.start_cycle(ScanLiteServers, sec=60, args=(ton,)) + from custom_overlays import deploy_custom_overlays local.start_cycle(deploy_custom_overlays, sec=60) thr_sleep() #end define diff --git a/mytonctrl.py b/mytonctrl.py index 6549afcd..f32cc0ef 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -4,7 +4,6 @@ from mypylib.mypylib import * from mypyconsole.mypyconsole import * from mytoncore import * -from custom_overlays import add_custom_overlay, list_custom_overlays, delete_custom_overlay import sys, getopt, os local = MyPyClass(__file__) @@ -26,6 +25,7 @@ def Init(argv): console.AddItem("seqno", Seqno, local.translate("seqno_cmd")) console.AddItem("getconfig", GetConfig, local.translate("getconfig_cmd")) + from custom_overlays import add_custom_overlay, list_custom_overlays, delete_custom_overlay console.AddItem("add_custom_overlay", add_custom_overlay, local.translate("add_custom_overlay_cmd")) console.AddItem("list_custom_overlays", list_custom_overlays, local.translate("list_custom_overlays_cmd")) console.AddItem("delete_custom_overlay", delete_custom_overlay, local.translate("delete_custom_overlay_cmd")) From d0b2f5917b52777eed98625f46f1ccd5ba9ef0b1 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 21:28:01 +0800 Subject: [PATCH 4/9] bugfix --- custom_overlays.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_overlays.py b/custom_overlays.py index 960629cb..7e9dca40 100644 --- a/custom_overlays.py +++ b/custom_overlays.py @@ -43,6 +43,8 @@ def add_custom_overlay(args): path = args[1] with open(path, 'r') as f: config = json.load(f) + if 'custom_overlays' not in mytoncore_local.db: + mytoncore_local.db['custom_overlays'] = {} mytoncore_local.db['custom_overlays'][args[0]] = config From 3863ef0b5d622eca9d63b473b38ba95ab8002a12 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 21:36:53 +0800 Subject: [PATCH 5/9] rm mytoncore_local from custom_overlays --- custom_overlays.py | 21 +++++++++------------ mytoncore.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/custom_overlays.py b/custom_overlays.py index 7e9dca40..105f0124 100644 --- a/custom_overlays.py +++ b/custom_overlays.py @@ -1,7 +1,7 @@ import json from mypylib.mypylib import color_print -from mytoncore import local as mytoncore_local, hex2base64 +from mytoncore import hex2base64 from mytonctrl import ton @@ -43,13 +43,11 @@ def add_custom_overlay(args): path = args[1] with open(path, 'r') as f: config = json.load(f) - if 'custom_overlays' not in mytoncore_local.db: - mytoncore_local.db['custom_overlays'] = {} - mytoncore_local.db['custom_overlays'][args[0]] = config + ton.set_custom_overlay(args[0], config) def list_custom_overlays(args): - for k, v in mytoncore_local.db['custom_overlays'].items(): + for k, v in ton.get_custom_overlays().items(): color_print(f"Custom overlay {{bold}}{k}{{endc}}:") print(json.dumps(v, indent=4)) @@ -58,7 +56,7 @@ def delete_custom_overlay(args): if len(args) != 1: color_print("{red}Bad args. Usage:{endc} delete_custom_overlay ") return - del mytoncore_local.db['custom_overlays'][args[0]] + ton.delete_custom_overlay(args[0]) def delete_custom_overlay_from_vc(name: str): @@ -67,7 +65,7 @@ def delete_custom_overlay_from_vc(name: str): def add_custom_overlay_to_vc(config: dict): - mytoncore_local.add_log(f"Adding custom overlay {config['name']}", "debug") + ton.add_log(f"Adding custom overlay {config['name']}", "debug") path = ton.tempDir + f'/custom_overlay_{config["name"]}.json' with open(path, 'w') as f: json.dump(config, f) @@ -100,15 +98,15 @@ def deploy_custom_overlays(): pure_name = '_'.join(name.split('_')[:-1]) el_id = int(suffix.split('elid')[-1].isdigit()) if el_id not in (current_el_id, next_el_id): - mytoncore_local.add_log(f"Overlay {name} is not in current or next election, deleting", "debug") + ton.add_log(f"Overlay {name} is not in current or next election, deleting", "debug") delete_custom_overlay_from_vc(name) # delete overlay if election id is not in current or next election continue - if pure_name not in mytoncore_local.db['custom_overlays']: - mytoncore_local.add_log(f"Overlay {name} is not in mtc db, deleting", "debug") + if pure_name not in ton.get_custom_overlays(): + ton.add_log(f"Overlay {name} is not in mtc db, deleting", "debug") delete_custom_overlay_from_vc(name) # delete overlay if it's not in mtc db - for name, config in mytoncore_local.db['custom_overlays'].items(): + for name, config in ton.get_custom_overlays().items(): if name in names: continue if '@validators' in config: @@ -123,6 +121,5 @@ def deploy_custom_overlays(): node_config = parse_config(new_name, config, next_vset) add_custom_overlay_to_vc(node_config) else: - node_config = parse_config(name, config) add_custom_overlay_to_vc(node_config) diff --git a/mytoncore.py b/mytoncore.py index b8971427..3de0304a 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -3646,6 +3646,23 @@ def GetPoolData(self, addrB64): return poolData #end define + def get_custom_overlays(self): + if 'custom_overlays' not in local.db: + local.db['custom_overlays'] = {} + return local.db['custom_overlays'] + + def set_custom_overlay(self, name: str, config: dict): + overlays = self.get_custom_overlays() + overlays[name] = config + local.save() + + def delete_custom_overlay(self, name: str): + del local.db['custom_overlays'][name] + local.save() + + def add_log(self, text, level="info"): + local.add_log(text, level) + def GetNetworkName(self): mainnetValidatorsElectedFor = 65536 mainnetZerostateRootHash = "x55B13F6D0E1D0C34C9C2160F6F918E92D82BF9DDCF8DE2E4C94A3FDF39D15446" From 8d584bc7e26b0f9bea9f5b85a67e26b1bf7d2df8 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 21:59:05 +0800 Subject: [PATCH 6/9] improves --- custom_overlays.py | 16 +++++++++++++--- mytoncore.py | 3 --- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/custom_overlays.py b/custom_overlays.py index 105f0124..8f0396d6 100644 --- a/custom_overlays.py +++ b/custom_overlays.py @@ -5,6 +5,11 @@ from mytonctrl import ton +def add_log(message: str, level: str = 'info'): + from mytoncore import local + local.add_log(message, level) + + def parse_config(name: str, config: dict, vset: list = None): """ Converts config to validator-console friendly format @@ -44,9 +49,13 @@ def add_custom_overlay(args): with open(path, 'r') as f: config = json.load(f) ton.set_custom_overlay(args[0], config) + color_print("add_custom_overlay - {green}OK{endc}") def list_custom_overlays(args): + if not ton.get_custom_overlays(): + color_print("{red}No custom overlays{endc}") + return for k, v in ton.get_custom_overlays().items(): color_print(f"Custom overlay {{bold}}{k}{{endc}}:") print(json.dumps(v, indent=4)) @@ -57,6 +66,7 @@ def delete_custom_overlay(args): color_print("{red}Bad args. Usage:{endc} delete_custom_overlay ") return ton.delete_custom_overlay(args[0]) + color_print("delete_custom_overlay - {green}OK{endc}") def delete_custom_overlay_from_vc(name: str): @@ -65,7 +75,7 @@ def delete_custom_overlay_from_vc(name: str): def add_custom_overlay_to_vc(config: dict): - ton.add_log(f"Adding custom overlay {config['name']}", "debug") + add_log(f"Adding custom overlay {config['name']}", "debug") path = ton.tempDir + f'/custom_overlay_{config["name"]}.json' with open(path, 'w') as f: json.dump(config, f) @@ -98,12 +108,12 @@ def deploy_custom_overlays(): pure_name = '_'.join(name.split('_')[:-1]) el_id = int(suffix.split('elid')[-1].isdigit()) if el_id not in (current_el_id, next_el_id): - ton.add_log(f"Overlay {name} is not in current or next election, deleting", "debug") + add_log(f"Overlay {name} is not in current or next election, deleting", "debug") delete_custom_overlay_from_vc(name) # delete overlay if election id is not in current or next election continue if pure_name not in ton.get_custom_overlays(): - ton.add_log(f"Overlay {name} is not in mtc db, deleting", "debug") + add_log(f"Overlay {name} is not in mtc db, deleting", "debug") delete_custom_overlay_from_vc(name) # delete overlay if it's not in mtc db for name, config in ton.get_custom_overlays().items(): diff --git a/mytoncore.py b/mytoncore.py index 3de0304a..532b53df 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -3660,9 +3660,6 @@ def delete_custom_overlay(self, name: str): del local.db['custom_overlays'][name] local.save() - def add_log(self, text, level="info"): - local.add_log(text, level) - def GetNetworkName(self): mainnetValidatorsElectedFor = 65536 mainnetZerostateRootHash = "x55B13F6D0E1D0C34C9C2160F6F918E92D82BF9DDCF8DE2E4C94A3FDF39D15446" From 1b9ff1c16273c92119d840a5c1469aaf98780d14 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 22:10:38 +0800 Subject: [PATCH 7/9] rm global variables from custom_overlays --- custom_overlays.py | 40 +++++++++++++++++++++++----------------- mytoncore.py | 4 ++-- mytonctrl.py | 3 ++- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/custom_overlays.py b/custom_overlays.py index 8f0396d6..94e31342 100644 --- a/custom_overlays.py +++ b/custom_overlays.py @@ -1,13 +1,14 @@ +import base64 import json from mypylib.mypylib import color_print -from mytoncore import hex2base64 -from mytonctrl import ton -def add_log(message: str, level: str = 'info'): - from mytoncore import local - local.add_log(message, level) +def hex2base64(h): + b = bytes.fromhex(h) + b64 = base64.b64encode(b) + s = b64.decode("utf-8") + return s def parse_config(name: str, config: dict, vset: list = None): @@ -42,6 +43,7 @@ def parse_config(name: str, config: dict, vset: list = None): def add_custom_overlay(args): + from mytonctrl import ton if len(args) != 2: color_print("{red}Bad args. Usage:{endc} add_custom_overlay ") return @@ -53,6 +55,7 @@ def add_custom_overlay(args): def list_custom_overlays(args): + from mytonctrl import ton if not ton.get_custom_overlays(): color_print("{red}No custom overlays{endc}") return @@ -62,6 +65,7 @@ def list_custom_overlays(args): def delete_custom_overlay(args): + from mytonctrl import ton if len(args) != 1: color_print("{red}Bad args. Usage:{endc} delete_custom_overlay ") return @@ -69,13 +73,12 @@ def delete_custom_overlay(args): color_print("delete_custom_overlay - {green}OK{endc}") -def delete_custom_overlay_from_vc(name: str): +def delete_custom_overlay_from_vc(ton, name: str): result = ton.validatorConsole.Run(f"delcustomoverlay {name}") return 'success' in result -def add_custom_overlay_to_vc(config: dict): - add_log(f"Adding custom overlay {config['name']}", "debug") +def add_custom_overlay_to_vc(ton, config: dict): path = ton.tempDir + f'/custom_overlay_{config["name"]}.json' with open(path, 'w') as f: json.dump(config, f) @@ -83,7 +86,7 @@ def add_custom_overlay_to_vc(config: dict): return 'success' in result -def deploy_custom_overlays(): +def deploy_custom_overlays(local, ton): result = ton.validatorConsole.Run("showcustomoverlays") if 'unknown command' in result: return # node old version @@ -108,13 +111,13 @@ def deploy_custom_overlays(): pure_name = '_'.join(name.split('_')[:-1]) el_id = int(suffix.split('elid')[-1].isdigit()) if el_id not in (current_el_id, next_el_id): - add_log(f"Overlay {name} is not in current or next election, deleting", "debug") - delete_custom_overlay_from_vc(name) # delete overlay if election id is not in current or next election + local.add_log(f"Overlay {name} is not in current or next election, deleting", "debug") + delete_custom_overlay_from_vc(ton, name) # delete overlay if election id is not in current or next election continue - if pure_name not in ton.get_custom_overlays(): - add_log(f"Overlay {name} is not in mtc db, deleting", "debug") - delete_custom_overlay_from_vc(name) # delete overlay if it's not in mtc db + elif pure_name not in ton.get_custom_overlays(): + local.add_log(f"Overlay {name} is not in mtc db, deleting", "debug") + delete_custom_overlay_from_vc(ton, name) # delete overlay if it's not in mtc db for name, config in ton.get_custom_overlays().items(): if name in names: @@ -123,13 +126,16 @@ def deploy_custom_overlays(): new_name = name + '_elid' + str(current_el_id) if new_name not in names: node_config = parse_config(new_name, config, current_vset) - add_custom_overlay_to_vc(node_config) + local.add_log(f"Adding custom overlay {config['name']}", "debug") + add_custom_overlay_to_vc(ton, node_config) if next_el_id != 0: new_name = name + '_elid' + str(next_el_id) if new_name not in names: node_config = parse_config(new_name, config, next_vset) - add_custom_overlay_to_vc(node_config) + local.add_log(f"Adding custom overlay {config['name']}", "debug") + add_custom_overlay_to_vc(ton, node_config) else: node_config = parse_config(name, config) - add_custom_overlay_to_vc(node_config) + local.add_log(f"Adding custom overlay {config['name']}", "debug") + add_custom_overlay_to_vc(ton, node_config) diff --git a/mytoncore.py b/mytoncore.py index 532b53df..bc7ee518 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -8,6 +8,7 @@ import requests import re from mypylib.mypylib import * +from custom_overlays import deploy_custom_overlays local = MyPyClass(__file__) @@ -4311,8 +4312,7 @@ def General(): local.start_cycle(Telemetry, sec=60, args=(ton, )) local.start_cycle(OverlayTelemetry, sec=7200, args=(ton, )) local.start_cycle(ScanLiteServers, sec=60, args=(ton,)) - from custom_overlays import deploy_custom_overlays - local.start_cycle(deploy_custom_overlays, sec=60) + local.start_cycle(deploy_custom_overlays, sec=60, args=(local, ton,)) thr_sleep() #end define diff --git a/mytonctrl.py b/mytonctrl.py index f32cc0ef..c05bf9f5 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -3,6 +3,8 @@ from mypylib.mypylib import * from mypyconsole.mypyconsole import * +from custom_overlays import add_custom_overlay, list_custom_overlays, delete_custom_overlay + from mytoncore import * import sys, getopt, os @@ -25,7 +27,6 @@ def Init(argv): console.AddItem("seqno", Seqno, local.translate("seqno_cmd")) console.AddItem("getconfig", GetConfig, local.translate("getconfig_cmd")) - from custom_overlays import add_custom_overlay, list_custom_overlays, delete_custom_overlay console.AddItem("add_custom_overlay", add_custom_overlay, local.translate("add_custom_overlay_cmd")) console.AddItem("list_custom_overlays", list_custom_overlays, local.translate("list_custom_overlays_cmd")) console.AddItem("delete_custom_overlay", delete_custom_overlay, local.translate("delete_custom_overlay_cmd")) From b0c15b362bc6a6809f37057b16e2ccdaf9046042 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 22:18:15 +0800 Subject: [PATCH 8/9] bugfix bugfix bugfix --- custom_overlays.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/custom_overlays.py b/custom_overlays.py index 94e31342..9a51b00f 100644 --- a/custom_overlays.py +++ b/custom_overlays.py @@ -93,7 +93,7 @@ def deploy_custom_overlays(local, ton): names = [] for line in result.split('\n'): if line.startswith('Overlay'): - names.append(line.split(' ')[1].replace('"', '')) + names.append(line.split(' ')[1].replace('"', '').replace(':', '')) config34 = ton.GetConfig34() current_el_id = config34['startWorkTime'] @@ -109,14 +109,14 @@ def deploy_custom_overlays(local, ton): suffix = name.split('_')[-1] if suffix.startswith('elid') and suffix.split('elid')[-1].isdigit(): # probably election id pure_name = '_'.join(name.split('_')[:-1]) - el_id = int(suffix.split('elid')[-1].isdigit()) + el_id = int(suffix.split('elid')[-1]) if el_id not in (current_el_id, next_el_id): local.add_log(f"Overlay {name} is not in current or next election, deleting", "debug") delete_custom_overlay_from_vc(ton, name) # delete overlay if election id is not in current or next election continue - elif pure_name not in ton.get_custom_overlays(): - local.add_log(f"Overlay {name} is not in mtc db, deleting", "debug") + if pure_name not in ton.get_custom_overlays(): + local.add_log(f"Overlay {name} ({pure_name}) is not in mtc db, deleting", "debug") delete_custom_overlay_from_vc(ton, name) # delete overlay if it's not in mtc db for name, config in ton.get_custom_overlays().items(): @@ -126,16 +126,16 @@ def deploy_custom_overlays(local, ton): new_name = name + '_elid' + str(current_el_id) if new_name not in names: node_config = parse_config(new_name, config, current_vset) - local.add_log(f"Adding custom overlay {config['name']}", "debug") + local.add_log(f"Adding custom overlay {name}", "debug") add_custom_overlay_to_vc(ton, node_config) if next_el_id != 0: new_name = name + '_elid' + str(next_el_id) if new_name not in names: node_config = parse_config(new_name, config, next_vset) - local.add_log(f"Adding custom overlay {config['name']}", "debug") + local.add_log(f"Adding custom overlay {name}", "debug") add_custom_overlay_to_vc(ton, node_config) else: node_config = parse_config(name, config) - local.add_log(f"Adding custom overlay {config['name']}", "debug") + local.add_log(f"Adding custom overlay {name}", "debug") add_custom_overlay_to_vc(ton, node_config) From cb8ab7df4b21e223869b6129fb6d6288e294c766 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 2 Apr 2024 22:33:51 +0800 Subject: [PATCH 9/9] logging improve --- custom_overlays.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_overlays.py b/custom_overlays.py index 9a51b00f..64dcbdcd 100644 --- a/custom_overlays.py +++ b/custom_overlays.py @@ -126,14 +126,14 @@ def deploy_custom_overlays(local, ton): new_name = name + '_elid' + str(current_el_id) if new_name not in names: node_config = parse_config(new_name, config, current_vset) - local.add_log(f"Adding custom overlay {name}", "debug") + local.add_log(f"Adding custom overlay {new_name}", "debug") add_custom_overlay_to_vc(ton, node_config) if next_el_id != 0: new_name = name + '_elid' + str(next_el_id) if new_name not in names: node_config = parse_config(new_name, config, next_vset) - local.add_log(f"Adding custom overlay {name}", "debug") + local.add_log(f"Adding custom overlay {new_name}", "debug") add_custom_overlay_to_vc(ton, node_config) else: node_config = parse_config(name, config)