Skip to content

Commit ff0c64e

Browse files
authored
Merge branch 'dev' into backup
2 parents 9074f6f + f483fc3 commit ff0c64e

File tree

8 files changed

+72
-69
lines changed

8 files changed

+72
-69
lines changed

modules/prometheus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ 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))
51-
if status.gcmasterchainblock is not None and status.last_deleted_mc_state is not None:
51+
if status.gcmasterchainblock is not None and status.last_deleted_mc_state is not None and status.last_deleted_mc_state != 0:
5252
result.append(METRICS['celldb_gc_state'].to_format(status.gcmasterchainblock - status.last_deleted_mc_state))
5353
result.append(METRICS['vc_up'].to_format(int(is_working)))
5454

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: 1 addition & 3 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

@@ -144,7 +143,7 @@ def set_node_argument(local, args):
144143
"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'")
145144
return
146145
arg_name = args[0]
147-
args = [arg_name, args[1] if len(args) > 1 else ""]
146+
args = [arg_name, " ".join(args[1:])]
148147
script_path = pkg_resources.resource_filename('mytoninstaller.scripts', 'set_node_argument.py')
149148
run_as_root(['python3', script_path] + args)
150149
color_print("set_node_argument - {green}OK{endc}")
@@ -295,7 +294,6 @@ def General(local, console):
295294
FirstNodeSettings(local)
296295
EnableValidatorConsole(local)
297296
EnableLiteServer(local)
298-
BackupVconfig(local)
299297
BackupMconfig(local)
300298
CreateSymlinks(local)
301299
EnableMode(local)

mytoninstaller/node_args.py

Lines changed: 16 additions & 40 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,43 +14,19 @@ def get_node_start_command():
1414
return line.split('=')[1].strip()
1515
#end define
1616

17-
18-
"""
19-
def get_node_args(command: str = None):
20-
if command is None:
21-
command = get_node_start_command()
22-
result = []
23-
key = ''
24-
for c in command.split(' ')[1:]:
25-
if c.startswith('--') or c.startswith('-'):
26-
if key:
27-
result.append([key, ''])
28-
key = c
29-
elif key:
30-
result.append([key, c])
31-
key = ''
32-
if key:
33-
result.append([key, ''])
34-
return result
35-
#end define
36-
"""
37-
38-
39-
def get_node_args(command: str = None):
40-
if command is None:
41-
command = get_node_start_command()
42-
result = {} # {key: [value1, value2]}
43-
key = ''
44-
for c in command.split(' ')[1:]:
45-
if c.startswith('--') or c.startswith('-'):
46-
if key:
47-
result[key] = result.get(key, []) + ['']
48-
key = c
49-
elif key:
50-
result[key] = result.get(key, []) + [c]
51-
key = ''
52-
if key:
53-
result[key] = result.get(key, []) + ['']
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
21+
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)
5431
return result
5532
#end define
56-

mytoninstaller/scripts/set_node_argument.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +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:
2326
if ' ' in arg_value:
24-
args[arg_name] = arg_value.split()
27+
node_args[arg_name] = arg_value.split()
2528
else:
26-
args[arg_name] = [arg_value]
27-
new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, vs in args.items() for v in vs])
28-
new_service = service.replace(command, new_command)
29-
with open('/etc/systemd/system/validator.service', 'w') as f:
30-
f.write(new_service)
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)
3143
restart_node()
3244
#end define
3345

mytoninstaller/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ 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+
70+
if os.getenv('ADD_SHARD'):
71+
add_shard = os.getenv('ADD_SHARD')
72+
cmd += f' -M'
73+
for shard in add_shard.split():
74+
cmd += f' --add-shard {shard}'
75+
6976
add2systemd(name="validator", user=vuser, start=cmd) # post="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py -e \"validator down\""
7077

7178
# Получить внешний ip адрес

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':

scripts/install.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ fi
8888
if [ "${mode}" = "none" ] && [ "$backup" = "none" ]; then # no mode or backup was provided
8989
echo "Running cli installer"
9090
wget https://raw.githubusercontent.com/${author}/${repo}/${branch}/scripts/install.py
91-
pip3 install inquirer==3.4.0
91+
python3 -m pip install --upgrade pip
92+
pip3 install inquirer==3.4.0 --break-system-packages
9293
python3 install.py
9394
exit
9495
fi
@@ -123,6 +124,16 @@ if [[ "$OSTYPE" =~ darwin.* ]]; then
123124
mkdir -p ${SOURCES_DIR}
124125
fi
125126

127+
128+
if [ ! -f ~/.config/pip/pip.conf ]; then # create pip config
129+
mkdir -p ~/.config/pip
130+
cat > ~/.config/pip/pip.conf <<EOF
131+
[global]
132+
break-system-packages = true
133+
EOF
134+
fi
135+
136+
126137
# check TON components
127138
file1=${BIN_DIR}/ton/crypto/fift
128139
file2=${BIN_DIR}/ton/lite-client/lite-client

0 commit comments

Comments
 (0)