Skip to content

Commit d6a53b0

Browse files
authored
Merge branch 'modes' into mytonctrl2_dev
2 parents 0567b57 + e79e687 commit d6a53b0

File tree

11 files changed

+152
-18
lines changed

11 files changed

+152
-18
lines changed

modules/__init__.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import typing
2+
from dataclasses import dataclass
3+
4+
from modules.module import MtcModule
5+
from modules.pool import PoolModule
6+
from modules.nominator_pool import NominatorPoolModule
7+
from modules.single_pool import SingleNominatorModule
8+
from modules.validator import ValidatorModule
9+
from modules.controller import ControllerModule
10+
11+
12+
MODES = {
13+
'validator': ValidatorModule,
14+
'nominator-pool': NominatorPoolModule,
15+
'single-nominator': SingleNominatorModule,
16+
'liquid-staking': ControllerModule,
17+
}
18+
19+
20+
def get_mode(mode_name: str) -> typing.Optional[MtcModule]:
21+
return MODES.get(mode_name)
22+
23+
24+
@dataclass
25+
class Setting:
26+
mode: typing.Optional[str]
27+
default_value: typing.Any
28+
description: str
29+
30+
31+
SETTINGS = {
32+
'stake': Setting('validator', None, 'Stake amount'),
33+
'stakePercent': Setting('validator', 99, 'Stake percent if `stake` is null'),
34+
'isSlashing': Setting('validator', None, 'Create complaints to validators'),
35+
'maxFactor': Setting('validator', None, 'Param send to Elector. if null will be taken from 17 config param'),
36+
'participateBeforeEnd': Setting('validator', None, 'Amount of seconds before start of round to participate'),
37+
'liquid_pool_addr': Setting('liquid-staking', None, 'Liquid staking pool address'),
38+
'min_loan': Setting('liquid-staking', 41000, 'Min loan amount'),
39+
'max_loan': Setting('liquid-staking', 43000, 'Max loan amount'),
40+
'max_interest_percent': Setting('liquid-staking', 10, 'Max interest percent'),
41+
'duplicateSendfile': Setting(None, True, 'Duplicate external to public Liteservers'),
42+
'sendTelemetry': Setting(None, True, 'Send node telemetry'),
43+
'telemetryLiteUrl': Setting(None, 'https://telemetry.toncenter.com/report_status', 'Telemetry url'),
44+
'overlayTelemetryUrl': Setting(None, 'https://telemetry.toncenter.com/report_overlays', 'Overlay telemetry url'),
45+
'duplicateApi': Setting(None, 'sendTelemetry', 'Duplicate external to Toncenter'),
46+
'duplicateApiUrl': Setting(None, 'https://[testnet.]toncenter.com/api/v2/sendBoc', 'Toncenter api url for duplicate'),
47+
'liteclient_timeout': Setting(None, 3, 'Liteclient default timeout'),
48+
'console_timeout': Setting(None, 3, 'Validator console default timeout'),
49+
'fift_timeout': Setting(None, 3, 'Fift default timeout'),
50+
'useDefaultCustomOverlays': Setting(None, True, 'Participate in default custom overlays node eligible to'),
51+
'defaultCustomOverlaysUrl': Setting(None, 'https://ton-blockchain.github.io/fallback_custom_overlays.json', 'Default custom overlays config url'),
52+
}
53+
54+
55+
def get_setting(name: str) -> typing.Optional[Setting]:
56+
return SETTINGS.get(name)
57+
58+
59+
def get_mode_settings(name: str):
60+
return {k: v for k, v in SETTINGS.items() if v.mode == name}
61+

modules/controller.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
class ControllerModule(MtcModule):
1212

13+
description = 'Liquid staking controllers.'
14+
default_value = False
15+
1316
def do_create_controllers(self):
1417
new_controllers = self.ton.GetControllers()
1518
old_controllers = self.ton.local.db.get("using_controllers", list())

modules/module.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from abc import ABC, abstractmethod
2-
from mytoncore.mytoncore import MyTonCore
32

