Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions mytonctrl/mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions mytoninstaller/mytoninstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-name> [arg-value] [-d (to delete)]")
color_print("{red}Bad args. Usage:{endc} set_node_argument <arg-name> [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}")
Expand Down
8 changes: 4 additions & 4 deletions mytoninstaller/node_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 5 additions & 2 deletions mytoninstaller/scripts/set_node_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions mytoninstaller/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 адрес
Expand Down
10 changes: 10 additions & 0 deletions scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <workchain>:<shard>. Divide multiple shards with space. "
"Example: `0:2000000000000000 0:6000000000000000`",
validate=lambda _, x: not x or all([":" in i for i in x.split()])
)
]

Expand All @@ -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"]

Expand All @@ -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':
Expand Down