Skip to content

Commit 374a88e

Browse files
authored
Merge pull request #316 from ton-blockchain/mytonctrl2_dev
Mytonctrl2 dev
2 parents e92989c + b40c9c7 commit 374a88e

File tree

7 files changed

+142
-9
lines changed

7 files changed

+142
-9
lines changed

modules/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Setting:
3434
'stake': Setting('validator', None, 'Stake amount'),
3535
'stakePercent': Setting('validator', 99, 'Stake percent if `stake` is null'),
3636
'isSlashing': Setting('validator', None, 'Create complaints to validators'),
37+
'validatorWalletName': Setting('validator', 'wallet_001', 'Validator\'s wallet name'),
3738
'maxFactor': Setting('validator', None, 'Param send to Elector. if null will be taken from 17 config param'),
3839
'participateBeforeEnd': Setting('validator', None, 'Amount of seconds before start of round to participate'),
3940
'liquid_pool_addr': Setting('liquid-staking', None, 'Liquid staking pool address'),

modules/collator_config.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import json
2+
import requests
3+
4+
from mypylib.mypylib import color_print
5+
from modules.module import MtcModule
6+
7+
8+
class CollatorConfigModule(MtcModule):
9+
10+
@staticmethod
11+
def check_config_url(url):
12+
try:
13+
r = requests.get(url, timeout=3)
14+
if r.status_code != 200:
15+
print(f'Failed to get config from {url}: {r.status_code} code; {r.text}')
16+
return
17+
return r.json()
18+
except Exception as e:
19+
print(f'Failed to get config from {url}: {e}')
20+
return
21+
22+
@staticmethod
23+
def check_config_file(path):
24+
try:
25+
with open(path, 'r') as f:
26+
return json.load(f)
27+
except Exception as e:
28+
print(f'Failed to read config from {path}: {e}')
29+
return
30+
31+
@staticmethod
32+
def get_config(path):
33+
if 'http' in path:
34+
config = CollatorConfigModule.check_config_url(path)
35+
else:
36+
config = CollatorConfigModule.check_config_file(path)
37+
if config is None:
38+
raise Exception(f'Failed to get config')
39+
return config
40+
41+
def add_collator_config_to_vc(self, config: dict):
42+
self.local.add_log(f"Adding collator options config to validator console", "debug")
43+
path = self.ton.tempDir + f'/collator_config.json'
44+
with open(path, 'w') as f:
45+
json.dump(config, f)
46+
result = self.ton.validatorConsole.Run(f"setcollatoroptionsjson {path}")
47+
return 'success' in result, result
48+
49+
def set_collator_config(self, args):
50+
if len(args) != 1:
51+
color_print("{red}Bad args. Usage:{endc} set_collator_config <path/url>")
52+
return
53+
location = args[0]
54+
config = self.get_config(location)
55+
self.ton.set_collator_config(location)
56+
added, msg = self.add_collator_config_to_vc(config)
57+
if not added:
58+
print(f'Failed to add collator config to validator console: {msg}')
59+
color_print("set_collator_config - {red}ERROR{endc}")
60+
return
61+
color_print("set_collator_config - {green}OK{endc}")
62+
63+
def get_collator_config(self, args):
64+
location = self.ton.get_collator_config_location()
65+
print(f'Collator config location: {location}')
66+
path = self.ton.tempDir + f'/current_collator_config.json'
67+
output = self.ton.validatorConsole.Run(f'getcollatoroptionsjson {path}')
68+
if 'saved config to' not in output:
69+
print(f'Failed to get collator config: {output}')
70+
color_print("get_collator_config - {red}ERROR{endc}")
71+
return
72+
with open(path, 'r') as f:
73+
config = json.load(f)
74+
print(f'Collator config:')
75+
print(json.dumps(config, indent=4))
76+
color_print("get_collator_config - {green}OK{endc}")
77+
78+
def update_collator_config(self, args):
79+
location = self.ton.get_collator_config_location()
80+
config = self.get_config(location)
81+
added, msg = self.add_collator_config_to_vc(config)
82+
if not added:
83+
print(f'Failed to add collator config to validator console: {msg}')
84+
color_print("update_collator_config - {red}ERROR{endc}")
85+
return
86+
color_print("update_collator_config - {green}OK{endc}")
87+
88+
def add_console_commands(self, console):
89+
console.AddItem("set_collator_config", self.set_collator_config, self.local.translate("set_collator_config_cmd"))
90+
console.AddItem("update_collator_config", self.update_collator_config, self.local.translate("update_collator_config_cmd"))
91+
console.AddItem("get_collator_config", self.get_collator_config, self.local.translate("get_collator_config_cmd"))

modules/nominator_pool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def do_activate_pool(self, pool, ex=True):
6262
elif account.status == "active":
6363
self.local.add_log("do_activate_pool warning: account status is active", "warning")
6464
else:
65+
validator_wallet = self.ton.GetValidatorWallet()
66+
self.ton.check_account_active(validator_wallet.addrB64)
6567
self.ton.SendFile(pool.bocFilePath, pool, timeout=False, remove=False)
6668
#end define
6769

modules/single_pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def do_activate_single_pool(self, pool):
5151
self.local.add_log("start activate_single_pool function", "debug")
5252
boc_mode = "--with-init"
5353
validator_wallet = self.ton.GetValidatorWallet()
54+
self.ton.check_account_active(validator_wallet.addrB64)
5455
result_file_path = self.ton.SignBocWithWallet(validator_wallet, pool.bocFilePath, pool.addrB64_init, 1, boc_mode=boc_mode)
5556
self.ton.SendFile(result_file_path, validator_wallet)
5657

