From 118dd69b0f27ecf40996570265eb6a56c3e82556 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 28 Nov 2024 14:13:57 +0900 Subject: [PATCH 1/3] support multiple node args with same name --- mytoninstaller/mytoninstaller.py | 8 +++++--- mytoninstaller/node_args.py | 8 ++++---- mytoninstaller/scripts/set_node_argument.py | 7 +++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mytoninstaller/mytoninstaller.py b/mytoninstaller/mytoninstaller.py index 270afe97..24e964ea 100644 --- a/mytoninstaller/mytoninstaller.py +++ b/mytoninstaller/mytoninstaller.py @@ -133,16 +133,18 @@ def Status(local, args): node_args = get_node_args() color_print("{cyan}===[ Node arguments ]==={endc}") for key, value in node_args.items(): - print(f"{key}: {value}") + for v in value: + print(f"{key}: {v}") #end define def set_node_argument(local, args): if len(args) < 1: - color_print("{red}Bad args. Usage:{endc} set_node_argument [arg-value] [-d (to delete)]") + color_print("{red}Bad args. Usage:{endc} set_node_argument [arg-value] [-d (to delete)].\n" + "Examples: 'set_node_argument --archive-ttl 86400' or 'set_node_argument --archive-ttl -d' or 'set_node_argument -M' or 'set_node_argument --add-shard 0:2000000000000000 0:a000000000000000'") return arg_name = args[0] - args = [arg_name, args[1] if len(args) > 1 else ""] + args = [arg_name, " ".join(args[1:])] script_path = pkg_resources.resource_filename('mytoninstaller.scripts', 'set_node_argument.py') run_as_root(['python3', script_path] + args) color_print("set_node_argument - {green}OK{endc}") diff --git a/mytoninstaller/node_args.py b/mytoninstaller/node_args.py index af7b8380..0c5fe3d0 100644 --- a/mytoninstaller/node_args.py +++ b/mytoninstaller/node_args.py @@ -18,18 +18,18 @@ def get_node_start_command(): def get_node_args(command: str = None): if command is None: command = get_node_start_command() - result = {} + result = {} # {key: [value1, value2]} key = '' for c in command.split(' ')[1:]: if c.startswith('--') or c.startswith('-'): if key: - result[key] = '' + result[key] = result.get(key, []) + [''] key = c elif key: - result[key] = c + result[key] = result.get(key, []) + [c] key = '' if key: - result[key] = '' + result[key] = result.get(key, []) + [''] return result #end define diff --git a/mytoninstaller/scripts/set_node_argument.py b/mytoninstaller/scripts/set_node_argument.py index 19fe67a5..cd241bea 100644 --- a/mytoninstaller/scripts/set_node_argument.py +++ b/mytoninstaller/scripts/set_node_argument.py @@ -20,8 +20,11 @@ def set_node_arg(arg_name: str, arg_value: str = ''): if arg_value == '-d': args.pop(arg_name, None) else: - args[arg_name] = arg_value - new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, v in args.items()]) + if ' ' in arg_value: + args[arg_name] = arg_value.split() + else: + args[arg_name] = [arg_value] + new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, vs in args.items() for v in vs]) new_service = service.replace(command, new_command) with open('/etc/systemd/system/validator.service', 'w') as f: f.write(new_service) From 37593eb4b123a3f4e563c5e08f7bf498c584f0e6 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 28 Nov 2024 14:16:49 +0900 Subject: [PATCH 2/3] dont remove state-ttl for vals on updates --- mytonctrl/mytonctrl.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index de3d7ce8..25e340fc 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -369,14 +369,6 @@ def Upgrade(ton, args): upgrade_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/upgrade.sh') runArgs = ["bash", upgrade_script_path, "-a", author, "-r", repo, "-b", branch] exitCode = run_as_root(runArgs) - if ton.using_validator(): - try: - from mytoninstaller.mytoninstaller import set_node_argument, get_node_args - node_args = get_node_args() - if node_args.get('--state-ttl') == '604800': - set_node_argument(ton.local, ["--state-ttl", "-d"]) - except Exception as e: - color_print(f"{{red}}Failed to set node argument: {e} {{endc}}") if exitCode == 0: text = "Upgrade - {green}OK{endc}" else: From 647f34e18f84310e6ff427b81c2c77bb9b07bf19 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 2 Dec 2024 20:14:46 +0900 Subject: [PATCH 3/3] add add-shard to installer --- mytoninstaller/settings.py | 7 +++++++ scripts/install.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/mytoninstaller/settings.py b/mytoninstaller/settings.py index cba219ea..b9ce9940 100644 --- a/mytoninstaller/settings.py +++ b/mytoninstaller/settings.py @@ -63,6 +63,13 @@ def FirstNodeSettings(local): # Прописать автозагрузку cpus = psutil.cpu_count() - 1 cmd = f"{validatorAppPath} --threads {cpus} --daemonize --global-config {globalConfigPath} --db {ton_db_dir} --logname {tonLogPath} --archive-ttl {archive_ttl} --verbosity 1" + + if os.getenv('ADD_SHARD'): + add_shard = os.getenv('ADD_SHARD') + cmd += f' -M' + for shard in add_shard.split(): + cmd += f' --add-shard {shard}' + add2systemd(name="validator", user=vuser, start=cmd) # post="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py -e \"validator down\"" # Получить внешний ip адрес diff --git a/scripts/install.py b/scripts/install.py index aa43c0ac..bfb569b4 100644 --- a/scripts/install.py +++ b/scripts/install.py @@ -38,6 +38,13 @@ def run_cli(): "dump", message="Do you want to download blockchain's dump? " "This reduces synchronization time but requires to download a large file", + ), + inquirer.Text( + "add-shard", + message="Set shards node will sync. Skip to sync all shards. " + "Format: :. Divide multiple shards with space. " + "Example: `0:2000000000000000 0:6000000000000000`", + validate=lambda _, x: not x or all([":" in i for i in x.split()]) ) ] @@ -51,6 +58,7 @@ def parse_args(answers: dict): network = answers["network"].lower() config = answers["config"] archive_ttl = answers["archive-ttl"] + add_shard = answers["add-shard"] validator_mode = answers["validator-mode"] dump = answers["dump"] @@ -61,6 +69,8 @@ def parse_args(answers: dict): if archive_ttl: os.putenv('ARCHIVE_TTL', archive_ttl) # set env variable + if add_shard: + os.putenv('ADD_SHARD', add_shard) if validator_mode and validator_mode not in ('Skip', 'Validator wallet'): if validator_mode == 'Nominator pool':