From 1afac1003dea4d638dcd14d77d09bec654e954ae Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 18:08:08 +0900 Subject: [PATCH 1/9] fix calculating efficiency for non-masterchain validators --- mytoncore/mytoncore.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index ed643083..393dcad9 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2503,7 +2503,7 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict: if buff: return buff #end if - + config34 = self.GetConfig34() text = "start GetValidatorsLoad function ({}, {})".format(start, end) self.local.add_log(text, "debug") if saveCompFiles is True: @@ -2544,6 +2544,8 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict: else: wr = workBlocksCreated / workBlocksExpected r = (mr + wr) / 2 + if vid >= config34["main"]: + r = wr efficiency = round(r * 100, 2) if efficiency > 10: online = True @@ -2589,8 +2591,9 @@ def GetValidatorsList(self, past=False): timestamp = get_timestamp() end = timestamp - 60 - start = end - 2000 + # start = end - 2000 config = self.GetConfig34() + start = config.get("startWorkTime") if past: config = self.GetConfig32() start = config.get("startWorkTime") @@ -2608,6 +2611,8 @@ def GetValidatorsList(self, past=False): validator["wr"] = validatorsLoad[vid]["wr"] validator["efficiency"] = validatorsLoad[vid]["efficiency"] validator["online"] = validatorsLoad[vid]["online"] + validator["blocks_created"] = validatorsLoad[vid]["masterBlocksCreated"] + validatorsLoad[vid]["workBlocksCreated"] + validator["blocks_expected"] = validatorsLoad[vid]["masterBlocksExpected"] + validatorsLoad[vid]["workBlocksExpected"] if saveElectionEntries and adnlAddr in saveElectionEntries: validator["walletAddr"] = saveElectionEntries[adnlAddr]["walletAddr"] #end for From f106beecc4e97563fd60481fbe3b8b7d49a2bceb Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 18:19:45 +0900 Subject: [PATCH 2/9] add vl fast --- mytoncore/mytoncore.py | 10 ++++++---- mytonctrl/mytonctrl.py | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 393dcad9..a2cf151d 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2581,7 +2581,7 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict: return data #end define - def GetValidatorsList(self, past=False): + def GetValidatorsList(self, past=False, fast=False): # Get buffer bname = "validatorsList" + str(past) buff = self.GetFunctionBuffer(bname, timeout=60) @@ -2591,9 +2591,11 @@ def GetValidatorsList(self, past=False): timestamp = get_timestamp() end = timestamp - 60 - # start = end - 2000 config = self.GetConfig34() - start = config.get("startWorkTime") + if fast: + start = end - 1000 + else: + start = config.get("startWorkTime") if past: config = self.GetConfig32() start = config.get("startWorkTime") @@ -3468,7 +3470,7 @@ def ImportCertificate(self, pubkey, fileName): def GetValidatorsWalletsList(self): result = list() - vl = self.GetValidatorsList() + vl = self.GetValidatorsList(fast=True) for item in vl: walletAddr = item["walletAddr"] result.append(walletAddr) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 33224717..b8ed8dda 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -1344,7 +1344,8 @@ def PrintElectionEntriesList(ton, args): def PrintValidatorList(ton, args): past = "past" in args - data = ton.GetValidatorsList(past=past) + fast = "fast" in args + data = ton.GetValidatorsList(past=past, fast=fast) if (data is None or len(data) == 0): print("No data") return @@ -1353,8 +1354,8 @@ def PrintValidatorList(ton, args): print(text) else: table = list() - table += [["ADNL", "Pubkey", "Wallet", "Efficiency", "Online"]] - for item in data: + table += [["id", "ADNL", "Pubkey", "Wallet", "Efficiency", "Online"]] + for i, item in enumerate(data): adnl = item.get("adnlAddr") pubkey = item.get("pubkey") walletAddr = item.get("walletAddr") @@ -1372,7 +1373,7 @@ def PrintValidatorList(ton, args): online = bcolors.green_text("true") if online == False: online = bcolors.red_text("false") - table += [[adnl, pubkey, walletAddr, efficiency, online]] + table += [[str(i), adnl, pubkey, walletAddr, efficiency, online]] print_table(table) #end define From 312b1f6d8caabf86648b4e55e6d18b26d7625afa Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 23:07:15 +0900 Subject: [PATCH 3/9] add check_ef command --- mytoncore/functions.py | 1 + mytoncore/mytoncore.py | 23 ++++++++++++++++++++++- mytonctrl/mytonctrl.py | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/mytoncore/functions.py b/mytoncore/functions.py index 0cca873a..5ae4602a 100755 --- a/mytoncore/functions.py +++ b/mytoncore/functions.py @@ -521,6 +521,7 @@ def Slashing(local, ton): def save_past_events(local, ton): local.try_function(ton.GetElectionEntries) local.try_function(ton.GetComplaints) + local.try_function(ton.GetValidatorsList, args=[True]) # cache past vl def ScanLiteServers(local, ton): diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index a2cf151d..71906598 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -916,6 +916,7 @@ def GetConfig32(self): config32 = dict() result = self.liteClient.Run("getconfig 32") config32["totalValidators"] = int(parse(result, "total:", ' ')) + config32["mainValidators"] = int(parse(result, "main:", ' ')) config32["startWorkTime"] = int(parse(result, "utime_since:", ' ')) config32["endWorkTime"] = int(parse(result, "utime_until:", ' ')) lines = result.split('\n') @@ -2320,6 +2321,19 @@ def GetSaveComplaints(self): return saveComplaints #end define + def GetSaveVl(self): + timestamp = get_timestamp() + save_vl = self.local.db.get("saveValidatorsLoad") + if save_vl is None: + save_vl = dict() + self.local.db["saveValidatorsLoad"] = save_vl + for key, item in list(save_vl.items()): + diff_time = timestamp - int(key) + if diff_time > 172800: # 48 hours + save_vl.pop(key) + return save_vl + #end define + def GetAdnlFromPubkey(self, inputPubkey): config32 = self.GetConfig32() validators = config32["validators"] @@ -2544,7 +2558,7 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict: else: wr = workBlocksCreated / workBlocksExpected r = (mr + wr) / 2 - if vid >= config34["main"]: + if vid >= config34["mainValidators"]: r = wr efficiency = round(r * 100, 2) if efficiency > 10: @@ -2600,7 +2614,11 @@ def GetValidatorsList(self, past=False, fast=False): config = self.GetConfig32() start = config.get("startWorkTime") end = config.get("endWorkTime") - 60 + save_vl = self.GetSaveVl() + if start in save_vl: + return save_vl[start] #end if + validatorsLoad = self.GetValidatorsLoad(start, end) validators = config["validators"] electionId = config.get("startWorkTime") @@ -2621,6 +2639,9 @@ def GetValidatorsList(self, past=False, fast=False): # Set buffer self.SetFunctionBuffer(bname, validators) + if past: + save_vl = self.GetSaveVl() + save_vl[start] = validators return validators #end define diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index b8ed8dda..06246622 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -80,6 +80,8 @@ def inject_globals(func): console.AddItem("set", inject_globals(SetSettings), local.translate("set_cmd")) console.AddItem("rollback", inject_globals(rollback_to_mtc1), local.translate("rollback_cmd")) + console.AddItem("check_ef", inject_globals(check_efficiency), local.translate("check_ef_cmd")) + console.AddItem("seqno", inject_globals(Seqno), local.translate("seqno_cmd")) console.AddItem("getconfig", inject_globals(GetConfig), local.translate("getconfig_cmd")) console.AddItem("get_pool_data", inject_globals(GetPoolData), local.translate("get_pool_data_cmd")) @@ -761,7 +763,7 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid color_print(local.translate("local_status_head")) print(validatorIndex_text) - print(validatorEfficiency_text) + # print(validatorEfficiency_text) print(adnlAddr_text) print(fullnode_adnl_text) print(walletAddr_text) @@ -873,6 +875,43 @@ def PrintTimes(local, rootWorkchainEnabledTime_int, startWorkTime, oldStartWorkT print(startNextElectionTime_text) #end define + +def find_myself(ton, validators: list) -> dict: + adnl_addr = ton.GetAdnlAddr() + for validator in validators: + if validator.get("adnlAddr") == adnl_addr: + return validator + return None + + +def check_efficiency(local, ton, args): + local.add_log("start GetValidatorEfficiency function", "debug") + validators = ton.GetValidatorsList(past=True) + validator = find_myself(ton, validators) + config32 = ton.GetConfig32() + if validator: + efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") + expected = validator['masterBlocksExpected'] + validator['workBlocksExpected'] + created = validator['masterBlocksCreated'] + validator['workBlocksCreated'] + print('#'*30) + print(f"Previous round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config32['startWorkTime'])} to {timestamp2utcdatetime(config32['endWorkTime'])}") + print('#'*30) + else: + print("Couldn't find this validator in the past round") + validators = ton.GetValidatorsList() + validator = find_myself(ton, validators) + config34 = ton.GetConfig34() + if validator: + efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") + expected = validator['masterBlocksExpected'] + validator['workBlocksExpected'] + created = validator['masterBlocksCreated'] + validator['workBlocksCreated'] + print('#'*30) + print(f"Current round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config34['startWorkTime'])} to {timestamp2utcdatetime(int(get_timestamp()))}") + print('#'*30) + else: + print("Couldn't find this validator in the current round") +# end define + def GetColorTime(datetime, timestamp): newTimestamp = get_timestamp() if timestamp > newTimestamp: From 1cbbcefcdb15fc7edcb06791d8e55da1898a4ff0 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 23:23:47 +0900 Subject: [PATCH 4/9] do not slash non masterchain validators --- mytoncore/mytoncore.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 71906598..a6b0e783 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -953,6 +953,7 @@ def GetConfig34(self): config34 = dict() result = self.liteClient.Run("getconfig 34") config34["totalValidators"] = int(parse(result, "total:", ' ')) + config34["mainValidators"] = int(parse(result, "main:", ' ')) config34["startWorkTime"] = int(parse(result, "utime_since:", ' ')) config34["endWorkTime"] = int(parse(result, "utime_until:", ' ')) config34["totalWeight"] = int(parse(result, "total_weight:", ' ')) @@ -2481,12 +2482,17 @@ def get_valid_complaints(self, complaints: dict, election_id: int): pseudohash = pubkey + str(election_id) if pseudohash == complaint['pseudohash']: exists = True + vid = item['id'] break if not exists: self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint info was not found, probably it's wrong", "info") continue + if vid >= config32['mainValidators']: + self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint created for non masterchain validator", "info") + continue + # check complaint fine value if complaint['suggestedFine'] != 101: # https://github.com/ton-blockchain/ton/blob/5847897b3758bc9ea85af38e7be8fc867e4c133a/lite-client/lite-client.cpp#L3708 self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine value is {complaint['suggestedFine']} ton", "info") @@ -2517,7 +2523,6 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict: if buff: return buff #end if - config34 = self.GetConfig34() text = "start GetValidatorsLoad function ({}, {})".format(start, end) self.local.add_log(text, "debug") if saveCompFiles is True: @@ -2558,8 +2563,6 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict: else: wr = workBlocksCreated / workBlocksExpected r = (mr + wr) / 2 - if vid >= config34["mainValidators"]: - r = wr efficiency = round(r * 100, 2) if efficiency > 10: online = True @@ -2633,6 +2636,11 @@ def GetValidatorsList(self, past=False, fast=False): validator["online"] = validatorsLoad[vid]["online"] validator["blocks_created"] = validatorsLoad[vid]["masterBlocksCreated"] + validatorsLoad[vid]["workBlocksCreated"] validator["blocks_expected"] = validatorsLoad[vid]["masterBlocksExpected"] + validatorsLoad[vid]["workBlocksExpected"] + validator["is_masterchain"] = False + if vid < config["mainValidators"]: + validator["is_masterchain"] = True + if not validator["is_masterchain"]: + validator["efficiency"] = round(validator["wr"] * 100, 2) if saveElectionEntries and adnlAddr in saveElectionEntries: validator["walletAddr"] = saveElectionEntries[adnlAddr]["walletAddr"] #end for @@ -2653,6 +2661,7 @@ def CheckValidators(self, start, end): data = self.GetValidatorsLoad(start, end, saveCompFiles=True) fullElectorAddr = self.GetFullElectorAddr() wallet = self.GetValidatorWallet(mode="vote") + config = self.GetConfig32() # Check wallet and balance if wallet is None: @@ -2670,6 +2679,8 @@ def CheckValidators(self, start, end): pseudohash = pubkey + str(electionId) if pseudohash in valid_complaints: continue + if item['id'] >= config['mainValidators']: # do not create complaints for non-masterchain validators + continue # Create complaint fileName = self.remove_proofs_from_complaint(fileName) fileName = self.PrepareComplaint(electionId, fileName) From 1fa64a0baaac53af846e6a5f71c4ed24514f0b7c Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 23:28:47 +0900 Subject: [PATCH 5/9] fixes --- mytoncore/mytoncore.py | 2 +- mytonctrl/mytonctrl.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index a6b0e783..ca19b1fd 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2506,7 +2506,7 @@ def get_valid_complaints(self, complaints: dict, election_id: int): def GetOnlineValidators(self): onlineValidators = list() - validators = self.GetValidatorsList() + validators = self.GetValidatorsList(fast=True) for validator in validators: online = validator.get("online") if online is True: diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 06246622..efbebdb3 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -580,7 +580,7 @@ def PrintStatus(local, ton, args): if opt != "fast": onlineValidators = ton.GetOnlineValidators() - validator_efficiency = ton.GetValidatorEfficiency() + # validator_efficiency = ton.GetValidatorEfficiency() if onlineValidators: onlineValidators = len(onlineValidators) From e7adb7c260e4c1be32bb75f36bff3c31e4480907 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 23:38:32 +0900 Subject: [PATCH 6/9] move check_ef to validator module --- modules/validator.py | 43 +++++++++++++++++++++++++++++++++++++++++- mytonctrl/mytonctrl.py | 38 ------------------------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/modules/validator.py b/modules/validator.py index e3569f93..cf463557 100644 --- a/modules/validator.py +++ b/modules/validator.py @@ -1,5 +1,7 @@ -from mypylib.mypylib import color_print +from mypylib.mypylib import color_print, get_timestamp from modules.module import MtcModule +from mytonctrl.mytonctrl import GetColorInt +from mytonctrl.utils import timestamp2utcdatetime class ValidatorModule(MtcModule): @@ -32,7 +34,46 @@ def vote_complaint(self, args): self.ton.VoteComplaint(election_id, complaint_hash) color_print("VoteComplaint - {green}OK{endc}") + def find_myself(self, validators: list) -> dict: + adnl_addr = self.ton.GetAdnlAddr() + for validator in validators: + if validator.get("adnlAddr") == adnl_addr: + return validator + return None + + def check_efficiency(self, args): + self.local.add_log("start GetValidatorEfficiency function", "debug") + validators = self.ton.GetValidatorsList(past=True) + validator = self.find_myself(validators) + config32 = self.ton.GetConfig32() + if validator: + efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") + expected = validator['blocks_expected'] + created = validator['blocks_created'] + print('#' * 30) + print( + f"Previous round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config32['startWorkTime'])} to {timestamp2utcdatetime(config32['endWorkTime'])}") + print('#' * 30) + else: + print("Couldn't find this validator in the past round") + validators = self.ton.GetValidatorsList() + validator = self.find_myself(validators) + config34 = self.ton.GetConfig34() + if validator: + efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") + expected = validator['blocks_expected'] + created = validator['blocks_created'] + print('#' * 30) + print( + f"Current round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config34['startWorkTime'])} to {timestamp2utcdatetime(int(get_timestamp()))}") + print('#' * 30) + else: + print("Couldn't find this validator in the current round") + + # end define + def add_console_commands(self, console): console.AddItem("vo", self.vote_offer, self.local.translate("vo_cmd")) console.AddItem("ve", self.vote_election_entry, self.local.translate("ve_cmd")) console.AddItem("vc", self.vote_complaint, self.local.translate("vc_cmd")) + console.AddItem("check_ef", self.check_efficiency, self.local.translate("check_ef_cmd")) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index efbebdb3..8df33dd5 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -80,8 +80,6 @@ def inject_globals(func): console.AddItem("set", inject_globals(SetSettings), local.translate("set_cmd")) console.AddItem("rollback", inject_globals(rollback_to_mtc1), local.translate("rollback_cmd")) - console.AddItem("check_ef", inject_globals(check_efficiency), local.translate("check_ef_cmd")) - console.AddItem("seqno", inject_globals(Seqno), local.translate("seqno_cmd")) console.AddItem("getconfig", inject_globals(GetConfig), local.translate("getconfig_cmd")) console.AddItem("get_pool_data", inject_globals(GetPoolData), local.translate("get_pool_data_cmd")) @@ -876,42 +874,6 @@ def PrintTimes(local, rootWorkchainEnabledTime_int, startWorkTime, oldStartWorkT #end define -def find_myself(ton, validators: list) -> dict: - adnl_addr = ton.GetAdnlAddr() - for validator in validators: - if validator.get("adnlAddr") == adnl_addr: - return validator - return None - - -def check_efficiency(local, ton, args): - local.add_log("start GetValidatorEfficiency function", "debug") - validators = ton.GetValidatorsList(past=True) - validator = find_myself(ton, validators) - config32 = ton.GetConfig32() - if validator: - efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") - expected = validator['masterBlocksExpected'] + validator['workBlocksExpected'] - created = validator['masterBlocksCreated'] + validator['workBlocksCreated'] - print('#'*30) - print(f"Previous round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config32['startWorkTime'])} to {timestamp2utcdatetime(config32['endWorkTime'])}") - print('#'*30) - else: - print("Couldn't find this validator in the past round") - validators = ton.GetValidatorsList() - validator = find_myself(ton, validators) - config34 = ton.GetConfig34() - if validator: - efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") - expected = validator['masterBlocksExpected'] + validator['workBlocksExpected'] - created = validator['masterBlocksCreated'] + validator['workBlocksCreated'] - print('#'*30) - print(f"Current round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config34['startWorkTime'])} to {timestamp2utcdatetime(int(get_timestamp()))}") - print('#'*30) - else: - print("Couldn't find this validator in the current round") -# end define - def GetColorTime(datetime, timestamp): newTimestamp = get_timestamp() if timestamp > newTimestamp: From 4234fc11c7821aa0c29f79ee8aeb23978024df48 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 23:40:42 +0900 Subject: [PATCH 7/9] add check_ef cmd local --- mytonctrl/resources/translate.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mytonctrl/resources/translate.json b/mytonctrl/resources/translate.json index 7bbfcf1d..9ece2f83 100644 --- a/mytonctrl/resources/translate.json +++ b/mytonctrl/resources/translate.json @@ -219,6 +219,11 @@ "ru": "Запустить установщик модулей TON", "zh_TW": "執行 TON 模組的安裝程序" }, + "check_ef_cmd": { + "en": "Check the efficiency of the validator", + "ru": "Проверить эффективность валидатора", + "zh_TW": "檢查驗證者的效率" + }, "ton_status_head": { "en": "{cyan}===[ TON network status ]==={endc}", "ru": "{cyan}===[ Статус сети TON ]==={endc}", From 984422845e2363fb1392ee122c7b27ab47a4c8b6 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 3 Sep 2024 23:43:45 +0900 Subject: [PATCH 8/9] fixes --- modules/validator.py | 3 +-- mytonctrl/mytonctrl.py | 18 +----------------- mytonctrl/utils.py | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/modules/validator.py b/modules/validator.py index cf463557..c57a756d 100644 --- a/modules/validator.py +++ b/modules/validator.py @@ -1,7 +1,6 @@ from mypylib.mypylib import color_print, get_timestamp from modules.module import MtcModule -from mytonctrl.mytonctrl import GetColorInt -from mytonctrl.utils import timestamp2utcdatetime +from mytonctrl.utils import timestamp2utcdatetime, GetColorInt class ValidatorModule(MtcModule): diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 8df33dd5..3811c7a4 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -42,7 +42,7 @@ ) from mytoncore.telemetry import is_host_virtual from mytonctrl.migrate import run_migrations -from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime, fix_git_config +from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime, fix_git_config, GetColorInt import sys, getopt, os @@ -781,22 +781,6 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid print() #end define -def GetColorInt(data, border, logic, ending=None): - if data is None: - result = "n/a" - elif logic == "more": - if data >= border: - result = bcolors.green_text(data, ending) - else: - result = bcolors.red_text(data, ending) - elif logic == "less": - if data <= border: - result = bcolors.green_text(data, ending) - else: - result = bcolors.red_text(data, ending) - return result -#end define - def GetColorStatus(input): if input == True: result = bcolors.green_text("working") diff --git a/mytonctrl/utils.py b/mytonctrl/utils.py index ba6cd105..ebb46ca6 100644 --- a/mytonctrl/utils.py +++ b/mytonctrl/utils.py @@ -1,6 +1,8 @@ import subprocess import time +from mypylib.mypylib import bcolors + def timestamp2utcdatetime(timestamp, format="%d.%m.%Y %H:%M:%S"): datetime = time.gmtime(timestamp) @@ -28,4 +30,20 @@ def fix_git_config(git_path: str): subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3) else: raise Exception(f'Failed to check git status: {err}') -#end define +# end define + +def GetColorInt(data, border, logic, ending=None): + if data is None: + result = "n/a" + elif logic == "more": + if data >= border: + result = bcolors.green_text(data, ending) + else: + result = bcolors.red_text(data, ending) + elif logic == "less": + if data <= border: + result = bcolors.green_text(data, ending) + else: + result = bcolors.red_text(data, ending) + return result +# end define From c3ec6a079dc5079da0a3fb982dffccd372e01377 Mon Sep 17 00:00:00 2001 From: Igroman787 <27614297+igroman787@users.noreply.github.com> Date: Tue, 3 Sep 2024 23:20:01 +0300 Subject: [PATCH 9/9] Visual changes and bugfix --- modules/validator.py | 44 ++++++++++++++++++++++++------------------ mytoncore/mytoncore.py | 13 +++++++------ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/modules/validator.py b/modules/validator.py index c57a756d..950b3451 100644 --- a/modules/validator.py +++ b/modules/validator.py @@ -42,33 +42,39 @@ def find_myself(self, validators: list) -> dict: def check_efficiency(self, args): self.local.add_log("start GetValidatorEfficiency function", "debug") - validators = self.ton.GetValidatorsList(past=True) - validator = self.find_myself(validators) + previous_validators = self.ton.GetValidatorsList(past=True) + validators = self.ton.GetValidatorsList() + validator = self.find_myself(previous_validators) config32 = self.ton.GetConfig32() + config34 = self.ton.GetConfig34() + color_print("{cyan}===[ Validator efficiency ]==={endc}") if validator: - efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") - expected = validator['blocks_expected'] - created = validator['blocks_created'] - print('#' * 30) - print( - f"Previous round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config32['startWorkTime'])} to {timestamp2utcdatetime(config32['endWorkTime'])}") - print('#' * 30) + efficiency = 100 if validator.efficiency > 100 else validator.efficiency + color_efficiency = GetColorInt(efficiency, 90, logic="more", ending="%") + created = validator.blocks_created + expected = validator.blocks_expected + start_time = timestamp2utcdatetime(config32.startWorkTime) + end_time = timestamp2utcdatetime(config32.endWorkTime) + color_print(f"Previous round efficiency: {color_efficiency} {{yellow}}({created} blocks created / {expected} blocks expected){{endc}}") + color_print(f"Previous round time: {{yellow}}from {start_time} to {end_time}{{endc}}") else: print("Couldn't find this validator in the past round") - validators = self.ton.GetValidatorsList() validator = self.find_myself(validators) - config34 = self.ton.GetConfig34() if validator: - efficiency = GetColorInt(validator["efficiency"], 90, logic="more", ending=" %") - expected = validator['blocks_expected'] - created = validator['blocks_created'] - print('#' * 30) - print( - f"Current round efficiency: {efficiency} ({created} blocks created / {expected} blocks expected) from {timestamp2utcdatetime(config34['startWorkTime'])} to {timestamp2utcdatetime(int(get_timestamp()))}") - print('#' * 30) + efficiency = 100 if validator.efficiency > 100 else validator.efficiency + color_efficiency = GetColorInt(efficiency, 90, logic="more", ending="%") + created = validator.blocks_created + expected = validator.blocks_expected + start_time = timestamp2utcdatetime(config34.startWorkTime) + end_time = timestamp2utcdatetime(int(get_timestamp())) + if validator.is_masterchain == False and efficiency < 90: + print("Your validator index is greater than 100.") + print("Efficiency before the validation round is complete may be inaccurate and not displayed.") + else: + color_print(f"Current round efficiency: {color_efficiency} {{yellow}}({created} blocks created / {expected} blocks expected){{endc}}") + color_print(f"Current round time: {{green}}from {start_time} to {end_time}{{endc}}") else: print("Couldn't find this validator in the current round") - # end define def add_console_commands(self, console): diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index ca19b1fd..3b433f8e 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -913,7 +913,7 @@ def GetConfig32(self): #end if self.local.add_log("start GetConfig32 function", "debug") - config32 = dict() + config32 = Dict() result = self.liteClient.Run("getconfig 32") config32["totalValidators"] = int(parse(result, "total:", ' ')) config32["mainValidators"] = int(parse(result, "main:", ' ')) @@ -929,7 +929,7 @@ def GetConfig32(self): validatorWeight = int(parse(line, "weight:", ' ')) except ValueError: validatorWeight = int(parse(line, "weight:", ')')) - buff = dict() + buff = Dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey buff["weight"] = validatorWeight @@ -950,7 +950,7 @@ def GetConfig34(self): #end if self.local.add_log("start GetConfig34 function", "debug") - config34 = dict() + config34 = Dict() result = self.liteClient.Run("getconfig 34") config34["totalValidators"] = int(parse(result, "total:", ' ')) config34["mainValidators"] = int(parse(result, "main:", ' ')) @@ -967,7 +967,7 @@ def GetConfig34(self): validatorWeight = int(parse(line, "weight:", ' ')) except ValueError: validatorWeight = int(parse(line, "weight:", ')')) - buff = dict() + buff = Dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey buff["weight"] = validatorWeight @@ -2618,8 +2618,9 @@ def GetValidatorsList(self, past=False, fast=False): start = config.get("startWorkTime") end = config.get("endWorkTime") - 60 save_vl = self.GetSaveVl() - if start in save_vl: - return save_vl[start] + start_str = str(start) + if start_str in save_vl: + return save_vl[start_str] #end if validatorsLoad = self.GetValidatorsLoad(start, end)