From 45b96a7a9cb1c962c0140a33bbfeac273eee51b5 Mon Sep 17 00:00:00 2001 From: yungwine Date: Fri, 23 Feb 2024 13:55:22 +0700 Subject: [PATCH 1/3] fix git config --- mytonctrl/mytonctrl.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 06a4d8ac..b4a7768a 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -225,9 +225,26 @@ def check_vport(local, ton): color_print(local.translate("vport_error")) #end define + +def fix_git_config(git_path: str): + args = ["git", "status"] + try: + process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_path, timeout=3) + err = process.stderr.decode("utf-8") + except Exception as e: + err = str(e) + if err: + if 'git config --global --add safe.directory' in err: + args = ["git", "config", "--global", "--add", "safe.directory", git_path] + subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3) + else: + raise Exception(f'Failed to check git status: {err}') + + def check_git(input_args, default_repo, text): src_dir = "/usr/src" git_path = f"{src_dir}/{default_repo}" + fix_git_config(git_path) default_author = "ton-blockchain" default_branch = "master" From 32afd4d34461280f6b5c30f4e894c3377b4268c2 Mon Sep 17 00:00:00 2001 From: yungwine Date: Fri, 23 Feb 2024 22:20:33 +0700 Subject: [PATCH 2/3] dont participate in elections if there is no adnl address in vconfig --- mytoncore/mytoncore.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 81fe2c8c..152fcdbf 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -1436,6 +1436,18 @@ def ElectionEntry(self, args=None): if (startWorkTime - now) > self.local.db["participateBeforeEnd"] and \ (now + self.local.db["periods"]["elections"]) < startWorkTime: return + + vconfig = self.GetValidatorConfig() + + have_adnl = False + # Check if ADNL address is in the list + for a in vconfig.adnl: + if base64.b64decode(a.id).hex() == adnlAddr: + have_adnl = True + break + if not have_adnl: + raise Exception('ADNL address is not found') + # Check if election entry already completed entries = self.GetElectionEntries() if adnlAddr in entries: From 777b1bf1d7da3f2860c96542e6a48eb4e0fa95de Mon Sep 17 00:00:00 2001 From: yungwine Date: Sat, 24 Feb 2024 00:29:18 +0700 Subject: [PATCH 3/3] bugfix --- mytoncore/mytoncore.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 152fcdbf..a92eb1bd 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -1428,7 +1428,8 @@ def ElectionEntry(self, args=None): #end if # Get ADNL address - adnlAddr = self.GetAdnlAddr() + adnl_addr = self.GetAdnlAddr() + adnl_addr_bytes = bytes.fromhex(adnl_addr) # Check wether it is too early to participate if "participateBeforeEnd" in self.local.db: @@ -1442,7 +1443,7 @@ def ElectionEntry(self, args=None): have_adnl = False # Check if ADNL address is in the list for a in vconfig.adnl: - if base64.b64decode(a.id).hex() == adnlAddr: + if base64.b64decode(a.id) == adnl_addr_bytes: have_adnl = True break if not have_adnl: @@ -1450,7 +1451,7 @@ def ElectionEntry(self, args=None): # Check if election entry already completed entries = self.GetElectionEntries() - if adnlAddr in entries: + if adnl_addr in entries: self.local.add_log("Elections entry already completed", "info") return #end if @@ -1468,24 +1469,24 @@ def ElectionEntry(self, args=None): validatorPubkey_b64 = self.GetPubKeyBase64(validatorKey) # Attach ADNL addr to validator - self.AttachAdnlAddrToValidator(adnlAddr, validatorKey, endWorkTime) + self.AttachAdnlAddrToValidator(adnl_addr, validatorKey, endWorkTime) # Get max factor maxFactor = self.GetMaxFactor() # Create fift's. Continue with pool or walet if usePool: - var1 = self.CreateElectionRequest(pool, startWorkTime, adnlAddr, maxFactor) + var1 = self.CreateElectionRequest(pool, startWorkTime, adnl_addr, maxFactor) validatorSignature = self.GetValidatorSignature(validatorKey, var1) - validatorPubkey, resultFilePath = self.SignElectionRequestWithPoolWithValidator(pool, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor, stake) + validatorPubkey, resultFilePath = self.SignElectionRequestWithPoolWithValidator(pool, startWorkTime, adnl_addr, validatorPubkey_b64, validatorSignature, maxFactor, stake) # Send boc file to TON resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, pool.addrB64, 1.3) self.SendFile(resultFilePath, wallet) else: - var1 = self.CreateElectionRequest(wallet, startWorkTime, adnlAddr, maxFactor) + var1 = self.CreateElectionRequest(wallet, startWorkTime, adnl_addr, maxFactor) validatorSignature = self.GetValidatorSignature(validatorKey, var1) - validatorPubkey, resultFilePath = self.SignElectionRequestWithValidator(wallet, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor) + validatorPubkey, resultFilePath = self.SignElectionRequestWithValidator(wallet, startWorkTime, adnl_addr, validatorPubkey_b64, validatorSignature, maxFactor) # Send boc file to TON resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, fullElectorAddr, stake) @@ -1493,7 +1494,7 @@ def ElectionEntry(self, args=None): #end if # Save vars to json file - self.SaveElectionVarsToJsonFile(wallet=wallet, account=account, stake=stake, maxFactor=maxFactor, fullElectorAddr=fullElectorAddr, startWorkTime=startWorkTime, validatorsElectedFor=validatorsElectedFor, endWorkTime=endWorkTime, validatorKey=validatorKey, validatorPubkey_b64=validatorPubkey_b64, adnlAddr=adnlAddr, var1=var1, validatorSignature=validatorSignature, validatorPubkey=validatorPubkey) + self.SaveElectionVarsToJsonFile(wallet=wallet, account=account, stake=stake, maxFactor=maxFactor, fullElectorAddr=fullElectorAddr, startWorkTime=startWorkTime, validatorsElectedFor=validatorsElectedFor, endWorkTime=endWorkTime, validatorKey=validatorKey, validatorPubkey_b64=validatorPubkey_b64, adnlAddr=adnl_addr, var1=var1, validatorSignature=validatorSignature, validatorPubkey=validatorPubkey) self.local.add_log("ElectionEntry completed. Start work time: " + str(startWorkTime)) #end define