mytoncore/mytoncore.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,7 @@ def SignBocWithWallet(self, wallet, boc_path, dest, coins, **kwargs):
11801180

11811181
# Balance checking
11821182
account = self.GetAccount(wallet.addrB64)
1183-
if account.balance < coins + 0.1:
1184-
raise Exception("Wallet balance is less than requested coins")
1185-
#end if
1183+
self.check_account_balance(account, coins + 0.1)
11861184

11871185
# Bounceable checking
11881186
destAccount = self.GetAccount(dest)
@@ -1864,6 +1862,25 @@ def GetWalletId(self, wallet):
18641862
return subwallet
18651863
#end define
18661864

1865+
def check_account_balance(self, account, coins):
1866+
if not isinstance(account, Account):
1867+
account = self.GetAccount(account)
1868+
if account.balance < coins:
1869+
raise Exception(f"Account {account.addrB64} balance is less than requested coins. Balance: {account.balance}, requested amount: {coins} (need {coins - account.balance} more)")
1870+
# end if
1871+
# end define
1872+
1873+
def check_account_active(self, account):
1874+
if not isinstance(account, Account):
1875+
address = account
1876+
account = self.GetAccount(account)
1877+
else:
1878+
address = account.addrB64
1879+
if account.status != "active":
1880+
raise Exception(f"Account {address} account is uninitialized")
1881+
# end if
1882+
# end define
1883+
18671884
def MoveCoins(self, wallet, dest, coins, **kwargs):
18681885
self.local.add_log("start MoveCoins function", "debug")
18691886
flags = kwargs.get("flags", list())
@@ -1884,11 +1901,8 @@ def MoveCoins(self, wallet, dest, coins, **kwargs):
18841901

18851902
# Balance checking
18861903
account = self.GetAccount(wallet.addrB64)
1887-
if account.balance < coins + 0.1:
1888-
raise Exception("Wallet balance is less than requested coins")
1889-
if account.status != "active":
1890-
raise Exception("Wallet account is uninitialized")
1891-
#end if
1904+
self.check_account_balance(account, coins + 0.1)
1905+
self.check_account_active(account)
18921906

18931907
# Bounceable checking
18941908
destAccount = self.GetAccount(dest)
@@ -3986,6 +4000,16 @@ def delete_custom_overlay(self, name: str):
39864000
del self.local.db['custom_overlays'][name]
39874001
self.local.save()
39884002

4003+
def set_collator_config(self, location: str):
4004+
self.local.db['collator_config'] = location
4005+
self.local.save()
4006+
4007+
def get_collator_config_location(self):
4008+
default = 'https://raw.githubusercontent.com/ton-blockchain/ton-blockchain.github.io/main/default_collator_options.json'
4009+
location = self.local.db.get('collator_config', default)
4010+
if location is None:
4011+
location = default
4012+
return location
39894013

39904014
def GetNetworkName(self):
39914015
data = self.local.read_db(self.liteClient.configPath)

mytonctrl/mytonctrl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def inject_globals(func):
128128
module = CustomOverlayModule(ton, local)
129129
module.add_console_commands(console)
130130

131+
from modules.collator_config import CollatorConfigModule
132+
module = CollatorConfigModule(ton, local)
133+
module.add_console_commands(console)
134+
131135
if ton.using_validator():
132136
from modules.validator import ValidatorModule
133137
module = ValidatorModule(ton, local)
@@ -384,7 +388,7 @@ def Upgrade(ton, args):
384388
try:
385389
from mytoninstaller.mytoninstaller import set_node_argument, get_node_args
386390
node_args = get_node_args()
387-
if node_args['--state-ttl'] == '604800':
391+
if node_args.get('--state-ttl') == '604800':
388392
set_node_argument(ton.local, ["--state-ttl", "-d"])
389393
except Exception as e:
390394
color_print(f"{{red}}Failed to set node argument: {e} {{endc}}")

mytonctrl/resources/translate.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@
419419
"ru": "{green}Доступно обновление MyTonCtrl. {red}Пожалуйста, обновите его с помощью команды `update`.{endc}",
420420
"zh_TW": "{green}MyTonCtrl 有可用更新. {red}請使用 `update` 命令進行更新.{endc}"
421421
},
422+
"update_mtc2_warning": {
423+
"en": "{red}This version is outdated. Please update to the second version: `update mytonctrl2`{endc}",
424+
"ru": "{red}Данная версия устарела. Пожалуйста обновитесь на вторую версию: `update mytonctrl2`{endc}",
425+
"zh_TW": "{red}這個版本已經過時了。請更新至第二版本: `update mytonctrl2`{endc}"
426+
},
427+
"disk_usage_warning": {
428+
"en": "{red} Disk is almost full, clean the TON database immediately: https://docs.ton.org/participate/nodes/node-maintenance-and-security#database-grooming {endc}",
429+
"ru": "{red} Диск почти заполнен, немедленно очистите базу данных TON: https://docs.ton.org/participate/nodes/node-maintenance-and-security#database-grooming {endc}",
430+
"zh_TW": "{red} 磁盤幾乎滿了,立即清理 TON 數據庫: https://docs.ton.org/participate/nodes/node-maintenance-and-security#database-grooming {endc}"
431+
},
422432
"ton_update_available": {
423433
"en": "{green}TON update available. {red}Please update it with `upgrade` command.{endc}",
424434
"ru": "{green}Доступно обновление TON. {red}Пожалуйста, обновите его с помощью команды `upgrade`.{endc}",

0 commit comments

Comments
 (0)