From 9846c732b5b18b3a906d81c299af3f16ce3a3cff Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 1 Feb 2024 18:54:02 +0700 Subject: [PATCH 1/7] add duplicating externals to toncenter --- mytoncore.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index fd1a9671..6aee5760 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -1430,14 +1430,28 @@ def SendFile(self, filePath, wallet=None, **kwargs): wallet.oldseqno = self.GetSeqno(wallet) self.liteClient.Run("sendfile " + filePath) if duplicateSendfile: - self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) - self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + self.send_boc_toncenter(filePath) + # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) if timeout and wallet: self.WaitTransaction(wallet, timeout) if remove == True: os.remove(filePath) #end define + def send_boc_toncenter(self, file_path: str): + local.add_log('Start send_boc_toncenter function: ' + file_path, 'debug') + with open(file_path, "rb") as f: + boc = f.read() + boc_b64 = base64.b64encode(boc).decode("utf-8") + data = {"boc": boc_b64} + result = requests.post(url='https://toncenter.com/api/v2/sendBoc', json=data) + if result.status_code != 200: + local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info') + return False + local.add_log('Sent boc to toncenter', 'info') + return True + def WaitTransaction(self, wallet, timeout=30): local.add_log("start WaitTransaction function", "debug") timesleep = 3 From cfc85fc2ae0980bcc3f5e69734453d8619f480eb Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 1 Feb 2024 19:02:29 +0700 Subject: [PATCH 2/7] add testnet support to sending bocs via toncenter --- mytoncore.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mytoncore.py b/mytoncore.py index 6aee5760..db2dca60 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -1445,7 +1445,11 @@ def send_boc_toncenter(self, file_path: str): boc = f.read() boc_b64 = base64.b64encode(boc).decode("utf-8") data = {"boc": boc_b64} - result = requests.post(url='https://toncenter.com/api/v2/sendBoc', json=data) + if self.GetNetworkName() == 'testnet': + url = 'https://testnet.toncenter.com/api/v2/sendBoc' + else: + url = 'https://toncenter.com/api/v2/sendBoc' + result = requests.post(url=url, json=data) if result.status_code != 200: local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info') return False From a12dd8df4187620c34b251304deda7b046de5aff Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 15 Feb 2024 01:01:53 +0700 Subject: [PATCH 3/7] fix GetSaveOffers() and GetSaveComplaints() --- mytoncore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index db2dca60..71797d9f 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -2396,7 +2396,7 @@ def GetComplaints(self, electionId=None, past=False): def GetSaveComplaints(self): timestamp = get_timestamp() saveComplaints = local.db.get("saveComplaints") - if type(saveComplaints) is not dict: + if saveComplaints is None: saveComplaints = dict() local.db["saveComplaints"] = saveComplaints buff = saveComplaints.copy() @@ -3061,7 +3061,7 @@ def WriteBookmarkData(self, bookmark): def GetSaveOffers(self): bname = "saveOffers" saveOffers = local.db.get(bname) - if type(saveOffers) != dict: + if saveOffers is None: saveOffers = dict() local.db[bname] = saveOffers return saveOffers From 5f839f5a81066fada0c94e4204f7be66eab34f29 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 19 Feb 2024 13:58:20 +0700 Subject: [PATCH 4/7] fix GetValidatorKey --- mytoncore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index 71797d9f..56307d28 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -2078,12 +2078,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 846ef29be01d9bd28d389ca19cece64fce34d447 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 19 Feb 2024 14:19:42 +0700 Subject: [PATCH 5/7] update duplicateSendfile --- mytoncore.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index 56307d28..65d66d3e 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -1430,9 +1430,12 @@ def SendFile(self, filePath, wallet=None, **kwargs): wallet.oldseqno = self.GetSeqno(wallet) self.liteClient.Run("sendfile " + filePath) if duplicateSendfile: + try: + self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + except Exception as e: + local.add_log('failed to send file via liteclient: ' + str(e), 'info') self.send_boc_toncenter(filePath) - # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) - # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) if timeout and wallet: self.WaitTransaction(wallet, timeout) if remove == True: From 52052ee9be969710d101073c6bd7724a83476b0f Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 26 Mar 2024 10:57:01 +0800 Subject: [PATCH 6/7] add rocksdb telemetry --- mytoncore.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/mytoncore.py b/mytoncore.py index 65d66d3e..82572b5b 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -4064,6 +4064,67 @@ def GetSwapInfo(): return result #end define + +def parse_db_stats(path: str): + with open(path) as f: + lines = f.readlines() + result = {} + for line in lines: + s = line.strip().split(maxsplit=1) + items = re.findall(r"(\S+)\s:\s(\S+)", s[1]) + if len(items) == 1: + item = items[0] + if float(item[1]) > 0: + result[s[0]] = float(item[1]) + else: + if any(float(v) > 0 for k, v in items): + result[s[0]] = {} + result[s[0]] = {k: float(v) for k, v in items} + return result +# end define + + +def get_db_stats(): + result = { + 'rocksdb': { + 'ok': True, + 'message': '', + 'data': {} + }, + 'celldb': { + 'ok': True, + 'message': '', + 'data': {} + }, + } + rocksdb_stats_path = '/var/ton-work/db/db_stats.txt' + celldb_stats_path = '/var/ton-work/db/celldb/db_stats.txt' + if os.path.exists(rocksdb_stats_path): + try: + result['rocksdb']['data'] = parse_db_stats(rocksdb_stats_path) + except Exception as e: + result['rocksdb']['ok'] = False + result['rocksdb']['message'] = f'failed to fetch db stats: {e}' + else: + result['rocksdb']['ok'] = False + result['rocksdb']['message'] = 'db stats file is not exists' + # end if + + if os.path.exists(celldb_stats_path): + try: + result['celldb']['data'] = parse_db_stats(celldb_stats_path) + except Exception as e: + result['celldb']['ok'] = False + result['celldb']['message'] = f'failed to fetch db stats: {e}' + else: + result['celldb']['ok'] = False + result['celldb']['message'] = 'db stats file is not exists' + # end if + + return result +# end define + + def GetValidatorProcessInfo(): pid = get_service_pid("validator") if pid == None or pid == 0: @@ -4108,6 +4169,7 @@ def Telemetry(ton): data["swap"] = GetSwapInfo() data["uname"] = GetUname() data["vprocess"] = GetValidatorProcessInfo() + data["dbStats"] = get_db_stats() elections = local.try_function(ton.GetElectionEntries) complaints = local.try_function(ton.GetComplaints) From 60b29c8148e70343f82de6bc32c3a47e5095f460 Mon Sep 17 00:00:00 2001 From: yungwine Date: Fri, 29 Mar 2024 15:29:07 +0800 Subject: [PATCH 7/7] add liblz4-dev installing --- scripts/toninstaller.sh | 2 +- scripts/upgrade.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/toninstaller.sh b/scripts/toninstaller.sh index 6248acf5..02f865a2 100755 --- a/scripts/toninstaller.sh +++ b/scripts/toninstaller.sh @@ -84,7 +84,7 @@ if [ "$OSTYPE" == "linux-gnu" ]; then elif [ -f /etc/debian_version ]; then echo "Ubuntu/Debian Linux detected." apt-get update - apt-get install -y build-essential git cmake clang libgflags-dev zlib1g-dev libssl-dev libreadline-dev libmicrohttpd-dev pkg-config libgsl-dev python3 python3-dev python3-pip libsecp256k1-dev libsodium-dev + apt-get install -y build-essential git cmake clang libgflags-dev zlib1g-dev libssl-dev libreadline-dev libmicrohttpd-dev pkg-config libgsl-dev python3 python3-dev python3-pip libsecp256k1-dev libsodium-dev liblz4-dev # Install ninja apt-get install -y ninja-build diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 3f95d73a..117d168b 100644 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -29,7 +29,7 @@ COLOR='\033[92m' ENDC='\033[0m' # Установить дополнительные зависимости -apt-get install -y libsecp256k1-dev libsodium-dev ninja-build +apt-get install -y libsecp256k1-dev libsodium-dev ninja-build liblz4-dev # bugfix if the files are in the wrong place wget "https://ton-blockchain.github.io/global.config.json" -O global.config.json