Skip to content

Commit 78f32e5

Browse files
committed
Merge remote-tracking branch 'origin/mytonctrl2_dev' into mytonctrl2_dev
2 parents d9176c3 + d52819a commit 78f32e5

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

mytoncore/liteclient.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ def Run(self, cmd, **kwargs):
1717
liteclient_timeout = self.local.db.liteclient_timeout if self.local.db.liteclient_timeout else 3
1818
timeout = kwargs.get("timeout", liteclient_timeout)
1919
useLocalLiteServer = kwargs.get("useLocalLiteServer", True)
20-
validatorStatus = self.ton.GetValidatorStatus()
21-
validatorOutOfSync = validatorStatus.get("outOfSync")
20+
validator_status = self.ton.GetValidatorStatus()
2221
args = [self.appPath, "--global-config", self.configPath, "--verbosity", "0", "--cmd", cmd]
2322
if index is not None:
2423
index = str(index)
2524
args += ["-i", index]
26-
elif useLocalLiteServer and self.pubkeyPath and validatorOutOfSync < 20:
25+
elif useLocalLiteServer and self.pubkeyPath and validator_status.out_of_sync and validator_status.out_of_sync < 20:
2726
args = [self.appPath, "--addr", self.addr, "--pub", self.pubkeyPath, "--verbosity", "0", "--cmd", cmd]
2827
else:
2928
liteServers = self.local.db.get("liteServers")

mytoncore/mytoncore.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -810,42 +810,48 @@ def GetShardsNumber(self, block=None):
810810

811811
def GetValidatorStatus(self):
812812
# Get buffer
813-
bname = "validatorStatus"
813+
bname = "validator_status"
814814
buff = self.GetFunctionBuffer(bname)
815815
if buff:
816816
return buff
817817
#end if
818818

819819
self.local.add_log("start GetValidatorStatus function", "debug")
820-
validatorStatus = dict()
820+
status = Dict()
821821
try:
822-
validatorStatus["isWorking"] = True
822+
# Parse
823+
status.is_working = True
823824
result = self.validatorConsole.Run("getstats")
824-
validatorStatus["unixtime"] = int(parse(result, "unixtime", '\n'))
825-
validatorStatus["masterchainblocktime"] = int(parse(result, "masterchainblocktime", '\n'))
826-
validatorStatus["stateserializermasterchainseqno"] = int(parse(result, "stateserializermasterchainseqno", '\n'))
827-
validatorStatus["shardclientmasterchainseqno"] = int(parse(result, "shardclientmasterchainseqno", '\n'))
825+
status.unixtime = int(parse(result, "unixtime", '\n'))
826+
status.masterchainblocktime = int(parse(result, "masterchainblocktime", '\n'))
827+
status.stateserializermasterchainseqno = int(parse(result, "stateserializermasterchainseqno", '\n'))
828+
status.shardclientmasterchainseqno = int(parse(result, "shardclientmasterchainseqno", '\n'))
828829
buff = parse(result, "masterchainblock", '\n')
829-
validatorStatus["masterchainblock"] = self.GVS_GetItemFromBuff(buff)
830+
status.masterchainblock = self.GVS_GetItemFromBuff(buff)
830831
buff = parse(result, "gcmasterchainblock", '\n')
831-
validatorStatus["gcmasterchainblock"] = self.GVS_GetItemFromBuff(buff)
832+
status.gcmasterchainblock = self.GVS_GetItemFromBuff(buff)
832833
buff = parse(result, "keymasterchainblock", '\n')
833-
validatorStatus["keymasterchainblock"] = self.GVS_GetItemFromBuff(buff)
834+
status.keymasterchainblock = self.GVS_GetItemFromBuff(buff)
834835
buff = parse(result, "rotatemasterchainblock", '\n')
835-
validatorStatus["rotatemasterchainblock"] = self.GVS_GetItemFromBuff(buff)
836-
validatorStatus["transNum"] = self.local.buffer.get("transNum", -1)
837-
validatorStatus["blocksNum"] = self.local.buffer.get("blocksNum", -1)
838-
validatorStatus["masterBlocksNum"] = self.local.buffer.get("masterBlocksNum", -1)
836+
status.rotatemasterchainblock = self.GVS_GetItemFromBuff(buff)
837+
# Calculate
838+
status.masterchain_out_of_sync = status.unixtime - status.masterchainblocktime
839+
status.shardchain_out_of_sync = status.masterchainblock - status.shardclientmasterchainseqno
840+
status.masterchain_out_of_ser = status.masterchainblock - status.stateserializermasterchainseqno
841+
status.out_of_sync = status.masterchain_out_of_sync if status.masterchain_out_of_sync > status.shardchain_out_of_sync else status.shardchain_out_of_sync
842+
status.out_of_ser = status.masterchain_out_of_ser
839843
except Exception as ex:
840844
self.local.add_log(f"GetValidatorStatus warning: {ex}", "warning")
841-
validatorStatus["isWorking"] = False
842-
validatorStatus["unixtime"] = get_timestamp()
843-
validatorStatus["masterchainblocktime"] = 0
844-
validatorStatus["outOfSync"] = validatorStatus["unixtime"] - validatorStatus["masterchainblocktime"]
845+
status.is_working = False
846+
#end try
847+
848+
# old vars
849+
status.outOfSync = status.out_of_sync
850+
status.isWorking = status.is_working
845851

