@@ -53,8 +53,6 @@ def Event(local, event_name):
5353 EnableVcEvent (local )
5454 elif event_name == "validator down" :
5555 ValidatorDownEvent (local )
56- elif event_name == "enable_ton_storage_provider" :
57- enable_ton_storage_provider_event (local )
5856 elif event_name .startswith ("enable_mode" ):
5957 enable_mode (local , event_name )
6058 elif event_name == "enable_btc_teleport" :
@@ -86,15 +84,6 @@ def ValidatorDownEvent(local):
8684# end define
8785
8886
89- def enable_ton_storage_provider_event (local ):
90- config_path = local .db .ton_storage .provider .config_path
91- config = GetConfig (path = config_path )
92- key_bytes = base64 .b64decode (config .ProviderKey )
93- ton = MyTonCore (local )
94- ton .import_wallet_with_version (key_bytes [:32 ], version = "v3r2" , wallet_name = "provider_wallet_001" )
95- #end define
96-
97-
9887def enable_mode (local , event_name ):
9988 ton = MyTonCore (local )
10089 mode = event_name .split ("_" )[- 1 ]
@@ -292,6 +281,64 @@ def CalculateNetworkStatistics(zerodata, data):
292281# end define
293282
294283
284+ def save_node_statistics (local , ton ):
285+ status = ton .GetValidatorStatus (no_cache = True )
286+ if status .unixtime is None :
287+ return
288+ data = {'timestamp' : status .unixtime }
289+
290+ def get_ok_error (value : str ):
291+ ok , error = value .split ()
292+ return int (ok .split (':' )[1 ]), int (error .split (':' )[1 ])
293+
294+ if 'total.collated_blocks.master' in status :
295+ master_ok , master_error = get_ok_error (status ['total.collated_blocks.master' ])
296+ shard_ok , shard_error = get_ok_error (status ['total.collated_blocks.shard' ])
297+ data ['collated_blocks' ] = {
298+ 'master' : {'ok' : master_ok , 'error' : master_error },
299+ 'shard' : {'ok' : shard_ok , 'error' : shard_error },
300+ }
301+ if 'total.validated_blocks.master' in status :
302+ master_ok , master_error = get_ok_error (status ['total.validated_blocks.master' ])
303+ shard_ok , shard_error = get_ok_error (status ['total.validated_blocks.shard' ])
304+ data ['validated_blocks' ] = {
305+ 'master' : {'ok' : master_ok , 'error' : master_error },
306+ 'shard' : {'ok' : shard_ok , 'error' : shard_error },
307+ }
308+ if 'total.ext_msg_check' in status :
309+ ok , error = get_ok_error (status ['total.ext_msg_check' ])
310+ data ['ext_msg_check' ] = {'ok' : ok , 'error' : error }
311+ if 'total.ls_queries_ok' in status and 'total.ls_queries_error' in status :
312+ data ['ls_queries' ] = {}
313+ for k in status ['total.ls_queries_ok' ].split ():
314+ if k .startswith ('TOTAL' ):
315+ data ['ls_queries' ]['ok' ] = int (k .split (':' )[1 ])
316+ for k in status ['total.ls_queries_error' ].split ():
317+ if k .startswith ('TOTAL' ):
318+ data ['ls_queries' ]['error' ] = int (k .split (':' )[1 ])
319+ statistics = local .db .get ("statistics" , dict ())
320+
321+ if time .time () - int (status .start_time ) <= 60 : # was node restart <60 sec ago, resetting node statistics
322+ statistics ['node' ] = []
323+
324+ # statistics['node'] = [stats_from_election_id, stats_from_prev_min, stats_now]
325+
326+ election_id = ton .GetConfig34 ()['startWorkTime' ]
327+ if 'node' not in statistics or len (statistics ['node' ]) == 0 :
328+ statistics ['node' ] = [None , data ]
329+ elif len (statistics ['node' ]) < 3 :
330+ statistics ['node' ].append (data )
331+ if len (statistics ['node' ]) == 3 :
332+ if statistics ['node' ][0 ] is None :
333+ if 0 < data ['timestamp' ] - election_id < 90 :
334+ statistics ['node' ][0 ] = data
335+ elif statistics ['node' ][0 ]['timestamp' ] < election_id :
336+ statistics ['node' ][0 ] = data
337+ statistics ['node' ] = statistics .get ('node' , []) + [data ]
338+ statistics ['node' ].pop (1 )
339+ local .db ["statistics" ] = statistics
340+
341+
295342def ReadTransData (local , scanner ):
296343 transData = local .buffer .transData
297344 SetToTimeData (transData , scanner .transNum )
@@ -417,6 +464,7 @@ def Telemetry(local, ton):
417464 data ["vprocess" ] = GetValidatorProcessInfo ()
418465 data ["dbStats" ] = local .try_function (get_db_stats )
419466 data ["nodeArgs" ] = local .try_function (get_node_args )
467+ data ["modes" ] = local .try_function (ton .get_modes )
420468 data ["cpuInfo" ] = {'cpuName' : local .try_function (get_cpu_name ), 'virtual' : local .try_function (is_host_virtual )}
421469 data ["validatorDiskName" ] = local .try_function (get_validator_disk_name )
422470 data ["pings" ] = local .try_function (get_pings_values )
@@ -550,6 +598,46 @@ def ScanLiteServers(local, ton):
550598# end define
551599
552600
601+ def check_initial_sync (local , ton ):
602+ if not ton .in_initial_sync ():
603+ return
604+ validator_status = ton .GetValidatorStatus ()
605+ if validator_status .initial_sync :
606+ return
607+ if validator_status .out_of_sync < 20 :
608+ ton .set_initial_sync_off ()
609+ return
610+
611+
612+ def gc_import (local , ton ):
613+ if not ton .local .db .get ('importGc' , False ):
614+ return
615+ local .add_log ("GC import is running" , "debug" )
616+ import_path = '/var/ton-work/db/import'
617+ files = os .listdir (import_path )
618+ if not files :
619+ local .add_log ("No files left to import" , "debug" )
620+ ton .local .db ['importGc' ] = False
621+ return
622+ try :
623+ status = ton .GetValidatorStatus ()
624+ node_seqno = int (status .shardclientmasterchainseqno )
625+ except Exception as e :
626+ local .add_log (f"Failed to get shardclientmasterchainseqno: { e } " , "warning" )
627+ return
628+ removed = 0
629+ for file in files :
630+ file_seqno = int (file .split ('.' )[1 ])
631+ if node_seqno > file_seqno + 101 :
632+ try :
633+ os .remove (os .path .join (import_path , file ))
634+ removed += 1
635+ except PermissionError :
636+ local .add_log (f"Failed to remove file { file } : Permission denied" , "error" )
637+ continue
638+ local .add_log (f"Removed { removed } import files up to { node_seqno } seqno" , "debug" )
639+
640+
553641def General (local ):
554642 local .add_log ("start General function" , "debug" )
555643 ton = MyTonCore (local )
@@ -576,6 +664,8 @@ def General(local):
576664
577665 local .start_cycle (ScanLiteServers , sec = 60 , args = (local , ton ,))
578666
667+ local .start_cycle (save_node_statistics , sec = 60 , args = (local , ton , ))
668+
579669 from modules .custom_overlays import CustomOverlayModule
580670 local .start_cycle (CustomOverlayModule (ton , local ).custom_overlays , sec = 60 , args = ())
581671
@@ -588,6 +678,11 @@ def General(local):
588678 from modules .btc_teleport import BtcTeleportModule
589679 local .start_cycle (BtcTeleportModule (ton , local ).auto_vote_offers , sec = 600 , args = ())
590680
681+ if ton .in_initial_sync ():
682+ local .start_cycle (check_initial_sync , sec = 120 , args = (local , ton ))
683+
684+ if ton .local .db .get ('importGc' ):
685+ local .start_cycle (gc_import , sec = 300 , args = (local , ton ))
591686
592687 thr_sleep ()
593688# end define
0 commit comments