Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 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
27 changes: 27 additions & 0 deletions modules/liteserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import psutil

from modules.module import MtcModule


class LiteserverModule(MtcModule):

description = 'For liteserver usage only - can\'t be used with validator.'
default_value = False

def enable(self):
from mytoninstaller.mytoninstaller import set_node_argument
set_node_argument(self.local, ["--celldb-no-preload-all"])
data = psutil.virtual_memory()
ram = data.total / 2**30
if ram < 100:
set_node_argument(self.local, ["--celldb-cache-size", "1073741824"])

def disable(self):
from mytoninstaller.mytoninstaller import set_node_argument
from mytoninstaller.node_args import get_node_args
set_node_argument(self.local, ["--celldb-no-preload-all", "-d"])
if get_node_args()['--celldb-cache-size']:
set_node_argument(self.local, ["--celldb-cache-size", "-d"])

def add_console_commands(self, console):
...
9 changes: 9 additions & 0 deletions mytoncore/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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 +92,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
17 changes: 17 additions & 0 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3261,9 +3261,21 @@ 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.')
MODES['liteserver'](self, self.local).enable()
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 All @@ -3272,6 +3284,8 @@ def disable_mode(self, name):
current_modes = self.get_modes()
if name not in current_modes:
raise Exception(f'Unknown module name: {name}. Available modes: {", ".join(MODES)}')
if name == 'liteserver':
MODES['liteserver'](self, self.local).disable()
current_modes[name] = False
self.local.save()

Expand All @@ -3296,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
2 changes: 1 addition & 1 deletion mytonctrl/mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def inject_globals(func):
module = NominatorPoolModule(ton, local)
module.add_console_commands(console)

if ton.get_mode_value('single-nominator'):
if ton.using_single_nominator():
from modules.single_pool import SingleNominatorModule
module = SingleNominatorModule(ton, local)
module.add_console_commands(console)
Expand Down
8 changes: 7 additions & 1 deletion mytoninstaller/mytoninstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
CreateSymlinks,
enable_ls_proxy,
enable_ton_storage,
enable_ton_storage_provider
enable_ton_storage_provider,
EnableMode
)
from mytoninstaller.config import (
CreateLocalConfig,
Expand Down Expand Up @@ -255,6 +256,10 @@ def General(local):
mx = sys.argv.index("--dump")
dump = sys.argv[mx+1]
local.buffer.dump = str2bool(dump)
if "-m" in sys.argv:
mx = sys.argv.index("-m")
mode = sys.argv[mx+1]
local.buffer.mode = mode
#end if

FirstMytoncoreSettings(local)
Expand All @@ -264,6 +269,7 @@ def General(local):
BackupVconfig(local)
BackupMconfig(local)
CreateSymlinks(local)
EnableMode(local)
#end define


Expand Down
6 changes: 6 additions & 0 deletions mytoninstaller/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,9 @@ def CreateSymlinks(local):
file.write(fiftpath + '\n')
file.close()
#end define


def EnableMode(local):
if local.buffer.mode == 'liteserver':
args = ["python3", "-m", "mytoncore", "-e", "enable_liteserver_mode"]
subprocess.run(args)
20 changes: 12 additions & 8 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ fi
author="ton-blockchain"
repo="mytonctrl"
branch="master"
mode="validator"

show_help_and_exit() {
echo 'Supported argumets:'
echo ' -c PATH Provide custom config for toninstaller.sh'
echo ' -t Disable telemetry'
echo ' -i Ignore minimum reqiurements'
echo ' -d Use pre-packaged dump. Reduces duration of initial synchronization.'
echo ' -a Set MyTonCtrl git repo author'
echo 'Supported argumets:'
echo ' -c PATH Provide custom config for toninstaller.sh'
echo ' -t Disable telemetry'
echo ' -i Ignore minimum reqiurements'
echo ' -d Use pre-packaged dump. Reduces duration of initial synchronization.'
echo ' -a Set MyTonCtrl git repo author'
echo ' -r Set MyTonCtrl git repo'
echo ' -b Set MyTonCtrl git repo branch'
echo ' -m MODE Install MyTonCtrl with specified mode (validator or liteserver)'
echo ' -h Show this help'
exit
}
Expand All @@ -40,7 +42,8 @@ ignore=false
dump=false


while getopts c:tida:r:b: flag

while getopts c:tida:r:b:m: flag
do
case "${flag}" in
c) config=${OPTARG};;
Expand All @@ -50,6 +53,7 @@ do
a) author=${OPTARG};;
r) repo=${OPTARG};;
b) branch=${OPTARG};;
m) mode=${OPTARG};;
h) show_help_and_exit;;
*)
echo "Flag -${flag} is not recognized. Aborting"
Expand Down Expand Up @@ -115,7 +119,7 @@ if [ "$parent_name" = "sudo" ] || [ "$parent_name" = "su" ]; then
user=$(logname)
fi
echo "User: $user"
python3 -m mytoninstaller -u ${user} -t ${telemetry} --dump ${dump}
python3 -m mytoninstaller -u ${user} -t ${telemetry} --dump ${dump} -m ${mode}

# set migrate version
migrate_version=1
Expand Down