From a7d37b50919fdf1e724b4a01367618f31f5d684b Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 2 Oct 2024 13:11:06 +0400 Subject: [PATCH 1/2] allow fines 1% of stake for not working validators --- mytoncore/mytoncore.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 9f65af15..838faa9e 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2305,6 +2305,7 @@ def get_valid_complaints(self, complaints: dict, election_id: int): continue exists = False + vload = None for item in validators_load.values(): if 'fileName' not in item: continue @@ -2314,14 +2315,14 @@ def get_valid_complaints(self, complaints: dict, election_id: int): pseudohash = pubkey + str(election_id) if pseudohash == complaint['pseudohash']: exists = True - vid = item['id'] + vload = item 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']: + if vload["id"] >= config32['mainValidators']: self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint created for non masterchain validator", "info") continue @@ -2330,8 +2331,13 @@ def get_valid_complaints(self, complaints: dict, election_id: int): self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine value is {complaint['suggestedFine']} ton", "info") continue if complaint['suggestedFinePart'] != 0: # https://github.com/ton-blockchain/ton/blob/5847897b3758bc9ea85af38e7be8fc867e4c133a/lite-client/lite-client.cpp#L3709 - self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine part value is {complaint['suggestedFinePart']} ton", "info") - continue + if vload["id"] < config32['mainValidators'] and vload["masterBlocksCreated"] + vload["workBlocksCreated"] == 0: # masterchain validator that created 0 blocks + if complaint['suggestedFinePart'] != 42949672: # (1LL << 32) / 100 + self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine part value is {complaint['suggestedFinePart']} ton", "info") + continue + else: + self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine part value is {complaint['suggestedFinePart']} ton", "info") + continue result[complaint['pseudohash']] = complaint return result From 6ef922be48f5dc5c45511cb21866439eccf43f09 Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 2 Oct 2024 13:45:54 +0400 Subject: [PATCH 2/2] update fine warnings --- modules/validator.py | 4 ++-- mytoncore/mytoncore.py | 1 + mytonctrl/mytonctrl.py | 15 +++++++++++++-- mytonctrl/resources/translate.json | 6 +++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/validator.py b/modules/validator.py index 7a6b9ad3..05f6e98a 100644 --- a/modules/validator.py +++ b/modules/validator.py @@ -55,7 +55,7 @@ def check_efficiency(self, args): color_print(f"Previous round time: {{yellow}}from {start_time} to {end_time}{{endc}}") if validator: if validator.is_masterchain == False: - print("Validator index is greater than 100 in the previous round - no efficiency data.") + print(f"Validator index is greater than {config32['mainValidators']} in the previous round - no efficiency data.") elif validator.get('efficiency') is None: print('Failed to get efficiency for the previous round') else: @@ -72,7 +72,7 @@ def check_efficiency(self, args): color_print(f"Current round time: {{green}}from {start_time} to {end_time}{{endc}}") if validator: if validator.is_masterchain == False: - print("Validator index is greater than 100 in the current round - no efficiency data.") + print(f"Validator index is greater than {config34['mainValidators']} in the current round - no efficiency data.") elif (time.time() - config34.startWorkTime) / (config34.endWorkTime - config34.startWorkTime) < 0.8: print("The validation round has started recently, there is not enough data yet. " "The efficiency evaluation will become more accurate towards the end of the round.") diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 838faa9e..60280f4c 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2482,6 +2482,7 @@ def GetValidatorsList(self, past=False, fast=False): validator["efficiency"] = round(validator["wr"] * 100, 2) if saveElectionEntries and adnlAddr in saveElectionEntries: validator["walletAddr"] = saveElectionEntries[adnlAddr]["walletAddr"] + validator["stake"] = saveElectionEntries[adnlAddr].get("stake") #end for # Set buffer diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 1020c5c9..1bc78e4d 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -483,11 +483,22 @@ def check_slashed(local, ton): config32 = ton.GetConfig32() save_complaints = ton.GetSaveComplaints() complaints = save_complaints.get(str(config32['startWorkTime'])) + from modules.validator import ValidatorModule + module = ValidatorModule(ton, local) + vl = ton.GetValidatorsList(past=True) + me = module.find_myself(vl) + if not me: # we were not a validator in the previous round + return if not complaints: return for c in complaints.values(): - if c["adnl"] == ton.GetAdnlAddr() and c["isPassed"]: - print_warning(local, "slashed_warning") + if c["adnl"] == me["adnlAddr"] and c["isPassed"]: + if me.get("stake"): + fine = f"""{round(c['suggestedFine'] + me["stake"] * (c['suggestedFinePart'] / (1<<32)))} TON""" + else: # unknown stake amount so just print percents + fine = f"""{round(c['suggestedFine'])} TON + {(c['suggestedFinePart'] / (1<<32)) * 100} % of stake""" + warning = local.translate("slashed_warning").format(fine) + print_warning(local, warning) #end define def check_adnl(local, ton): diff --git a/mytonctrl/resources/translate.json b/mytonctrl/resources/translate.json index 632158b4..19dfbeec 100644 --- a/mytonctrl/resources/translate.json +++ b/mytonctrl/resources/translate.json @@ -445,9 +445,9 @@ "zh_TW": "{red}錯誤 - 驗證器的 UDP 端口無法從外部訪問.{endc}" }, "slashed_warning": { - "en": "{red}You were fined by 101 TON for low efficiency in the previous round.{endc}", - "ru": "{red}Вы были оштрафованы на 101 TON за низкую эффективность в предыдущем раунде.{endc}", - "zh_TW": "{red}您因上一輪效率低而被罰款 101 TON。{endc}" + "en": "{red}You were fined by {0} for low efficiency in the previous round.{endc}", + "ru": "{red}Вы были оштрафованы на {0} за низкую эффективность в предыдущем раунде.{endc}", + "zh_TW": "{red}您因上一輪效率低而被罰款 {0}。{endc}" }, "add_custom_overlay_cmd": { "en": "Add custom overlay",