Skip to content

Commit 900cf1a

Browse files
authored
Merge pull request #470 from yungwine/validator-stats
fix validator stats
2 parents a9f424b + 0cafaf8 commit 900cf1a

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

mytoncore/functions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def get_ok_error(value: str):
317317

318318
# statistics['node'] = [stats_from_election_id, stats_from_prev_min, stats_now]
319319

320-
election_id = ton.GetConfig34()['startWorkTime']
320+
election_id = ton.GetConfig34(no_cache=True)['startWorkTime']
321321
if 'node' not in statistics or len(statistics['node']) == 0:
322322
statistics['node'] = [None, data]
323323
elif len(statistics['node']) < 3:
@@ -328,9 +328,11 @@ def get_ok_error(value: str):
328328
statistics['node'][0] = data
329329
elif statistics['node'][0]['timestamp'] < election_id:
330330
statistics['node'][0] = data
331-
statistics['node'] = statistics.get('node', []) + [data]
332-
statistics['node'].pop(1)
331+
temp = statistics.get('node', []) + [data]
332+
temp.pop(1)
333+
statistics['node'] = temp
333334
local.db["statistics"] = statistics
335+
local.save()
334336

335337

336338
def ReadTransData(local, scanner):

mytoncore/mytoncore.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -930,11 +930,11 @@ def GetConfig32(self):
930930
return config32
931931
#end define
932932

933-
def GetConfig34(self):
933+
def GetConfig34(self, no_cache: bool = False):
934934
# Get buffer
935935
bname = "config34"
936-
buff = self.GetFunctionBuffer(bname, timeout=60)
937-
if buff:
936+
buff = self.GetFunctionBuffer(bname, timeout=10)
937+
if buff and not no_cache:
938938
return buff
939939
#end if
940940

@@ -3061,17 +3061,17 @@ def get_node_statistics(self):
30613061
stats = self.local.db.get('statistics', {}).get('node')
30623062
result = {}
30633063
if stats is not None and len(stats) == 3 and stats[0] is not None:
3064-
for k in ['master', 'shard']:
3065-
result = {
3066-
'collated': {
3067-
'ok': 0,
3068-
'error': 0,
3069-
},
3070-
'validated': {
3071-
'ok': 0,
3072-
'error': 0,
3073-
}
3064+
result = {
3065+
'collated': {
3066+
'ok': 0,
3067+
'error': 0,
3068+
},
3069+
'validated': {
3070+
'ok': 0,
3071+
'error': 0,
30743072
}
3073+
}
3074+
for k in ['master', 'shard']:
30753075
collated_ok = stats[2]['collated_blocks'][k]['ok'] - stats[0]['collated_blocks'][k]['ok']
30763076
collated_error = stats[2]['collated_blocks'][k]['error'] - stats[0]['collated_blocks'][k]['error']
30773077
validated_ok = stats[2]['validated_blocks'][k]['ok'] - stats[0]['validated_blocks'][k]['ok']
@@ -3088,7 +3088,7 @@ def get_node_statistics(self):
30883088
result['collated']['error'] += collated_error
30893089
result['validated']['ok'] += validated_ok
30903090
result['validated']['error'] += validated_error
3091-
if stats is not None and len(stats) >= 2 and stats[0] is not None:
3091+
if stats is not None and len(stats) >= 2 and stats[-2] is not None and stats[-1] is not None:
30923092
result['ls_queries'] = {
30933093
'ok': stats[-1]['ls_queries']['ok'] - stats[-2]['ls_queries']['ok'],
30943094
'error': stats[-1]['ls_queries']['error'] - stats[-2]['ls_queries']['error'],

mytonctrl/mytonctrl.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -774,23 +774,25 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
774774

775775
active_validator_groups = None
776776

777-
if ton.using_validator() and validator_status.validator_groups_master and validator_status.validator_groups_shard:
777+
if ton.using_validator() and validator_status.validator_groups_master is not None and validator_status.validator_groups_shard is not None:
778778
active_validator_groups = local.translate("active_validator_groups").format(validator_status.validator_groups_master, validator_status.validator_groups_shard)
779779

780780
collated, validated = None, None
781781
ls_queries = None
782-
if ton.using_validator():
783-
node_stats = ton.get_node_statistics()
784-
if node_stats and 'collated' in node_stats and 'validated' in node_stats:
785-
collated = local.translate('collated_blocks').format(node_stats['collated']['ok'], node_stats['collated']['error'])
786-
validated = local.translate('validated_blocks').format(node_stats['validated']['ok'], node_stats['validated']['error'])
787-
else:
788-
collated = local.translate('collated_blocks').format('collecting data...', 'wait for the next validation round')
789-
validated = local.translate('validated_blocks').format('collecting data...', 'wait for the next validation round')
790-
if ton.using_liteserver():
791-
node_stats = ton.get_node_statistics()
792-
if node_stats and 'ls_queries' in node_stats:
793-
ls_queries = local.translate('ls_queries').format(node_stats['ls_queries']['time'], node_stats['ls_queries']['ok'], node_stats['ls_queries']['error'])
782+
node_stats = local.try_function(ton.get_node_statistics)
783+
if node_stats is not None:
784+
if ton.using_validator():
785+
if 'collated' in node_stats and 'validated' in node_stats:
786+
collated = local.translate('collated_blocks').format(node_stats['collated']['ok'], node_stats['collated']['error'])
787+
validated = local.translate('validated_blocks').format(node_stats['validated']['ok'], node_stats['validated']['error'])
788+
else:
789+
collated = local.translate('collated_blocks').format('collecting data...', 'wait for the next validation round')
790+
validated = local.translate('validated_blocks').format('collecting data...', 'wait for the next validation round')
791+
if ton.using_liteserver():
792+
if 'ls_queries' in node_stats:
793+
ls_queries = local.translate('ls_queries').format(node_stats['ls_queries']['time'], node_stats['ls_queries']['ok'], node_stats['ls_queries']['error'])
794+
else:
795+
local.add_log("Failed to get node statistics", "warning")
794796

795797
dbSize_text = GetColorInt(dbSize, 1000, logic="less", ending=" Gb")
796798
dbUsage_text = GetColorInt(dbUsage, 80, logic="less", ending="%")

0 commit comments

Comments
 (0)