Skip to content

Commit a27fcec

Browse files
committed
add check_adnl_connection_failed
1 parent 09e1e81 commit a27fcec

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

modules/alert_bot.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ def check_slashed(self):
205205
if c is not None:
206206
self.send_alert("validator_slashed", amount=int(c['suggestedFine']))
207207

208+
def check_adnl_connection_failed(self):
209+
from modules.utilities import UtilitiesModule
210+
utils_module = UtilitiesModule(self.ton, self.local)
211+
ok, error = utils_module.check_adnl_connection()
212+
if not ok:
213+
self.send_alert("adnl_connection_failed")
214+
208215
def check_status(self):
209216
if not self.inited:
210217
self.init()
@@ -216,6 +223,7 @@ def check_status(self):
216223
self.local.try_function(self.check_zero_blocks_created)
217224
self.local.try_function(self.check_sync)
218225
self.local.try_function(self.check_slashed)
226+
self.local.try_function(self.check_adnl_connection_failed)
219227

220228
def add_console_commands(self, console):
221229
...

modules/utilities.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import base64
21
import json
3-
import os
2+
import random
43
import subprocess
54
import time
65

6+
import requests
7+
78
from mypylib.mypylib import color_print, print_table, color_text, timeago, bcolors
89
from modules.module import MtcModule
910

@@ -335,6 +336,35 @@ def print_validator_list(self, args):
335336
print_table(table)
336337
# end define
337338

339+
def check_adnl_connection(self):
340+
telemetry = self.ton.local.db.get("sendTelemetry", False)
341+
check_adnl = self.ton.local.db.get("checkAdnl", telemetry)
342+
if not check_adnl:
343+
return True, ''
344+
self.local.add_log('Checking ADNL connection to local node', 'info')
345+
hosts = ['45.129.96.53', '5.154.181.153', '2.56.126.137', '91.194.11.68', '45.12.134.214', '138.124.184.27',
346+
'103.106.3.171']
347+
hosts = random.sample(hosts, k=3)
348+
data = self.ton.get_local_adnl_data()
349+
error = ''
350+
ok = True
351+
for host in hosts:
352+
url = f'http://{host}/adnl_check'
353+
try:
354+
response = requests.post(url, json=data, timeout=5).json()
355+
except Exception as e:
356+
ok = False
357+
error = f'{{red}}Failed to check ADNL connection to local node: {type(e)}: {e}{{endc}}'
358+
continue
359+
result = response.get("ok")
360+
if result:
361+
ok = True
362+
break
363+
if not result:
364+
ok = False
365+
error = f'{{red}}Failed to check ADNL connection to local node: {response.get("message")}{{endc}}'
366+
return ok, error
367+
338368
def add_console_commands(self, console):
339369
console.AddItem("vas", self.view_account_status, self.local.translate("vas_cmd"))
340370
console.AddItem("vah", self.view_account_history, self.local.translate("vah_cmd"))

mytonctrl/mytonctrl.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -492,31 +492,9 @@ def check_slashed(local, ton):
492492
#end define
493493

494494
def check_adnl(local, ton):
495-
telemetry = ton.local.db.get("sendTelemetry", False)
496-
check_adnl = ton.local.db.get("checkAdnl", telemetry)
497-
local.add_log('Checking ADNL connection to local node', 'info')
498-
if not check_adnl:
499-
return
500-
hosts = ['45.129.96.53', '5.154.181.153', '2.56.126.137', '91.194.11.68', '45.12.134.214', '138.124.184.27', '103.106.3.171']
501-
hosts = random.sample(hosts, k=3)
502-
data = ton.get_local_adnl_data()
503-
error = ''
504-
ok = True
505-
for host in hosts:
506-
url = f'http://{host}/adnl_check'
507-
try:
508-
response = requests.post(url, json=data, timeout=5).json()
509-
except Exception as e:
510-
ok = False
511-
error = f'{{red}}Failed to check ADNL connection to local node: {type(e)}: {e}{{endc}}'
512-
continue
513-
result = response.get("ok")
514-
if result:
515-
ok = True
516-
break
517-
if not result:
518-
ok = False
519-
error = f'{{red}}Failed to check ADNL connection to local node: {response.get("message")}{{endc}}'
495+
from modules.utilities import UtilitiesModule
496+
utils_module = UtilitiesModule(ton, local)
497+
ok, error = utils_module.check_adnl_connection()
520498
if not ok:
521499
print_warning(local, error)
522500
#end define

0 commit comments

Comments
 (0)