846852
# Set buffer
847-
self.SetFunctionBuffer(bname, validatorStatus)
848-
return validatorStatus
853+
self.SetFunctionBuffer(bname, status)
854+
return status
849855
#end define
850856

851857
def GVS_GetItemFromBuff(self, buff):
@@ -2087,8 +2093,8 @@ def GetOffers(self):
20872093

20882094
# Create dict
20892095
# parser from: https://github.com/ton-blockchain/ton/blob/dab7ee3f9794db5a6d32c895dbc2564f681d9126/crypto/smartcont/config-code.fc#L607
2090-
item = dict()
2091-
item["config"] = dict()
2096+
item = Dict()
2097+
item["config"] = Dict()
20922098
item["hash"] = hash
20932099
item["endTime"] = subdata[0] # *expires*
20942100
item["critFlag"] = subdata[1] # *critical*
@@ -2349,12 +2355,12 @@ def VoteOffer(self, offerHash):
23492355
if validatorIndex in offer.get("votedValidators"):
23502356
self.local.add_log("Proposal already has been voted", "debug")
23512357
return
2358+
self.add_save_offer(offer)
23522359
var1 = self.CreateConfigProposalRequest(offerHash, validatorIndex)
23532360
validatorSignature = self.GetValidatorSignature(validatorKey, var1)
23542361
resultFilePath = self.SignProposalVoteRequestWithValidator(offerHash, validatorIndex, validatorPubkey_b64, validatorSignature)
23552362
resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, fullConfigAddr, 1.5)
23562363
self.SendFile(resultFilePath, wallet)
2357-
self.add_save_offer(offer)
23582364
#end define
23592365

23602366
def VoteComplaint(self, electionId, complaintHash):

mytonctrl/mytonctrl.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def PrintTonStatus(local, startWorkTime, totalValidators, onlineValidators, shar
597597
print()
598598
#end define
599599

600-
def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, validatorWallet, validatorAccount, validatorStatus, dbSize, dbUsage, memoryInfo, swapInfo, netLoadAvg, disksLoadAvg, disksLoadPercentAvg):
600+
def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, validatorWallet, validatorAccount, validator_status, dbSize, dbUsage, memoryInfo, swapInfo, netLoadAvg, disksLoadAvg, disksLoadPercentAvg):
601601
if validatorWallet is None:
602602
return
603603
walletAddr = validatorWallet.addrB64
@@ -610,7 +610,6 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid
610610
netLoad1 = netLoadAvg[0]
611611
netLoad5 = netLoadAvg[1]
612612
netLoad15 = netLoadAvg[2]
613-
validatorOutOfSync = validatorStatus.get("outOfSync")
614613

