Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d2c7a79
add checking adnl connection
yungwine Apr 23, 2024
e5d00f3
bugfix
yungwine Apr 23, 2024
f7b0f77
Merge pull request #249 from yungwine/mytonctrl2_dev
igroman787 Apr 25, 2024
a83696f
not display unnecessary data
igroman787 May 3, 2024
8047e59
bugfix
igroman787 May 4, 2024
a82ad84
add network name into status
igroman787 May 7, 2024
48e5486
use jemalloc
igroman787 May 13, 2024
566e4a6
add liteserver mode
yungwine May 15, 2024
540e5f8
bugfix
yungwine May 15, 2024
c9f6a48
add installation with liteserver
yungwine May 15, 2024
979a925
bugfix
yungwine May 15, 2024
00c6c9f
bugfix
yungwine May 15, 2024
10c4bed
Merge pull request #254 from yungwine/mytonctrl2_dev
igroman787 May 15, 2024
0b2839f
install requirements before migration
igroman787 May 17, 2024
860f1b5
Merge branch 'mytonctrl2_dev' of github.com:ton-blockchain/mytonctrl …
igroman787 May 17, 2024
28804e7
Merge pull request #256 from ton-blockchain/mytonctrl2_dev
igroman787 May 17, 2024
302c498
sort complaints
yungwine May 17, 2024
3614119
fix git config in status and telemetry
yungwine May 20, 2024
15d83bc
Merge pull request #257 from yungwine/mytonctrl2_dev
igroman787 May 20, 2024
ea5e3ec
Merge pull request #261 from yungwine/check-git
igroman787 May 20, 2024
de3d757
move deposit/withdraw from pools to PoolModule
yungwine May 20, 2024
bea19f9
remove en(dis)abling ls mode
yungwine May 21, 2024
3c53e6e
add validator installation mode
yungwine May 21, 2024
6c61563
run installer commands in mtc console
yungwine May 21, 2024
dd9be89
Merge pull request #262 from yungwine/mytonctrl2_dev
igroman787 May 21, 2024
1e3648b
Merge pull request #263 from yungwine/ls-mode-2
igroman787 May 21, 2024
46e8911
Merge pull request #264 from yungwine/installer
igroman787 May 21, 2024
3fdd42a
move setting archive ttl to FN
yungwine May 21, 2024
03dd9c6
fix installing ls mode
yungwine May 22, 2024
2c67a1c
add more warnings
yungwine May 22, 2024
251b127
bugfix
yungwine May 22, 2024
60e74ea
Merge remote-tracking branch 'tonblkch/mytonctrl2_dev' into warnings
yungwine May 22, 2024
2f18f03
bugfix
yungwine May 22, 2024
f9deb94
Merge pull request #266 from yungwine/mytonctrl2_dev
igroman787 May 22, 2024
fe744ec
Merge pull request #267 from yungwine/warnings
igroman787 May 22, 2024
f1d4947
Merge pull request #269 from ton-blockchain/mytonctrl2_dev
igroman787 May 23, 2024
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
3 changes: 3 additions & 0 deletions modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from modules.single_pool import SingleNominatorModule
from modules.validator import ValidatorModule
from modules.controller import ControllerModule
from modules.liteserver import LiteserverModule


MODES = {
'validator': ValidatorModule,
'nominator-pool': NominatorPoolModule,
'single-nominator': SingleNominatorModule,
'liquid-staking': ControllerModule,
'liteserver': LiteserverModule
}


Expand Down Expand Up @@ -44,6 +46,7 @@ class Setting:
'overlayTelemetryUrl': Setting(None, 'https://telemetry.toncenter.com/report_overlays', 'Overlay telemetry url'),
'duplicateApi': Setting(None, 'sendTelemetry', 'Duplicate external to Toncenter'),
'duplicateApiUrl': Setting(None, 'https://[testnet.]toncenter.com/api/v2/sendBoc', 'Toncenter api url for duplicate'),
'checkAdnl': Setting(None, 'sendTelemetry', 'Check local udp port and adnl connection'),
'liteclient_timeout': Setting(None, 3, 'Liteclient default timeout'),
'console_timeout': Setting(None, 3, 'Validator console default timeout'),
'fift_timeout': Setting(None, 3, 'Fift default timeout'),
Expand Down
12 changes: 12 additions & 0 deletions modules/liteserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import psutil

from modules.module import MtcModule


class LiteserverModule(MtcModule):

description = 'For liteserver usage only without validator.'
default_value = False

def add_console_commands(self, console):
...
40 changes: 0 additions & 40 deletions modules/nominator_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,42 +78,6 @@ def activate_pool(self, args):
self.do_activate_pool(pool)
color_print("ActivatePool - {green}OK{endc}")

def do_deposit_to_pool(self, pool_addr, amount):
wallet = self.ton.GetValidatorWallet()
bocPath = self.ton.local.buffer.my_temp_dir + wallet.name + "validator-deposit-query.boc"
fiftScript = self.ton.contractsDir + "nominator-pool/func/validator-deposit.fif"
args = [fiftScript, bocPath]
result = self.ton.fift.Run(args)
resultFilePath = self.ton.SignBocWithWallet(wallet, bocPath, pool_addr, amount)
self.ton.SendFile(resultFilePath, wallet)

