Skip to content

Commit 9cd6c4e

Browse files
authored
Merge pull request #178 from ton-blockchain/mytonctrl2_dev
merge mytonctrl2_dev to mytonctrl2
2 parents 2897f5b + 05fa3ab commit 9cd6c4e

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

mytoncore/mytoncore.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,8 @@ def SendFile(self, filePath, wallet=None, **kwargs):
12051205
timeout = kwargs.get("timeout", 30)
12061206
remove = kwargs.get("remove", True)
12071207
duplicateSendfile = self.local.db.get("duplicateSendfile", True)
1208-
duplicateApi = self.local.db.get("duplicateApi", False)
1208+
telemetry = self.local.db.get("sendTelemetry", False)
1209+
duplicateApi = self.local.db.get("duplicateApi", telemetry)
12091210
if not os.path.isfile(filePath):
12101211
raise Exception("SendFile error: no such file '{filePath}'".format(filePath=filePath))
12111212
if timeout and wallet:
@@ -1911,12 +1912,13 @@ def MoveCoinsFromHW(self, wallet, destList, **kwargs):
19111912

19121913
def GetValidatorKey(self):
19131914
vconfig = self.GetValidatorConfig()
1914-
for validator in vconfig["validators"]:
1915+
validators = sorted(vconfig["validators"], key=lambda i: i['election_date'], reverse=True)
1916+
for validator in validators:
19151917
validatorId = validator["id"]
19161918
key_bytes = base64.b64decode(validatorId)
19171919
validatorKey = key_bytes.hex().upper()
19181920
timestamp = get_timestamp()
1919-
if timestamp > validator["election_date"]:
1921+
if validator["election_date"] < timestamp < validator["expire_at"]:
19201922
return validatorKey
19211923
raise Exception("GetValidatorKey error: validator key not found. Are you sure you are a validator?")
19221924
#end define
@@ -2183,6 +2185,7 @@ def GetComplaints(self, electionId=None, past=False):
21832185
buff = subdata[0] # *complaint*
21842186
item["electionId"] = electionId
21852187
item["hash"] = chash
2188+
item["hash_hex"] = dec2hex(chash)
21862189
pubkey = Dec2HexAddr(buff[0]) # *validator_pubkey*
21872190
adnl = self.GetAdnlFromPubkey(pubkey)
21882191
item["pubkey"] = pubkey
@@ -2229,7 +2232,7 @@ def GetComplaints(self, electionId=None, past=False):
22292232
def GetSaveComplaints(self):
22302233
timestamp = get_timestamp()
22312234
saveComplaints = self.local.db.get("saveComplaints")
2232-
if type(saveComplaints) is not dict:
2235+
if saveComplaints is None:
22332236
saveComplaints = dict()
22342237
self.local.db["saveComplaints"] = saveComplaints
22352238
buff = saveComplaints.copy()
@@ -2322,18 +2325,11 @@ def VoteComplaint(self, electionId, complaintHash):
23222325
validatorKey = self.GetValidatorKey()
23232326
validatorPubkey_b64 = self.GetPubKeyBase64(validatorKey)
23242327
validatorIndex = self.GetValidatorIndex()
2325-
complaint = self.GetComplaint(electionId, complaintHash)
2326-
votedValidators = complaint.get("votedValidators")
2327-
pubkey = complaint.get("pubkey")
2328-
if validatorIndex in votedValidators:
2329-
self.local.add_log("Complaint already has been voted", "info")
2330-
return
23312328
var1 = self.CreateComplaintRequest(electionId, complaintHash, validatorIndex)
23322329
validatorSignature = self.GetValidatorSignature(validatorKey, var1)
23332330
resultFilePath = self.SignComplaintVoteRequestWithValidator(complaintHash, electionId, validatorIndex, validatorPubkey_b64, validatorSignature)
23342331
resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, fullElectorAddr, 1.5)
23352332
self.SendFile(resultFilePath, wallet)
2336-
self.AddVotedComplaints(complaint)
23372333
#end define
23382334

