Skip to content

Commit b427c27

Browse files
authored
Merge branch 'dev' into exec-start-pre
2 parents 7198ed1 + 5281abc commit b427c27

File tree

11 files changed

+91
-57
lines changed

11 files changed

+91
-57
lines changed

modules/alert_bot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def disable_alert(self, args):
218218
color_print("disable_alert - {green}OK{endc}")
219219

220220
def print_alerts(self, args):
221+
init_alerts()
221222
table = [['Name', 'Enabled', 'Last sent']]
222223
for alert_name in ALERTS:
223224
alert = self.get_alert_from_db(alert_name)
@@ -337,7 +338,7 @@ def check_stake_returned(self):
337338
if not self.ton.using_validator():
338339
return
339340
config = self.ton.GetConfig32()
340-
if not (config['endWorkTime'] + FREEZE_PERIOD + 1800 <= time.time() < config['endWorkTime'] + FREEZE_PERIOD + 1860): # check between 25th and 26th minutes after stakes have been unfrozen
341+
if not (config['endWorkTime'] + FREEZE_PERIOD + 1800 <= time.time() < config['endWorkTime'] + FREEZE_PERIOD + 1860): # check between 30th and 31st minutes after stakes have been unfrozen
341342
return
342343
res = self.get_myself_from_election(config)
343344
if not res:
@@ -356,6 +357,9 @@ def check_voting(self):
356357
validator_index = self.ton.GetValidatorIndex()
357358
if validator_index == -1:
358359
return
360+
config = self.ton.GetConfig34()
361+
if time.time() - config['startWorkTime'] < 600: # less than 10 minutes passed since round start
362+
return
359363
need_to_vote = []
360364
offers = self.ton.GetOffers()
361365
for offer in offers:

modules/prometheus.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ def get_validator_status_metrics(self, result: list):
4444
result.append(METRICS['master_out_of_sync'].to_format(status.masterchain_out_of_sync))
4545
if status.shardchain_out_of_sync is not None:
4646
result.append(METRICS['shard_out_of_sync'].to_format(status.shardchain_out_of_sync))
47-
if status.masterchain_out_of_ser is not None:
47+
if status.masterchain_out_of_ser is not None and status.stateserializermasterchainseqno != 0:
4848
result.append(METRICS['out_of_ser'].to_format(status.masterchain_out_of_ser))
4949
if status.masterchainblock is not None and status.gcmasterchainblock is not None:
5050
result.append(METRICS['celldb_gc_block'].to_format(status.masterchainblock - status.gcmasterchainblock))
5151
if status.gcmasterchainblock is not None and status.last_deleted_mc_state is not None:
52-
result.append(METRICS['celldb_gc_state'].to_format(status.gcmasterchainblock - status.last_deleted_mc_state))
52+
if status.last_deleted_mc_state != 0:
53+
result.append(METRICS['celldb_gc_state'].to_format(status.gcmasterchainblock - status.last_deleted_mc_state))
54+
else:
55+
result.append(METRICS['celldb_gc_state'].to_format(-1))
5356
result.append(METRICS['vc_up'].to_format(int(is_working)))
5457

5558
def get_validator_validation_metrics(self, result: list):

mytonctrl/mytonctrl.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,6 @@ def Upgrade(ton, args):
370370
upgrade_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/upgrade.sh')
371371
runArgs = ["bash", upgrade_script_path, "-a", author, "-r", repo, "-b", branch]
372372
exitCode = run_as_root(runArgs)
373-
if ton.using_validator():
374-
try:
375-
from mytoninstaller.mytoninstaller import set_node_argument, get_node_args
376-
node_args = get_node_args()
377-
if node_args.get('--state-ttl') == '604800':
378-
set_node_argument(ton.local, ["--state-ttl", "-d"])
379-
except Exception as e:
380-
color_print(f"{{red}}Failed to set node argument: {e} {{endc}}")
381373
if exitCode == 0:
382374
text = "Upgrade - {green}OK{endc}"
383375
else:

mytonctrl/scripts/restore_backup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ do
1616
esac
1717
done
1818

19+
if [ ! -f "$name" ]; then
20+
echo "Backup file not found, aborting."
21+
exit 1
22+
fi
1923

