Skip to content

Commit 6275ec4

Browse files
committed
add shard_collators_offline alert
1 parent d3d603a commit 6275ec4

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

modules/alert_bot.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from modules.module import MtcModule
66
from 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
88
from 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"))

modules/validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def delete_collator(self, args: list):
234234
self.set_collators_list(collators_list)
235235
color_print("delete_collator - {green}OK{endc}")
236236

237-
def _get_collators_stats(self):
237+
def get_collators_stats(self):
238238
output = self.ton.validatorConsole.Run('collation-manager-stats')
239239
if 'No stats' in output:
240240
return {}
@@ -257,7 +257,7 @@ def print_collators(self, args: list):
257257
if 'collators list is empty' in result:
258258
print("No collators found")
259259
return
260-
collators_stats = self._get_collators_stats()
260+
collators_stats = self.get_collators_stats()
261261
for adnl, alive in collators_stats.items():
262262
if adnl in result:
263263
status = '{green}online{endc}' if alive else '{red}offline{endc}'

0 commit comments

Comments
 (0)