615614
validatorIndex_text = GetColorInt(validatorIndex, 0, logic="more")
616615
validatorIndex_text = local.translate("local_status_validator_index").format(validatorIndex_text)
@@ -671,11 +670,12 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid
671670
validatorUptime = get_service_uptime("validator")
672671
mytoncoreUptime_text = bcolors.green_text(time2human(mytoncoreUptime))
673672
validatorUptime_text = bcolors.green_text(time2human(validatorUptime))
674-
mytoncoreStatus = GetColorStatus(mytoncoreStatus_bool)
675-
validatorStatus = GetColorStatus(validatorStatus_bool)
676-
mytoncoreStatus_text = local.translate("local_status_mytoncore_status").format(mytoncoreStatus, mytoncoreUptime_text)
677-
validatorStatus_text = local.translate("local_status_validator_status").format(validatorStatus, validatorUptime_text)
678-
validatorOutOfSync_text = local.translate("local_status_validator_out_of_sync").format(GetColorInt(validatorOutOfSync, 20, logic="less", ending=" s"))
673+
mytoncoreStatus_color = GetColorStatus(mytoncoreStatus_bool)
674+
validatorStatus_color = GetColorStatus(validatorStatus_bool)
675+
mytoncoreStatus_text = local.translate("local_status_mytoncore_status").format(mytoncoreStatus_color, mytoncoreUptime_text)
676+
validatorStatus_text = local.translate("local_status_validator_status").format(validatorStatus_color, validatorUptime_text)
677+
validator_out_of_sync_text = local.translate("local_status_validator_out_of_sync").format(GetColorInt(validator_status.out_of_sync, 20, logic="less", ending=" s"))
678+
validator_out_of_ser_text = local.translate("local_status_validator_out_of_ser").format(GetColorInt(validator_status.out_of_ser, 20, logic="less", ending=" blocks"))
679679
dbSize_text = GetColorInt(dbSize, 1000, logic="less", ending=" Gb")
680680
dbUsage_text = GetColorInt(dbUsage, 80, logic="less", ending="%")
681681
dbStatus_text = local.translate("local_status_db").format(dbSize_text, dbUsage_text)
@@ -708,7 +708,8 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid
708708
print(disksLoad_text)
709709
print(mytoncoreStatus_text)
710710
print(validatorStatus_text)
711-
print(validatorOutOfSync_text)
711+
print(validator_out_of_sync_text)
712+
print(validator_out_of_ser_text)
712713
print(dbStatus_text)
713714
print(mtcVersion_text)
714715
print(validatorVersion_text)
@@ -717,7 +718,7 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid
717718

718719
def GetColorInt(data, border, logic, ending=None):
719720
if data is None:
720-
result = bcolors.green_text("n/a")
721+
result = "n/a"
721722
elif logic == "more":
722723
if data >= border:
723724
result = bcolors.green_text(data, ending)
@@ -1104,7 +1105,7 @@ def PrintOffersList(ton, args):
11041105
print(text)
11051106
else:
11061107
table = list()
1107-
table += [["Hash", "Votes", "W/L", "Approved", "Is passed"]]
1108+
table += [["Hash", "Config", "Votes", "W/L", "Approved", "Is passed"]]
11081109
for item in data:
11091110
hash = item.get("hash")
11101111
votedValidators = len(item.get("votedValidators"))
@@ -1120,7 +1121,7 @@ def PrintOffersList(ton, args):
11201121
isPassed = bcolors.green_text("true")
11211122
if isPassed == False:
11221123
isPassed = bcolors.red_text("false")
1123-
table += [[hash, votedValidators, wl, approvedPercent_text, isPassed]]
1124+
table += [[hash, item.config.id, votedValidators, wl, approvedPercent_text, isPassed]]
11241125
print_table(table)
11251126
#end define
11261127

mytonctrl/resources/translate.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@
324324
"ru": "Рассинхронизация локального валидатора: {0}",
325325
"zh_TW": "本地驗證者不同步: {0}"
326326
},
327+
"local_status_validator_out_of_ser": {
328+
"en": "Local validator out of ser: {0}",
329+
"ru": "Рассериализация локального валидатора: {0}",
330+
"zh_TW": "本地驗證者不同步: {0}"
331+
},
327332
"local_status_db": {
328333
"en": "Local validator database size: {0}, {1}",
329334
"ru": "Размер БД локального валидатора: {0}, {1}",

0 commit comments

Comments
 (0)