Skip to content

Commit af9cf22

Browse files
committed
add collated and validated blocks stats
1 parent 638cf6c commit af9cf22

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

mytoncore/functions.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,56 @@ def CalculateNetworkStatistics(zerodata, data):
286286
# end define
287287

288288

289+
def save_node_statistics(local, ton):
290+
status = ton.GetValidatorStatus()
291+
if status.unixtime is None:
292+
return
293+
data = {'timestamp': status.unixtime}
294+
295+
def get_ok_error(value: str):
296+
ok, error = value.split()
297+
return int(ok.split(':')[1]), int(error.split(':')[1])
298+
299+
if 'total.collated_blocks.master' in status:
300+
master_ok, master_error = get_ok_error(status['total.collated_blocks.master'])
301+
shard_ok, shard_error = get_ok_error(status['total.collated_blocks.shard'])
302+
data['collated_blocks'] = {
303+
'master': {'ok': master_ok, 'error': master_error},
304+
'shard': {'ok': shard_ok, 'error': shard_error},
305+
}
306+
if 'total.validated_blocks.master' in status:
307+
master_ok, master_error = get_ok_error(status['total.validated_blocks.master'])
308+
shard_ok, shard_error = get_ok_error(status['total.validated_blocks.shard'])
309+
data['validated_blocks'] = {
310+
'master': {'ok': master_ok, 'error': master_error},
311+
'shard': {'ok': shard_ok, 'error': shard_error},
312+
}
313+
if 'total.ext_msg_check' in status:
314+
ok, error = get_ok_error(status['total.ext_msg_check'])
315+
data['ext_msg_check'] = {'ok': ok, 'error': error}
316+
if 'total.ls_queries_ok' in status and 'total.ls_queries_error' in status:
317+
data['ls_queries'] = {}
318+
for k in status['total.ls_queries_ok']:
319+
if k.startswith('TOTAL'):
320+
data['ls_queries']['ok'] = k.split(':')[1]
321+
for k in status['total.ls_queries_error']:
322+
if k.startswith('TOTAL'):
323+
data['ls_queries']['error'] = k.split(':')[1]
324+
statistics = local.db.get("statistics", dict())
325+
326+
# statistics['node'] = [stats_from_election_id, stats_from_prev_min, stats_now]
327+
328+
election_id = ton.GetConfig32()['startWorkTime']
329+
if 'node' not in statistics or len(statistics['node']) < 1:
330+
statistics['node'] = [data]
331+
elif statistics['node'][0]['timestamp'] < election_id:
332+
statistics['node'] = [data, data]
333+
else:
334+
statistics['node'] = statistics.get('node', []) + [data]
335+
statistics['node'].pop(1)
336+
local.db["statistics"] = statistics
337+
338+
289339
def ReadTransData(local, scanner):
290340
transData = local.buffer.transData
291341
SetToTimeData(transData, scanner.transNum)
@@ -581,6 +631,8 @@ def General(local):
581631

582632
local.start_cycle(ScanLiteServers, sec=60, args=(local, ton,))
583633

634+
local.start_cycle(save_node_statistics, sec=60, args=(local, ton, ))
635+
584636
from modules.custom_overlays import CustomOverlayModule
585637
local.start_cycle(CustomOverlayModule(ton, local).custom_overlays, sec=60, args=())
586638

mytonctrl/mytonctrl.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,23 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
751751
if validator_status.stateserializerenabled:
752752
validator_out_of_ser_text = local.translate("local_status_validator_out_of_ser").format(f'{validator_status.out_of_ser} blocks ago')
753753

754+
collated, validated = None, None
755+
if ton.using_validator() and validatorIndex != -1:
756+
stats = ton.local.db.get('statistics', {}).get('node')
757+
if stats is not None and len(stats) == 3:
758+
collated_ok = 0
759+
collated_error = 0
760+
validated_ok = 0
761+
validated_error = 0
762+
for k in ['master', 'shard']:
763+
collated_ok += stats[2]['collated_blocks'][k]['ok'] - stats[0]['collated_blocks'][k]['ok']
764+
collated_error += stats[2]['collated_blocks'][k]['error'] - stats[0]['collated_blocks'][k]['error']
765+
validated_ok += stats[2]['validated_blocks'][k]['ok'] - stats[0]['validated_blocks'][k]['ok']
766+
validated_error += stats[2]['validated_blocks'][k]['error'] - stats[0]['validated_blocks'][k]['error']
767+
collated = local.translate['collated_blocks'].format(collated_ok, collated_error)
768+
validated = local.translate['validated_blocks'].format(validated_ok, validated_error)
769+
770+
754771
dbSize_text = GetColorInt(dbSize, 1000, logic="less", ending=" Gb")
755772
dbUsage_text = GetColorInt(dbUsage, 80, logic="less", ending="%")
756773
dbStatus_text = local.translate("local_status_db").format(dbSize_text, dbUsage_text)
@@ -800,6 +817,9 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
800817
print(validator_out_of_sync_text)
801818
print(master_out_of_sync_text)
802819
print(shard_out_of_sync_text)
820+
if collated and validated:
821+
print(collated)
822+
print(validated)
803823
if validator_out_of_ser_text:
804824
print(validator_out_of_ser_text)
805825
print(dbStatus_text)

mytonctrl/resources/translate.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,16 @@
344344
"ru": "Серализация стейта локального валидатора была: {0}",
345345
"zh_TW": "本地驗證者最後一次狀態序列化: {0}"
346346
},
347+
"collated_blocks": {
348+
"en": "Collated blocks since validation round started (success/error): {0}",
349+
"ru": "Собранные блоки с начала раунда валидации (успех/ошибка): {0}",
350+
"zh_TW": "自驗證週期開始以來的彙編區塊 (成功/錯誤): {0}"
351+
},
352+
"validated_blocks": {
353+
"en": "Validated blocks since validation round started (success/error): {0}",
354+
"ru": "Проверенные блоки с начала раунда валидации (успех/ошибка): {0}",
355+
"zh_TW": "自驗證週期開始以來的驗證區塊 (成功/錯誤): {0}"
356+
},
347357
"local_status_db": {
348358
"en": "Local validator database size: {0}, {1}",
349359
"ru": "Размер БД локального валидатора: {0}, {1}",

0 commit comments

Comments
 (0)