Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -2958,13 +2952,15 @@ 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 pseudohash, complaint in complaints.items():
votedValidators = complaint.get("votedValidators")
if validator_index in votedValidators:
result[pseudohash] = complaint
return result
#end define

def AddVotedComplaints(self, complaint):
Expand Down