Skip to content

Commit 9363982

Browse files
committed
add gc import/ dir
1 parent b4181c6 commit 9363982

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

modules/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class Setting:
6262
'auto_backup': Setting('validator', None, 'Make validator backup every election'),
6363
'auto_backup_path': Setting('validator', '/tmp/mytoncore/auto_backups/', 'Path to store auto-backups'),
6464
'prometheus_url': Setting('prometheus', None, 'Prometheus pushgateway url'),
65-
'onlyNode': Setting(None, None, 'MyTonCtrl will work only for collecting validator telemetry (if `sendTelemetry` is True), without participating in Elections and etc.')
65+
'onlyNode': Setting(None, None, 'MyTonCtrl will work only for collecting validator telemetry (if `sendTelemetry` is True), without participating in Elections and etc.'),
66+
'importGc': Setting(None, None, 'Delete imported archive blocks files. Restart mytoncore to apply this setting'),
6667
}
6768

6869

mytoncore/functions.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,35 @@ def check_initial_sync(local, ton):
602602
return
603603

604604

605+
def gc_import(local, ton):
606+
if not ton.local.db.get('importGc', False):
607+
return
608+
local.add_log("GC import is running", "debug")
609+
import_path = '/var/ton-work/db/import'
610+
files = os.listdir(import_path)
611+
if not files:
612+
local.add_log("No files left to import", "debug")
613+
ton.local.db['importGc'] = False
614+
return
615+
try:
616+
status = ton.GetValidatorStatus()
617+
node_seqno = int(status.shardclientmasterchainseqno)
618+
except Exception as e:
619+
local.add_log(f"Failed to get shardclientmasterchainseqno: {e}", "warning")
620+
return
621+
removed = 0
622+
for file in files:
623+
file_seqno = int(file.split('.')[1])
624+
if node_seqno > file_seqno + 101:
625+
try:
626+
os.remove(os.path.join(import_path, file))
627+
removed += 1
628+
except PermissionError:
629+
local.add_log(f"Failed to remove file {file}: Permission denied", "error")
630+
continue
631+
local.add_log(f"Removed {removed} import files up to {node_seqno} seqno", "debug")
632+
633+
605634
def General(local):
606635
local.add_log("start General function", "debug")
607636
ton = MyTonCore(local)
@@ -642,6 +671,9 @@ def General(local):
642671
if ton.in_initial_sync():
643672
local.start_cycle(check_initial_sync, sec=120, args=(local, ton))
644673

674+
if ton.local.db.get('importGc'):
675+
local.start_cycle(gc_import, sec=300, args=(local, ton))
676+
645677
thr_sleep()
646678
# end define
647679

mytoninstaller/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def download_archive_from_ts(local):
269269
for bag in block_bags + master_block_bags:
270270
subprocess.run(f'mv {downloads_path}/{bag["bag"]}/packages/*/* {import_dir}', shell=True)
271271
# subprocess.run(['rm', '-rf', f"{downloads_path}/{bag['bag']}"])
272-
subprocess.run(['rm', '-rf', downloads_path + '*'])
272+
subprocess.run(f'rm -rf {downloads_path}*', shell=True)
273273

274274
stop_service(local, "ton_storage") # stop TS
275275
disable_service(local, "ton_storage")
@@ -285,6 +285,13 @@ def download_archive_from_ts(local):
285285
if c['validator']['hardforks'] and c['validator']['hardforks'][-1]['seqno'] > block_from:
286286
run_process_hardforks(local, block_from)
287287

288+
local.add_log(f"Changing permissions on imported files", "info")
289+
subprocess.run(["chmod", "o+w", import_dir])
290+
mconfig_path = local.buffer.mconfig_path
291+
mconfig = GetConfig(path=mconfig_path)
292+
mconfig.importGc = True
293+
SetConfig(path=mconfig_path, data=mconfig)
294+
288295

289296
def run_process_hardforks(local, from_seqno: int):
290297
script_path = os.path.join(local.buffer.mtc_src_dir, 'mytoninstaller', 'scripts', 'process_hardforks.py')

scripts/install.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def validate_archive_blocks(value):
4646
return "Block number cannot be negative"
4747
elif not part.isdigit() and not is_valid_date_format(part):
4848
return "Incorrect date format, use YYYY-MM-DD"
49+
if len(parts) == 2 and parts[1].isdigit() and parts[0].isdigit():
50+
if int(parts[1]) < int(parts[0]):
51+
return "End block seqno cannot be less than start block seqno"
4952
return True
5053

5154

0 commit comments

Comments
 (0)