def deposit_to_pool(self, args):
try:
poll_addr = args[0]
amount = float(args[1])
except:
color_print("{red}Bad args. Usage:{endc} deposit_to_pool <pool-addr> <amount>")
return
self.do_deposit_to_pool(poll_addr, amount)
color_print("DepositToPool - {green}OK{endc}")

def do_withdraw_from_pool(self, pool_addr, amount):
pool_data = self.ton.GetPoolData(pool_addr)
if pool_data["state"] == 0:
self.ton.WithdrawFromPoolProcess(pool_addr, amount)
else:
self.ton.PendWithdrawFromPool(pool_addr, amount)

def withdraw_from_pool(self, args):
try:
pool_addr = args[0]
amount = float(args[1])
except:
color_print("{red}Bad args. Usage:{endc} withdraw_from_pool <pool-addr> <amount>")
return
self.do_withdraw_from_pool(pool_addr, amount)
color_print("WithdrawFromPool - {green}OK{endc}")

def update_validator_set(self, args):
try:
pool_addr = args[0]
Expand All @@ -127,8 +91,4 @@ def update_validator_set(self, args):
def add_console_commands(self, console):
console.AddItem("new_pool", self.new_pool, self.local.translate("new_pool_cmd"))
console.AddItem("activate_pool", self.activate_pool, self.local.translate("activate_pool_cmd"))
console.AddItem("deposit_to_pool", self.deposit_to_pool, self.local.translate("deposit_to_pool_cmd"))
console.AddItem("withdraw_from_pool", self.withdraw_from_pool, self.local.translate("withdraw_from_pool_cmd"))
console.AddItem("update_validator_set", self.update_validator_set, self.local.translate("update_validator_set_cmd"))


38 changes: 38 additions & 0 deletions modules/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,45 @@ def check_download_pool_contract_scripts(self):
if not os.path.isdir(contract_path):
self.ton.DownloadContract("https://github.com/ton-blockchain/nominator-pool")

def do_deposit_to_pool(self, pool_addr, amount):
wallet = self.ton.GetValidatorWallet()
bocPath = self.ton.local.buffer.my_temp_dir + wallet.name + "validator-deposit-query.boc"
fiftScript = self.ton.contractsDir + "nominator-pool/func/validator-deposit.fif"
args = [fiftScript, bocPath]
result = self.ton.fift.Run(args)
resultFilePath = self.ton.SignBocWithWallet(wallet, bocPath, pool_addr, amount)
self.ton.SendFile(resultFilePath, wallet)

def deposit_to_pool(self, args):
try:
poll_addr = args[0]
amount = float(args[1])
except:
color_print("{red}Bad args. Usage:{endc} deposit_to_pool <pool-addr> <amount>")
return
self.do_deposit_to_pool(poll_addr, amount)
color_print("DepositToPool - {green}OK{endc}")

def do_withdraw_from_pool(self, pool_addr, amount):
pool_data = self.ton.GetPoolData(pool_addr)
if pool_data["state"] == 0:
self.ton.WithdrawFromPoolProcess(pool_addr, amount)
else:
self.ton.PendWithdrawFromPool(pool_addr, amount)

def withdraw_from_pool(self, args):
try:
pool_addr = args[0]
amount = float(args[1])
except:
color_print("{red}Bad args. Usage:{endc} withdraw_from_pool <pool-addr> <amount>")
return
self.do_withdraw_from_pool(pool_addr, amount)
color_print("WithdrawFromPool - {green}OK{endc}")

def add_console_commands(self, console):
console.AddItem("pools_list", self.print_pools_list, self.local.translate("pools_list_cmd"))
console.AddItem("delete_pool", self.delete_pool, self.local.translate("delete_pool_cmd"))
console.AddItem("import_pool", self.import_pool, self.local.translate("import_pool_cmd"))
console.AddItem("deposit_to_pool", self.deposit_to_pool, self.local.translate("deposit_to_pool_cmd"))
console.AddItem("withdraw_from_pool", self.withdraw_from_pool, self.local.translate("withdraw_from_pool_cmd"))
14 changes: 13 additions & 1 deletion mytoncore/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess

