Skip to content

Commit d57e793

Browse files
authored
Merge pull request #349 from yungwine/efficiency
do not print efficiency for non masterchain validators
2 parents 3cd99d0 + 1f25c32 commit d57e793

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

modules/validator.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
from mypylib.mypylib import color_print, get_timestamp
24
from modules.module import MtcModule
35
from mytonctrl.utils import timestamp2utcdatetime, GetColorInt
@@ -48,37 +50,40 @@ def check_efficiency(self, args):
4850
config32 = self.ton.GetConfig32()
4951
config34 = self.ton.GetConfig34()
5052
color_print("{cyan}===[ Validator efficiency ]==={endc}")
53+
start_time = timestamp2utcdatetime(config32.startWorkTime)
54+
end_time = timestamp2utcdatetime(config32.endWorkTime)
55+
color_print(f"Previous round time: {{yellow}}from {start_time} to {end_time}{{endc}}")
5156
if validator:
52-
if validator.get('efficiency') is None:
53-
print('Failed to get efficiency for the past round')
57+
if validator.is_masterchain == False:
58+
print("Validator index is greater than 100 in the previous round - no efficiency data.")
59+
elif validator.get('efficiency') is None:
60+
print('Failed to get efficiency for the previous round')
5461
else:
5562
efficiency = 100 if validator.efficiency > 100 else validator.efficiency
5663
color_efficiency = GetColorInt(efficiency, 90, logic="more", ending="%")
5764
created = validator.blocks_created
5865
expected = validator.blocks_expected
59-
start_time = timestamp2utcdatetime(config32.startWorkTime)
60-
end_time = timestamp2utcdatetime(config32.endWorkTime)
61-
color_print(f"Previous round efficiency: {color_efficiency} {{yellow}}({created} blocks created / {expected} blocks expected){{endc}}")
62-
color_print(f"Previous round time: {{yellow}}from {start_time} to {end_time}{{endc}}")
66+
color_print(f"Previous round efficiency: {color_efficiency} {{yellow}}({created} blocks created / {round(expected, 1)} blocks expected){{endc}}")
6367
else:
64-
print("Couldn't find this validator in the past round")
68+
print("Couldn't find this validator in the previous round")
6569
validator = self.find_myself(validators)
70+
start_time = timestamp2utcdatetime(config34.startWorkTime)
71+
end_time = timestamp2utcdatetime(int(get_timestamp()))
72+
color_print(f"Current round time: {{green}}from {start_time} to {end_time}{{endc}}")
6673
if validator:
67-
if validator.get('efficiency') is None:
74+
if validator.is_masterchain == False:
75+
print("Validator index is greater than 100 in the current round - no efficiency data.")
76+
elif (time.time() - config34.startWorkTime) / (config34.endWorkTime - config34.startWorkTime) < 0.8:
77+
print("The validation round has started recently, there is not enough data yet. "
78+
"The efficiency evaluation will become more accurate towards the end of the round.")
79+
elif validator.get('efficiency') is None:
6880
print('Failed to get efficiency for the current round')
6981
else:
7082
efficiency = 100 if validator.efficiency > 100 else validator.efficiency
7183
color_efficiency = GetColorInt(efficiency, 90, logic="more", ending="%")
7284
created = validator.blocks_created
7385
expected = validator.blocks_expected
74-
start_time = timestamp2utcdatetime(config34.startWorkTime)
75-
end_time = timestamp2utcdatetime(int(get_timestamp()))
76-
if not validator.is_masterchain and efficiency < 90:
77-
print("Your validator index is greater than 100.")
78-
print("Efficiency while the validation round is active may be inaccurate and not displayed.")
79-
else:
80-
color_print(f"Current round efficiency: {color_efficiency} {{yellow}}({created} blocks created / {expected} blocks expected){{endc}}")
81-
color_print(f"Current round time: {{green}}from {start_time} to {end_time}{{endc}}")
86+
color_print(f"Current round efficiency: {color_efficiency} {{yellow}}({created} blocks created / {round(expected, 1)} blocks expected){{endc}}")
8287
else:
8388
print("Couldn't find this validator in the current round")
8489
# end define

0 commit comments

Comments
 (0)