23392335
def SaveComplaints(self, electionId):
@@ -2375,19 +2371,19 @@ def CheckComplaint(self, file_path: str):
23752371
def complaint_is_valid(self, complaint: dict):
23762372
self.local.add_log("start complaint_is_valid function", "debug")
23772373

2378-
voted_complaints = self.GetVotedComplaints()
2374+
election_id = complaint['electionId']
2375+
voted_complaints = self.GetVotedComplaints(election_id)
23792376
if complaint['pseudohash'] in voted_complaints:
2380-
self.local.add_log(f"skip checking complaint {complaint['hash']}: "
2377+
self.local.add_log(f"skip checking complaint {complaint['hash_hex']}: "
23812378
f"complaint with this pseudohash ({complaint['pseudohash']})"
23822379
f" has already been voted", "debug")
23832380
return False
23842381

23852382
# check that complaint is valid
2386-
election_id = complaint['electionId']
23872383
config32 = self.GetConfig32()
23882384
start = config32.get("startWorkTime")
23892385
if election_id != start:
2390-
self.local.add_log(f"skip checking complaint {complaint['hash']}: "
2386+
self.local.add_log(f"skip checking complaint {complaint['hash_hex']}: "
23912387
f"election_id ({election_id}) doesn't match with "
23922388
f"start work time ({config32.get('startWorkTime')})", "info")
23932389
return False
@@ -2405,15 +2401,15 @@ def complaint_is_valid(self, complaint: dict):
24052401
break
24062402

24072403
if not exists:
2408-
self.local.add_log(f"complaint {complaint['hash']} declined: complaint info was not found", "info")
2404+
self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint info was not found", "info")
24092405
return False
24102406

24112407
# check complaint fine value
24122408
if complaint['suggestedFine'] != 101: # https://github.com/ton-blockchain/ton/blob/5847897b3758bc9ea85af38e7be8fc867e4c133a/lite-client/lite-client.cpp#L3708
2413-
self.local.add_log(f"complaint {complaint['hash']} declined: complaint fine value is {complaint['suggestedFine']} ton", "info")
2409+
self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine value is {complaint['suggestedFine']} ton", "info")
24142410
return False
24152411
if complaint['suggestedFinePart'] != 0: # https://github.com/ton-blockchain/ton/blob/5847897b3758bc9ea85af38e7be8fc867e4c133a/lite-client/lite-client.cpp#L3709
2416-
self.local.add_log(f"complaint {complaint['hash']} declined: complaint fine part value is {complaint['suggestedFinePart']} ton", "info")
2412+
self.local.add_log(f"complaint {complaint['hash_hex']} declined: complaint fine part value is {complaint['suggestedFinePart']} ton", "info")
24172413
return False
24182414

24192415
return True
@@ -2941,7 +2937,7 @@ def WriteBookmarkData(self, bookmark):
29412937
def GetSaveOffers(self):
29422938
bname = "saveOffers"
29432939
saveOffers = self.local.db.get(bname)
2944-
if type(saveOffers) != dict:
2940+
if saveOffers is None:
29452941
saveOffers = dict()
29462942
self.local.db[bname] = saveOffers
29472943
return saveOffers
@@ -2956,13 +2952,15 @@ def AddSaveOffer(self, offer):
29562952
self.local.save()
29572953
#end define
29582954

2959-
def GetVotedComplaints(self):
2960-
bname = "votedComplaints"
2961-
votedComplaints = self.local.db.get(bname)
2962-
if votedComplaints is None:
2963-
votedComplaints = dict()
2964-
self.local.db[bname] = votedComplaints
2965-
return votedComplaints
2955+
def GetVotedComplaints(self, election_id: int = None):
2956+
complaints = self.GetComplaints(election_id)
2957+
result = {}
2958+
validator_index = self.GetValidatorIndex()
2959+
for pseudohash, complaint in complaints.items():
2960+
votedValidators = complaint.get("votedValidators")
2961+
if validator_index in votedValidators:
2962+
result[pseudohash] = complaint
2963+
return result
29662964
#end define
29672965

29682966
def AddVotedComplaints(self, complaint):

0 commit comments

Comments
 (0)