from mytoncore.mytoncore import MyTonCore
from mytonctrl.utils import fix_git_config
from mytoninstaller.config import GetConfig
from mypylib.mypylib import (
b2mb,
Expand Down Expand Up @@ -54,6 +55,8 @@ def Event(local, event_name):
ValidatorDownEvent(local)
elif event_name == "enable_ton_storage_provider":
enable_ton_storage_provider_event(local)
elif event_name == "enable_liteserver_mode":
enable_liteserver_mode(local)
local.exit()
# end define

Expand Down Expand Up @@ -90,6 +93,13 @@ def enable_ton_storage_provider_event(local):
#end define


def enable_liteserver_mode(local):
ton = MyTonCore(local)
ton.disable_mode('validator')
ton.enable_mode('liteserver')
#end define


def Elections(local, ton):
use_pool = ton.using_pool()
use_liquid_staking = ton.using_liquid_staking()
Expand Down Expand Up @@ -411,7 +421,9 @@ def Telemetry(local, ton):

# Get git hashes
gitHashes = dict()
gitHashes["mytonctrl"] = get_git_hash("/usr/src/mytonctrl")
mtc_path = "/usr/src/mytonctrl"
local.try_function(fix_git_config, args=[mtc_path])
gitHashes["mytonctrl"] = get_git_hash(mtc_path)
gitHashes["validator"] = GetBinGitHash(
"/usr/bin/ton/validator-engine/validator-engine")
data["gitHashes"] = gitHashes
Expand Down
58 changes: 58 additions & 0 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,8 @@ def SignBocWithWallet(self, wallet, boc_path, dest, coins, **kwargs):
elif "v3" in wallet.version:
fift_script = "wallet-v3.fif"
args = [fift_script, wallet.path, dest, subwallet, seqno, coins, boc_mode, boc_path, result_file_path]
else:
raise Exception(f"SignBocWithWallet error: Wallet version '{wallet.version}' is not supported")
if flags:
args += flags
result = self.fift.Run(args)
Expand Down Expand Up @@ -1912,6 +1914,8 @@ def MoveCoins(self, wallet, dest, coins, **kwargs):
elif "v3" in wallet.version:
fiftScript = "wallet-v3.fif"
args = [fiftScript, wallet.path, dest, subwallet, seqno, coins, "-m", mode, resultFilePath]
else:
raise Exception(f"MoveCoins error: Wallet version '{wallet.version}' is not supported")
if flags:
args += flags
result = self.fift.Run(args)
Expand Down Expand Up @@ -2276,6 +2280,9 @@ def GetComplaints(self, electionId=None, past=False):
complaints[chash] = item
#end for

# sort complaints by their creation time and hash
complaints = dict(sorted(complaints.items(), key=lambda item: (item[1]["createdTime"], item[0])))

# Set buffer
self.SetFunctionBuffer(bname, complaints)

Expand Down Expand Up @@ -2707,6 +2714,43 @@ def GetDbSize(self, exceptions="log"):
return result
#end define

def check_adnl(self):
telemetry = self.local.db.get("sendTelemetry", False)
check_adnl = self.local.db.get("checkAdnl", telemetry)
if not check_adnl:
return
url = 'http://45.129.96.53/adnl_check'
try:
data = self.get_local_adnl_data()
response = requests.post(url, json=data, timeout=5).json()
except Exception as e:
self.local.add_log(f'Failed to check adnl connection: {type(e)}: {e}', 'error')
return False
result = response.get("ok")
if not result:
self.local.add_log(f'Failed to check adnl connection to local node: {response.get("message")}', 'error')
return result
#end define

def get_local_adnl_data(self):

def int2ip(dec):
import socket
return socket.inet_ntoa(struct.pack("!i", dec))

vconfig = self.GetValidatorConfig()

data = {"host": int2ip(vconfig["addrs"][0]["ip"]), "port": vconfig["addrs"][0]["port"]}

dht_id = vconfig["dht"][0]["id"]
dht_id_hex = base64.b64decode(dht_id).hex().upper()

result = self.validatorConsole.Run(f"exportpub {dht_id_hex}")
pubkey = parse(result, "got public key: ", "\n")
data["pubkey"] = base64.b64encode(base64.b64decode(pubkey)[4:]).decode()
return data
#end define

def Result2List(self, text):
buff = parse(text, "result:", "\n")
if buff is None or "error" in buff:
Expand Down Expand Up @@ -3220,9 +3264,20 @@ def get_modes(self):
current_modes[name] = mode.default_value # assign default mode value
return current_modes

def check_enable_mode(self, name):
if name == 'liteserver':
if self.using_validator():
raise Exception(f'Cannot enable liteserver mode while validator mode is enabled. '
f'Use `disable_mode validator` first.')
if name == 'validator':
if self.using_liteserver():
raise Exception(f'Cannot enable validator mode while liteserver mode is enabled. '
f'Use `disable_mode liteserver` first.')

def enable_mode(self, name):
if name not in MODES:
raise Exception(f'Unknown module name: {name}. Available modes: {", ".join(MODES)}')
self.check_enable_mode(name)
current_modes = self.get_modes()
current_modes[name] = True
self.local.save()
Expand Down Expand Up @@ -3255,6 +3310,9 @@ def using_pool(self) -> bool:
def using_validator(self):
return self.get_mode_value('validator')

def using_liteserver(self):
return self.get_mode_value('liteserver')

def Tlb2Json(self, text):
# Заменить скобки
start = 0
Expand Down
7 changes: 7 additions & 0 deletions mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#
import os
import sys
import subprocess

requirements_path = "/usr/src/mytonctrl/requirements.txt"
if os.path.isfile(requirements_path):
args = ["pip3", "install", "-r", requirements_path]
subprocess.run(args)
#end if

sys.path.insert(0, '/usr/bin/mytonctrl') # Add path to mytonctrl module

Expand Down
Loading