44
55from modules .module import MtcModule
66from mypylib .mypylib import get_timestamp , print_table , color_print
7- from mytoncore import get_hostname
7+ from mytoncore import get_hostname , signed_int_to_hex64
88from mytonctrl .utils import timestamp2utcdatetime
99
1010
@@ -121,7 +121,13 @@ def init_alerts():
121121 "Initial sync has been completed (info alert with no sound)" ,
122122 "Node initial sync has been completed" ,
123123 0
124- )
124+ ),
125+ "shard_collators_offline" : Alert (
126+ "high" ,
127+ "All collators for specific shards are offline" ,
128+ "All collators for shards <code>{shards}</code> are offline." ,
129+ 3600
130+ ),
125131 }
126132
127133
@@ -452,6 +458,27 @@ def check_initial_sync(self):
452458 self .initial_sync = False
453459 self .send_alert ("initial_sync_completed" )
454460
461+ def check_online_collators (self ):
462+ if not self .ton .using_validator ():
463+ return
464+ collators_list = self .validator_module .get_collators_list ()
465+ if not collators_list or not collators_list ['shards' ]:
466+ return
467+ collators_stats = self .validator_module .get_collators_stats ()
468+ offline_shards = []
469+
470+ for shard in collators_list ['shards' ]:
471+ if not shard ['collators' ]:
472+ continue
473+ collators_alive = []
474+ for c in shard ['collators' ]:
475+ collators_alive .append (collators_stats .get (c ['adnl_id' ]))
476+ if not any (collators_alive ):
477+ offline_shards .append (f"{ shard ['shard_id' ]['workchain' ]} :{ signed_int_to_hex64 (int (shard ['shard_id' ]['shard' ]))} " )
478+
479+ if offline_shards :
480+ self .send_alert ("shard_collators_offline" , shards = ' ' .join (offline_shards ))
481+
455482 def check_status (self ):
456483 if not self .ton .using_alert_bot ():
457484 return
@@ -471,6 +498,7 @@ def check_status(self):
471498 self .local .try_function (self .check_stake_returned )
472499 self .local .try_function (self .check_voting )
473500 self .local .try_function (self .check_initial_sync )
501+ self .local .try_function (self .check_online_collators )
474502
475503 def add_console_commands (self , console ):
476504 console .AddItem ("enable_alert" , self .enable_alert , self .local .translate ("enable_alert_cmd" ))
0 commit comments