Skip to content

Commit 0a0acb1

Browse files
authored
Merge pull request #380 from yungwine/bot
alerting updates
2 parents a4c9fb8 + 79bf05b commit 0a0acb1

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

modules/alert_bot.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, ton, local, *args, **kwargs):
8585
self.hostname = None
8686
self.token = self.ton.local.db.get("BotToken")
8787
self.chat_id = self.ton.local.db.get("ChatId")
88+
self.last_db_check = None
8889

8990
def send_message(self, text: str):
9091
if self.token is None:
@@ -189,6 +190,9 @@ def test_alert(self, args):
189190
self.send_message('Test alert')
190191

191192
def check_db_usage(self):
193+
if time.time() - self.last_db_check < 600:
194+
return
195+
self.last_db_check = time.time()
192196
usage = self.ton.GetDbUsage()
193197
if usage > 95:
194198
self.send_alert("db_usage_95")
@@ -206,12 +210,15 @@ def check_validator_wallet_balance(self):
206210
def check_efficiency(self):
207211
if not self.ton.using_validator():
208212
return
209-
validator = self.validator_module.find_myself(self.ton.GetValidatorsList(fast=True))
210-
if validator is None or validator.is_masterchain is False or validator.efficiency is None:
213+
validator = self.validator_module.find_myself(self.ton.GetValidatorsList())
214+
if validator is None or validator.efficiency is None:
211215
return
212216
config34 = self.ton.GetConfig34()
213217
if (time.time() - config34.startWorkTime) / (config34.endWorkTime - config34.startWorkTime) < 0.8:
214218
return # less than 80% of round passed
219+
if validator.is_masterchain is False:
220+
if validator.efficiency != 0:
221+
return
215222
if validator.efficiency < 90:
216223
self.send_alert("low_efficiency", efficiency=validator.efficiency)
217224

@@ -255,6 +262,8 @@ def check_adnl_connection_failed(self):
255262
self.send_alert("adnl_connection_failed")
256263

257264
def check_status(self):
265+
if not self.ton.using_alert_bot():
266+
return
258267
if not self.inited:
259268
self.init()
260269

modules/validator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def check_efficiency(self, args):
5454
end_time = timestamp2utcdatetime(config32.endWorkTime)
5555
color_print(f"Previous round time: {{yellow}}from {start_time} to {end_time}{{endc}}")
5656
if validator:
57-
if validator.is_masterchain == False:
58-
print(f"Validator index is greater than {config32['mainValidators']} in the previous round - no efficiency data.")
59-
elif validator.get('efficiency') is None:
57+
if validator.get('efficiency') is None:
6058
print('Failed to get efficiency for the previous round')
59+
elif validator.is_masterchain is False and validator.get('efficiency') != 0:
60+
print(f"Validator index is greater than {config32['mainValidators']} in the previous round - no efficiency data.")
6161
else:
6262
efficiency = 100 if validator.efficiency > 100 else validator.efficiency
6363
color_efficiency = GetColorInt(efficiency, 90, logic="more", ending="%")
@@ -74,7 +74,7 @@ def check_efficiency(self, args):
7474
end_time = timestamp2utcdatetime(int(get_timestamp()))
7575
color_print(f"Current round time: {{green}}from {start_time} to {end_time}{{endc}}")
7676
if validator:
77-
if validator.is_masterchain == False:
77+
if validator.is_masterchain is False and validator.efficiency != 0:
7878
print(f"Validator index is greater than {config34['mainValidators']} in the current round - no efficiency data.")
7979
elif (time.time() - config34.startWorkTime) / (config34.endWorkTime - config34.startWorkTime) < 0.8:
8080
print("The validation round has started recently, there is not enough data yet. "

mytoncore/functions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,8 @@ def General(local):
569569
from modules.custom_overlays import CustomOverlayModule
570570
local.start_cycle(CustomOverlayModule(ton, local).custom_overlays, sec=60, args=())
571571

572-
if ton.get_mode_value('alert-bot'):
573-
from modules.alert_bot import AlertBotModule
574-
local.start_cycle(AlertBotModule(ton, local).check_status, sec=1000, args=())
572+
from modules.alert_bot import AlertBotModule
573+
local.start_cycle(AlertBotModule(ton, local).check_status, sec=60, args=())
575574

576575
thr_sleep()
577576
# end define

mytonctrl/resources/translate.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@
445445
"zh_TW": "{red}錯誤 - 驗證器的 UDP 端口無法從外部訪問.{endc}"
446446
},
447447
"slashed_warning": {
448-
"en": "{red}You were fined by {0} TON for low efficiency in the previous round.{endc}",
449-
"ru": "{red}Вы были оштрафованы на {0} TON за низкую эффективность в предыдущем раунде.{endc}",
450-
"zh_TW": "{red}您因上一輪效率低而被罰款 {0} TON。{endc}"
448+
"en": "{{red}}You were fined by {0} TON for low efficiency in the previous round.{{endc}}",
449+
"ru": "{{red}}Вы были оштрафованы на {0} TON за низкую эффективность в предыдущем раунде.{{endc}}",
450+
"zh_TW": "{{red}}您因上一輪效率低而被罰款 {0} TON。{{endc}}"
451451
},
452452
"add_custom_overlay_cmd": {
453453
"en": "Add custom overlay",

0 commit comments

Comments
 (0)