2024
COLOR='\033[92m'
2125
ENDC='\033[0m'
@@ -43,6 +47,8 @@ rm -rf /var/ton-work/db/keyring
4347

4448
chown -R $user:$user ${tmp_dir}/mytoncore
4549
chown -R $user:$user ${tmp_dir}/keys
50+
chown validator:validator ${tmp_dir}/keys
51+
chown -R validator:validator ${tmp_dir}/db
4652

4753
cp -rfp ${tmp_dir}/db /var/ton-work
4854
cp -rfp ${tmp_dir}/keys /var/ton-work

mytoninstaller/config.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ def backup_config(local, config_path):
4343
#end define
4444

4545

46-
def BackupVconfig(local):
47-
if local.buffer.only_mtc:
48-
return
49-
local.add_log("Backup validator config file 'config.json' to 'config.json.backup'", "debug")
50-
vconfig_path = local.buffer.vconfig_path
51-
backupPath = vconfig_path + ".backup"
52-
args = ["cp", vconfig_path, backupPath]
53-
subprocess.run(args)
54-
#end define
55-
56-
5746
def BackupMconfig(local):
5847
local.add_log("Backup mytoncore config file 'mytoncore.db' to 'mytoncore.db.backup'", "debug")
5948
mconfig_path = local.buffer.mconfig_path

mytoninstaller/mytoninstaller.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
)
3535
from mytoninstaller.config import (
3636
CreateLocalConfig,
37-
BackupVconfig,
3837
BackupMconfig,
3938
)
4039

@@ -133,16 +132,18 @@ def Status(local, args):
133132
node_args = get_node_args()
134133
color_print("{cyan}===[ Node arguments ]==={endc}")
135134
for key, value in node_args.items():
136-
print(f"{key}: {value}")
135+
for v in value:
136+
print(f"{key}: {v}")
137137
#end define
138138

139139

140140
def set_node_argument(local, args):
141141
if len(args) < 1:
142-
color_print("{red}Bad args. Usage:{endc} set_node_argument <arg-name> [arg-value] [-d (to delete)]")
142+
color_print("{red}Bad args. Usage:{endc} set_node_argument <arg-name> [arg-value] [-d (to delete)].\n"
143+
"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'")
143144
return
144145
arg_name = args[0]
145-
args = [arg_name, args[1] if len(args) > 1 else ""]
146+
args = [arg_name, " ".join(args[1:])]
146147
script_path = pkg_resources.resource_filename('mytoninstaller.scripts', 'set_node_argument.py')
147148
run_as_root(['python3', script_path] + args)
148149
color_print("set_node_argument - {green}OK{endc}")
@@ -293,7 +294,6 @@ def General(local, console):
293294
FirstNodeSettings(local)
294295
EnableValidatorConsole(local)
295296
EnableLiteServer(local)
296-
BackupVconfig(local)
297297
BackupMconfig(local)
298298
CreateSymlinks(local)
299299
EnableMode(local)

mytoninstaller/node_args.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
def get_validator_service():
44
path = '/etc/systemd/system/validator.service'
5-
with open(path, 'r') as f:
6-
return f.read()
5+
with open(path, 'r') as file:
6+
return file.read()
77
#end define
88

99

@@ -14,22 +14,19 @@ def get_node_start_command():
1414
return line.split('=')[1].strip()
1515
#end define
1616

17+
def get_node_args(start_command: str = None):
18+
if start_command is None:
19+
start_command = get_node_start_command()
20+
#end if
1721

18-
def get_node_args(command: str = None):
19-
if command is None:
20-
command = get_node_start_command()
21-
result = {}
22-
key = ''
23-
for c in command.split(' ')[1:]:
24-
if c.startswith('--') or c.startswith('-'):
25-
if key:
26-
result[key] = ''
27-
key = c
28-
elif key:
29-
result[key] = c
30-
key = ''
31-
if key:
32-
result[key] = ''
22+
result = dict() # {key: [value1, value2]}
23+
node_args = start_command.split(' ')[1:]
24+
key = None
25+
for item in node_args:
26+
if item.startswith('-'):
27+
key = item
28+
result[key] = list()
29+
else:
30+
result[key].append(item)
3331
return result
3432
#end define
35-

