From 5c2f1f1e9d1caa0daab43c7118ddb3292c728d6a Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 14 Feb 2024 14:34:45 +0700 Subject: [PATCH 1/6] fix GetSaveOffers() --- mytoncore/mytoncore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 3d18fb6b..1ee3038e 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2941,7 +2941,7 @@ def WriteBookmarkData(self, bookmark): def GetSaveOffers(self): bname = "saveOffers" saveOffers = self.local.db.get(bname) - if type(saveOffers) != dict: + if saveOffers is None: saveOffers = dict() self.local.db[bname] = saveOffers return saveOffers From 74fdbe66c71b6f2c659da154440833e557b9de31 Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 14 Feb 2024 17:55:30 +0700 Subject: [PATCH 2/6] fix GetSaveComplaints() --- mytoncore/mytoncore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 1ee3038e..63c47e89 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2229,7 +2229,7 @@ def GetComplaints(self, electionId=None, past=False): def GetSaveComplaints(self): timestamp = get_timestamp() saveComplaints = self.local.db.get("saveComplaints") - if type(saveComplaints) is not dict: + if saveComplaints is None: saveComplaints = dict() self.local.db["saveComplaints"] = saveComplaints buff = saveComplaints.copy() From 0a130ee424bfedd261ce5900f91b337b4e816db6 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 15 Feb 2024 16:50:15 +0700 Subject: [PATCH 3/6] fix GetValidatorKey() --- mytoncore/mytoncore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 63c47e89..43b9b420 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -1911,12 +1911,13 @@ def MoveCoinsFromHW(self, wallet, destList, **kwargs): def GetValidatorKey(self): vconfig = self.GetValidatorConfig() - for validator in vconfig["validators"]: + validators = sorted(vconfig["validators"], key=lambda i: i['election_date'], reverse=True) + for validator in validators: validatorId = validator["id"] key_bytes = base64.b64decode(validatorId) validatorKey = key_bytes.hex().upper() timestamp = get_timestamp() - if timestamp > validator["election_date"]: + if validator["election_date"] < timestamp < validator["expire_at"]: return validatorKey raise Exception("GetValidatorKey error: validator key not found. Are you sure you are a validator?") #end define From c28197dbd2953794f82ef3f813fa1cb9bfe264ff Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 15 Feb 2024 17:18:27 +0700 Subject: [PATCH 4/6] change duplicateApi default behaviour --- mytoncore/mytoncore.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 43b9b420..f49a4eba 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -1205,7 +1205,8 @@ def SendFile(self, filePath, wallet=None, **kwargs): timeout = kwargs.get("timeout", 30) remove = kwargs.get("remove", True) duplicateSendfile = self.local.db.get("duplicateSendfile", True) - duplicateApi = self.local.db.get("duplicateApi", False) + telemetry = self.local.db.get("sendTelemetry", False) + duplicateApi = self.local.db.get("duplicateApi", telemetry) if not os.path.isfile(filePath): raise Exception("SendFile error: no such file '{filePath}'".format(filePath=filePath)) if timeout and wallet: From f54ded076af11c5d584a3ddecbb8cdf4ff028510 Mon Sep 17 00:00:00 2001 From: yungwine Date: Fri, 16 Feb 2024 14:07:27 +0700 Subject: [PATCH 5/6] refactor complaints --- mytoncore/mytoncore.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index f49a4eba..eaa1268c 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2185,6 +2185,7 @@ def GetComplaints(self, electionId=None, past=False): buff = subdata[0] # *complaint* item["electionId"] = electionId item["hash"] = chash + item["hash_hex"] = dec2hex(chash) pubkey = Dec2HexAddr(buff[0]) # *validator_pubkey* adnl = self.GetAdnlFromPubkey(pubkey) item["pubkey"] = pubkey @@ -2324,18 +2325,11 @@ def VoteComplaint(self, electionId, complaintHash): validatorKey = self.GetValidatorKey() validatorPubkey_b64 = self.GetPubKeyBase64(validatorKey) validatorIndex = self.GetValidatorIndex() - complaint = self.GetComplaint(electionId, complaintHash) - votedValidators = complaint.get("votedValidators") - pubkey = complaint.get("pubkey") - if validatorIndex in votedValidators: - self.local.add_log("Complaint already has been voted", "info") - return var1 = self.CreateComplaintRequest(electionId, complaintHash, validatorIndex) validatorSignature = self.GetValidatorSignature(validatorKey, var1) resultFilePath = self.SignComplaintVoteRequestWithValidator(complaintHash, electionId, validatorIndex, validatorPubkey_b64, validatorSignature) resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, fullElectorAddr, 1.5) self.SendFile(resultFilePath, wallet) - self.AddVotedComplaints(complaint) #end define def SaveComplaints(self, electionId): @@ -2377,19 +2371,19 @@ def CheckComplaint(self, file_path: str): def complaint_is_valid(self, complaint: dict): self.local.add_log("start complaint_is_valid function", "debug") - voted_complaints = self.GetVotedComplaints() + election_id = complaint['electionId'] + voted_complaints = self.GetVotedComplaints(election_id) if complaint['pseudohash'] in voted_complaints: - self.local.add_log(f"skip checking complaint {complaint['hash']}: " + self.local.add_log(f"skip checking complaint {complaint['hash_hex']}: " f"complaint with this pseudohash ({complaint['pseudohash']})" f" has already been voted", "debug") return False # check that complaint is valid - election_id = complaint['electionId'] config32 = self.GetConfig32() start = config32.get("startWorkTime") if election_id != start: - self.local.add_log(f"skip checking complaint {complaint['hash']}: " + self.local.add_log(f"skip checking complaint {complaint['hash_hex']}: " f"election_id ({election_id}) doesn't match with " f"start work time ({config32.get('startWorkTime')})", "info") return False @@ -2407,15 +2401,15 @@ def complaint_is_valid(self, complaint: dict): break if not exists: - self.local.add_log(f"complaint {complaint['hash']} declined: complaint info was not found", "info") + self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint info was not found", "info") return False # 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']} declined: complaint fine value is {complaint['suggestedFine']} ton", "info") + self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine value is {complaint['suggestedFine']} ton", "info") return False 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']} declined: complaint fine part value is {complaint['suggestedFinePart']} ton", "info") + self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine part value is {complaint['suggestedFinePart']} ton", "info") return False return True @@ -2958,13 +2952,17 @@ def AddSaveOffer(self, offer): self.local.save() #end define - def GetVotedComplaints(self): - bname = "votedComplaints" - votedComplaints = self.local.db.get(bname) - if votedComplaints is None: - votedComplaints = dict() - self.local.db[bname] = votedComplaints - return votedComplaints + def GetVotedComplaints(self, election_id: int = None): + complaints = self.GetComplaints(election_id) + result = {} + validator_index = self.GetValidatorIndex() + for complaint in complaints.values(): + votedValidators = complaint.get("votedValidators") + if validator_index in votedValidators: + pubkey = complaint.get("pubkey") + election_id = complaint.get("electionId") + result[pubkey + str(election_id)] = complaint + return result #end define def AddVotedComplaints(self, complaint): From f9353b7121b10c80209271b0c31e9ae4266bc873 Mon Sep 17 00:00:00 2001 From: yungwine Date: Fri, 16 Feb 2024 14:10:46 +0700 Subject: [PATCH 6/6] improves --- mytoncore/mytoncore.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index eaa1268c..b515d01b 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -2956,12 +2956,10 @@ def GetVotedComplaints(self, election_id: int = None): complaints = self.GetComplaints(election_id) result = {} validator_index = self.GetValidatorIndex() - for complaint in complaints.values(): + for pseudohash, complaint in complaints.items(): votedValidators = complaint.get("votedValidators") if validator_index in votedValidators: - pubkey = complaint.get("pubkey") - election_id = complaint.get("electionId") - result[pubkey + str(election_id)] = complaint + result[pseudohash] = complaint return result #end define