Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions modules/alert_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(self, ton, local, *args, **kwargs):
self.hostname = None
self.token = self.ton.local.db.get("BotToken")
self.chat_id = self.ton.local.db.get("ChatId")
self.last_db_check = None

def send_message(self, text: str):
if self.token is None:
Expand Down Expand Up @@ -189,6 +190,9 @@ def test_alert(self, args):
self.send_message('Test alert')

def check_db_usage(self):
if time.time() - self.last_db_check < 600:
return
self.last_db_check = time.time()
usage = self.ton.GetDbUsage()
if usage > 95:
self.send_alert("db_usage_95")
Expand All @@ -206,12 +210,15 @@ def check_validator_wallet_balance(self):
def check_efficiency(self):
if not self.ton.using_validator():
return
validator = self.validator_module.find_myself(self.ton.GetValidatorsList(fast=True))
if validator is None or validator.is_masterchain is False or validator.efficiency is None:
validator = self.validator_module.find_myself(self.ton.GetValidatorsList())
if validator is None or validator.efficiency is None:
return
config34 = self.ton.GetConfig34()
if (time.time() - config34.startWorkTime) / (config34.endWorkTime - config34.startWorkTime) < 0.8:
return # less than 80% of round passed
if validator.is_masterchain is False:
if validator.efficiency != 0:
return
if validator.efficiency < 90:
self.send_alert("low_efficiency", efficiency=validator.efficiency)

Expand Down Expand Up @@ -255,6 +262,8 @@ def check_adnl_connection_failed(self):
self.send_alert("adnl_connection_failed")

def check_status(self):
if not self.ton.using_alert_bot():
return
if not self.inited:
self.init()

Expand Down
8 changes: 4 additions & 4 deletions modules/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def check_efficiency(self, args):
end_time = timestamp2utcdatetime(config32.endWorkTime)
color_print(f"Previous round time: {{yellow}}from {start_time} to {end_time}{{endc}}")
if validator:
if validator.is_masterchain == False:
print(f"Validator index is greater than {config32['mainValidators']} in the previous round - no efficiency data.")
elif validator.get('efficiency') is None:
if validator.get('efficiency') is None:
print('Failed to get efficiency for the previous round')
elif validator.is_masterchain is False and validator.get('efficiency') != 0:
print(f"Validator index is greater than {config32['mainValidators']} in the previous round - no efficiency data.")
else:
efficiency = 100 if validator.efficiency > 100 else validator.efficiency
color_efficiency = GetColorInt(efficiency, 90, logic="more", ending="%")
Expand All @@ -74,7 +74,7 @@ def check_efficiency(self, args):
end_time = timestamp2utcdatetime(int(get_timestamp()))
color_print(f"Current round time: {{green}}from {start_time} to {end_time}{{endc}}")
if validator:
if validator.is_masterchain == False:
if validator.is_masterchain is False and validator.efficiency != 0:
print(f"Validator index is greater than {config34['mainValidators']} in the current round - no efficiency data.")
elif (time.time() - config34.startWorkTime) / (config34.endWorkTime - config34.startWorkTime) < 0.8:
print("The validation round has started recently, there is not enough data yet. "
Expand Down
5 changes: 2 additions & 3 deletions mytoncore/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,8 @@ def General(local):
from modules.custom_overlays import CustomOverlayModule
local.start_cycle(CustomOverlayModule(ton, local).custom_overlays, sec=60, args=())

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

thr_sleep()
# end define
Expand Down
6 changes: 3 additions & 3 deletions mytonctrl/resources/translate.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@
"zh_TW": "{red}錯誤 - 驗證器的 UDP 端口無法從外部訪問.{endc}"
},
"slashed_warning": {
"en": "{red}You were fined by {0} TON for low efficiency in the previous round.{endc}",
"ru": "{red}Вы были оштрафованы на {0} TON за низкую эффективность в предыдущем раунде.{endc}",
"zh_TW": "{red}您因上一輪效率低而被罰款 {0} TON。{endc}"
"en": "{{red}}You were fined by {0} TON for low efficiency in the previous round.{{endc}}",
"ru": "{{red}}Вы были оштрафованы на {0} TON за низкую эффективность в предыдущем раунде.{{endc}}",
"zh_TW": "{{red}}您因上一輪效率低而被罰款 {0} TON。{{endc}}"
},
"add_custom_overlay_cmd": {
"en": "Add custom overlay",
Expand Down