43

54
class MtcModule(ABC):
65

6+
description = '' # module text description
7+
default_value = True # is module enabled by default
8+
79
def __init__(self, ton, local, *args, **kwargs):
10+
from mytoncore.mytoncore import MyTonCore
811
self.ton: MyTonCore = ton
912
self.local = local
1013

modules/nominator_pool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class NominatorPoolModule(PoolModule):
99

10+
description = 'Standard nominator pools.'
11+
default_value = False
12+
1013
def do_create_pool(self, pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake,
1114
min_nominator_stake):
1215
self.ton.local.add_log("start CreatePool function", "debug")

modules/pool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class PoolModule(MtcModule):
88

9+
description = 'Basic pools functions.'
10+
default_value = False
11+
912
def print_pools_list(self, args):
1013
table = list()
1114
table += [["Name", "Status", "Balance", "Version", "Address"]]

modules/single_pool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
class SingleNominatorModule(PoolModule):
1010

11+
description = 'Orbs\'s single nominator pools.'
12+
default_value = False
13+
1114
def do_create_single_pool(self, pool_name, owner_address):
1215
self.ton.local.add_log("start create_single_pool function", "debug")
1316

modules/validator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from mypylib.mypylib import color_print
22
from modules.module import MtcModule
33

4-
from mytoncore.functions import Elections
5-
64

75
class ValidatorModule(MtcModule):
86

7+
description = ('Validator functions. Activates participating in elections and staking. '
8+
'If pools and l/s modes are disabled stakes from validator wallet.')
9+
10+
default_value = True
11+
912
def vote_offer(self, args):
1013
if len(args) == 0:
1114
color_print("{red}Bad args. Usage:{endc} vo <offer-hash>")
@@ -15,6 +18,7 @@ def vote_offer(self, args):
1518
color_print("VoteOffer - {green}OK{endc}")
1619

1720
def vote_election_entry(self, args):
21+
from mytoncore.functions import Elections
1822
Elections(self.ton.local, self.ton)
1923
color_print("VoteElectionEntry - {green}OK{endc}")
2024

mytoncore/modes.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

mytoncore/mytoncore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import requests
1212
from fastcrc import crc16
1313

14-
from mytoncore.modes import MODES
14+
from modules import MODES
1515
from mytoncore.utils import xhex2hex, ng2g
1616
from mytoncore.liteclient import LiteClient
1717
from mytoncore.validator_console import ValidatorConsole
@@ -3209,9 +3209,9 @@ def get_modes(self):
32093209
if 'modes' not in self.local.db:
32103210
self.local.db['modes'] = current_modes
32113211
self.migrate_to_modes()
3212-
for mode in MODES:
3213-
if mode not in current_modes:
3214-
current_modes[mode] = MODES[mode] # assign default mode value
3212+
for name, mode in MODES.items():
3213+
if name not in current_modes:
3214+
current_modes[name] = mode.default_value # assign default mode value
32153215
return current_modes
32163216

32173217
def enable_mode(self, name):

mytonctrl/mytonctrl.py

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ def inject_globals(func):
7070
console.AddItem("installer", inject_globals(Installer), local.translate("installer_cmd"))
7171
console.AddItem("status", inject_globals(PrintStatus), local.translate("status_cmd"))
7272
console.AddItem("status_modes", inject_globals(mode_status), local.translate("status_modes_cmd"))
73+
console.AddItem("status_settings", inject_globals(settings_status), local.translate("settings_status_cmd"))
7374
console.AddItem("enable_mode", inject_globals(enable_mode), local.translate("enable_mode_cmd"))
7475
console.AddItem("disable_mode", inject_globals(disable_mode), local.translate("disable_mode_cmd"))
76+
console.AddItem("about", inject_globals(about), local.translate("about_cmd"))
7577
console.AddItem("get", inject_globals(GetSettings), local.translate("get_cmd"))
7678
console.AddItem("set", inject_globals(SetSettings), local.translate("set_cmd"))
7779
console.AddItem("rollback", inject_globals(rollback_to_mtc1), local.translate("rollback_cmd"))
@@ -184,6 +186,7 @@ def inject_globals(func):
184186
#end define
185187