mytoninstaller/scripts/set_node_argument.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,35 @@ def set_node_arg(arg_name: str, arg_value: str = ''):
1111
"""
1212
assert arg_name.startswith('-'), 'arg_name must start with "-" or "--"'
1313
service = get_validator_service()
14-
command = get_node_start_command()
15-
if command.split(' ')[0] != '/usr/bin/ton/validator-engine/validator-engine':
16-
raise Exception('Invalid node start command in service file')
17-
if command is None:
14+
start_command = get_node_start_command()
15+
if start_command is None:
1816
raise Exception('Cannot find node start command in service file')
19-
args = get_node_args(command)
17+
first_arg = start_command.split(' ')[0]
18+
if first_arg != '/usr/bin/ton/validator-engine/validator-engine':
19+
raise Exception('Invalid node start command in service file')
20+
#end if
21+
22+
node_args = get_node_args(start_command)
2023
if arg_value == '-d':
21-
args.pop(arg_name, None)
24+
node_args.pop(arg_name, None)
2225
else:
23-
args[arg_name] = arg_value
24-
new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, v in args.items()])
25-
new_service = service.replace(command, new_command)
26-
with open('/etc/systemd/system/validator.service', 'w') as f:
27-
f.write(new_service)
26+
if ' ' in arg_value:
27+
node_args[arg_name] = arg_value.split()
28+
else:
29+
node_args[arg_name] = [arg_value]
30+
#end if
31+
32+
buffer = list()
33+
buffer.append(first_arg)
34+
for key, value_list in node_args.items():
35+
if len(value_list) == 0:
36+
buffer.append(f"{key}")
37+
for value in value_list:
38+
buffer.append(f"{key} {value}")
39+
new_start_command = ' '.join(buffer)
40+
new_service = service.replace(start_command, new_start_command)
41+
with open('/etc/systemd/system/validator.service', 'w') as file:
42+
file.write(new_service)
2843
restart_node()
2944
#end define
3045

mytoninstaller/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ def FirstNodeSettings(local):
6666
# Прописать автозагрузку
6767
cpus = psutil.cpu_count() - 1
6868
cmd = f"{validatorAppPath} --threads {cpus} --daemonize --global-config {globalConfigPath} --db {ton_db_dir} --logname {tonLogPath} --archive-ttl {archive_ttl} --verbosity 1"
69+
6970
add2systemd(name="validator", user=vuser, start=cmd, pre='/bin/sleep 2') # post="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py -e \"validator down\""
7071

72+
if os.getenv('ADD_SHARD'):
73+
add_shard = os.getenv('ADD_SHARD')
74+
cmd += f' -M'
75+
for shard in add_shard.split():
76+
cmd += f' --add-shard {shard}'
77+
7178
# Получить внешний ip адрес
7279
ip = get_own_ip()
7380
vport = random.randint(2000, 65000)

scripts/install.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def run_cli():
3838
"dump",
3939
message="Do you want to download blockchain's dump? "
4040
"This reduces synchronization time but requires to download a large file",
41+
),
42+
inquirer.Text(
43+
"add-shard",
44+
message="Set shards node will sync. Skip to sync all shards. "
45+
"Format: <workchain>:<shard>. Divide multiple shards with space. "
46+
"Example: `0:2000000000000000 0:6000000000000000`",
47+
validate=lambda _, x: not x or all([":" in i for i in x.split()])
4148
)
4249
]
4350

@@ -51,6 +58,7 @@ def parse_args(answers: dict):
5158
network = answers["network"].lower()
5259
config = answers["config"]
5360
archive_ttl = answers["archive-ttl"]
61+
add_shard = answers["add-shard"]
5462
validator_mode = answers["validator-mode"]
5563
dump = answers["dump"]
5664

@@ -61,6 +69,8 @@ def parse_args(answers: dict):
6169

6270
if archive_ttl:
6371
os.putenv('ARCHIVE_TTL', archive_ttl) # set env variable
72+
if add_shard:
73+
os.putenv('ADD_SHARD', add_shard)
6474

6575
if validator_mode and validator_mode not in ('Skip', 'Validator wallet'):
6676
if validator_mode == 'Nominator pool':

0 commit comments

Comments
 (0)