Skip to content

Commit c4ac040

Browse files
committed
add initial sync to mtc
1 parent 028e67e commit c4ac040

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

mytoncore/functions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ def ScanLiteServers(local, ton):
544544
# end define
545545

546546

547+
def check_initial_sync(local, ton):
548+
if not ton.in_initial_sync():
549+
return
550+
validator_status = ton.GetValidatorStatus()
551+
if validator_status.initial_sync:
552+
return
553+
if validator_status.out_of_sync < 20:
554+
ton.set_initial_sync_off()
555+
return
556+
557+
547558
def General(local):
548559
local.add_log("start General function", "debug")
549560
ton = MyTonCore(local)
@@ -579,6 +590,9 @@ def General(local):
579590
from modules.prometheus import PrometheusModule
580591
local.start_cycle(PrometheusModule(ton, local).push_metrics, sec=30, args=())
581592

593+
if ton.in_initial_sync():
594+
local.start_cycle(check_initial_sync, sec=120, args=(local, ton))
595+
582596
thr_sleep()
583597
# end define
584598

mytoncore/mytoncore.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ def GetValidatorStatus(self):
781781

782782
self.local.add_log("start GetValidatorStatus function", "debug")
783783
status = Dict()
784+
result = None
784785
try:
785786
# Parse
786787
status.is_working = True
@@ -808,7 +809,8 @@ def GetValidatorStatus(self):
808809
except Exception as ex:
809810
self.local.add_log(f"GetValidatorStatus warning: {ex}", "warning")
810811
status.is_working = False
811-
self.local.try_function(self.parse_stats_from_vc, args=[result, status])
812+
if result is not None:
813+
self.local.try_function(self.parse_stats_from_vc, args=[result, status])
812814
#end try
813815
status.initial_sync = status.get("process.initial_sync")
814816

@@ -3137,6 +3139,13 @@ def using_alert_bot(self):
31373139
def using_prometheus(self):
31383140
return self.get_mode_value('prometheus')
31393141

3142+
def in_initial_sync(self):
3143+
return self.local.db.get('initialSync', False)
3144+
3145+
def set_initial_sync_off(self):
3146+
self.local.db.pop('initialSync', None)
3147+
self.local.save()
3148+
31403149
def Tlb2Json(self, text):
31413150
# Заменить скобки
31423151
start = 0

mytonctrl/mytonctrl.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def check_disk_usage(local, ton):
440440

441441
def check_sync(local, ton):
442442
validator_status = ton.GetValidatorStatus()
443-
if validator_status.initial_sync:
443+
if validator_status.initial_sync or ton.in_initial_sync():
444444
print_warning(local, "initial_sync_warning")
445445
return
446446
if not validator_status.is_working or validator_status.out_of_sync >= 20:
@@ -733,12 +733,18 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
733733
validatorStatus_text = local.translate("local_status_validator_status").format(validatorStatus_color, validatorUptime_text)
734734

735735
validator_initial_sync_text = ''
736+
validator_out_of_sync_text = ''
736737

737738
if validator_status.initial_sync:
738739
validator_initial_sync_text = local.translate("local_status_validator_initial_sync").format(validator_status['process.initial_sync'])
739-
validator_out_of_sync_text = local.translate("local_status_validator_out_of_sync").format(GetColorInt(validator_status.out_of_sync, 20, logic="less"))
740-
master_out_of_sync_text = local.translate("local_status_master_out_of_sync").format(GetColorInt(validator_status.masterchain_out_of_sync, 20, logic="less", ending=" sec"))
741-
shard_out_of_sync_text = local.translate("local_status_shard_out_of_sync").format(GetColorInt(validator_status.shardchain_out_of_sync, 5, logic="less", ending=" blocks"))
740+
elif ton.in_initial_sync(): # states have been downloaded, now downloading blocks
741+
validator_initial_sync_text = local.translate("local_status_validator_initial_sync").format(
742+
f'Syncing blocks, last known block was {validator_status.out_of_sync} s ago'
743+
)
744+
else:
745+
validator_out_of_sync_text = local.translate("local_status_validator_out_of_sync").format(GetColorInt(validator_status.out_of_sync, 20, logic="less"))
746+
master_out_of_sync_text = local.translate("local_status_master_out_of_sync").format(GetColorInt(validator_status.masterchain_out_of_sync, 20, logic="less", ending=" sec"))
747+
shard_out_of_sync_text = local.translate("local_status_shard_out_of_sync").format(GetColorInt(validator_status.shardchain_out_of_sync, 5, logic="less", ending=" blocks"))
742748

743749
validator_out_of_ser_text = local.translate("local_status_validator_out_of_ser").format(f'{validator_status.out_of_ser} blocks ago')
744750

@@ -785,11 +791,12 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
785791
print(mytoncoreStatus_text)
786792
if not is_node_remote:
787793
print(validatorStatus_text)
788-
if validator_status.initial_sync:
794+
if validator_initial_sync_text:
789795
print(validator_initial_sync_text)
790-
print(validator_out_of_sync_text)
791-
print(master_out_of_sync_text)
792-
print(shard_out_of_sync_text)
796+
if validator_out_of_sync_text:
797+
print(validator_out_of_sync_text)
798+
print(master_out_of_sync_text)
799+
print(shard_out_of_sync_text)
793800
print(validator_out_of_ser_text)
794801
print(dbStatus_text)
795802
print(mtcVersion_text)

mytoninstaller/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def FirstMytoncoreSettings(local):
206206
# Telemetry
207207
mconfig.sendTelemetry = local.buffer.telemetry
208208

209+
mconfig.initialSync = True
210+
209211
# Записать настройки в файл
210212
SetConfig(path=mconfig_path, data=mconfig)
211213

0 commit comments

Comments
 (0)