186188

189+
187190
def activate_ton_storage_provider(local, ton, args):
188191
wallet_name = "provider_wallet_001"
189192
wallet = ton.GetLocalWallet(wallet_name)
@@ -201,6 +204,25 @@ def activate_ton_storage_provider(local, ton, args):
201204
#end define
202205

203206

207+
def about(local, ton, args):
208+
from modules import get_mode, get_mode_settings
209+
if len(args) != 1:
210+
color_print("{red}Bad args. Usage:{endc} about <mode_name>")
211+
mode_name = args[0]
212+
mode = get_mode(mode_name)
213+
if mode is None:
214+
color_print(f"{{red}}Mode {mode_name} not found{{endc}}")
215+
return
216+
mode_settings = get_mode_settings(mode_name)
217+
color_print(f'''{{cyan}}===[ {mode_name} MODE ]==={{endc}}''')
218+
color_print(f'''Description: {mode.description}''')
219+
color_print('Enabled: ' + color_text('{green}yes{endc}' if ton.get_mode_value(mode_name) else '{red}no{endc}'))
220+
print('Settings:', 'no' if len(mode_settings) == 0 else '')
221+
for setting_name, setting in mode_settings.items():
222+
color_print(f' {{bold}}{setting_name}{{endc}}: {setting.description}.\n Default value: {setting.default_value}')
223+
#end define
224+
225+
204226
def check_installer_user():
205227
args = ["whoami"]
206228
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
@@ -447,13 +469,28 @@ def sl(ton, args):
447469
Slashing(ton.local, ton)
448470
#end define
449471

472+
450473
def mode_status(ton, args):
474+
from modules import get_mode
451475
modes = ton.get_modes()
452-
text = "########## {bold}Modes{endc} ########## \n"
453-
for mode in modes:
454-
status = '{green}enabled{endc}' if modes[mode] else '{red}disabled{endc}'
455-
text += f"{mode}: {status}\n"
456-
color_print(text)
476+
table = [["Name", "Status", "Description"]]
477+
for mode_name in modes:
478+
mode = get_mode(mode_name)
479+
status = color_text('{green}enabled{endc}' if modes[mode_name] else '{red}disabled{endc}')
480+
table.append([mode_name, status, mode.description])
481+
print_table(table)
482+
#end define
483+
484+
485+
def settings_status(ton, args):
486+
from modules import SETTINGS
487+
table = [["Name", "Description", "Mode", "Default value", "Current value"]]
488+
for name, setting in SETTINGS.items():
489+
current_value = ton.local.db.get(name)
490+
table.append([name, setting.description, setting.mode, setting.default_value, current_value])
491+
print_table(table)
492+
#end define
493+
457494

458495
def PrintStatus(local, ton, args):
459496
opt = None
@@ -1289,6 +1326,19 @@ def SetSettings(ton, args):
12891326
color_print(f"{{red}} Error: set {name} ... is deprecated and does not work {{endc}}."
12901327
f"\nInstead, use {{bold}}enable_mode {mode_name}{{endc}}")
12911328
return
1329+
force = False
1330+
if len(args) > 2:
1331+
if args[2] == "--force":
1332+
force = True
1333+
from modules import get_setting
1334+
setting = get_setting(name)
1335+
if setting is None and not force:
1336+
color_print(f"{{red}} Error: setting {name} not found.{{endc}} Use flag --force to set it anyway")
1337+
return
1338+
if setting is not None and setting.mode is not None:
1339+
if not ton.get_mode_value(setting.mode) and not force:
1340+
color_print(f"{{red}} Error: mode {setting.mode} is disabled.{{endc}} Use flag --force to set it anyway")
1341+
return
12921342
ton.SetSettings(name, value)
12931343
color_print("SetSettings - {green}OK{endc}")
12941344
#end define

0 commit comments

Comments
 (0)