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
70 changes: 70 additions & 0 deletions custom_overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def add_custom_overlay(args):
with open(path, 'r') as f:
config = json.load(f)
ton.set_custom_overlay(args[0], config)
if '@validators' in config:
print('Dynamic overlay will be added within 1 minute')
else:
result = add_custom_overlay_to_vc(ton, parse_config(args[0], config))
if not result:
print('Failed to add overlay to validator console')
color_print("add_custom_overlay - {red}ERROR{endc}")
return
color_print("add_custom_overlay - {green}OK{endc}")


Expand All @@ -70,6 +78,14 @@ def delete_custom_overlay(args):
color_print("{red}Bad args. Usage:{endc} delete_custom_overlay <name>")
return
ton.delete_custom_overlay(args[0])
if '@validators' in ton.get_custom_overlays().get(args[0], {}):
print('Dynamic overlay will be deleted within 1 minute')
else:
result = delete_custom_overlay_from_vc(ton, args[0])
if not result:
print('Failed to delete overlay from validator console')
color_print("delete_custom_overlay - {red}ERROR{endc}")
return
color_print("delete_custom_overlay - {green}OK{endc}")


Expand All @@ -86,6 +102,13 @@ def add_custom_overlay_to_vc(ton, config: dict):
return 'success' in result


def custom_overlays(local, ton):
config = get_default_custom_overlay(local, ton)
if config is not None:
ton.set_custom_overlay('default', config)
deploy_custom_overlays(local, ton)


def deploy_custom_overlays(local, ton):
result = ton.validatorConsole.Run("showcustomoverlays")
if 'unknown command' in result:
Expand Down Expand Up @@ -139,3 +162,50 @@ def deploy_custom_overlays(local, ton):
node_config = parse_config(name, config)
local.add_log(f"Adding custom overlay {name}", "debug")
add_custom_overlay_to_vc(ton, node_config)


MAINNET_DEFAULT_CUSTOM_OVERLAY = {
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA": {
"msg_sender": True,
"msg_sender_priority": 15
},
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB": {
"msg_sender": True,
"msg_sender_priority": 10
},
"@validators": True
}


TESTNET_DEFAULT_CUSTOM_OVERLAY = {
"DF27B30444D07087863B77F8BD27BABA8E57EDECA393605F6610FDCB64FFECD1": {
"msg_sender": True,
"msg_sender_priority": 15
},
"B360D229CA597906ADFC522FAC3EB5F8AE9D80981693225E7083577A4F016118": {
"msg_sender": True,
"msg_sender_priority": 10
},
"F794DE0B21423B6F4C168C5652758E5743CD977ACE13B3B2BA88E28580D9BEDB": {
"msg_sender": True,
"msg_sender_priority": 10
},
"6447CEAC80573AF2ABCA741FC940BB690AC263DC4B779FB6609CE5E9A4B31AE1": {
"msg_sender": True,
"msg_sender_priority": 5,
},
"@validators": True
}


def get_default_custom_overlay(local, ton):
if not local.db.get('useDefaultCustomOverlays', True):
return None
network = ton.GetNetworkName()
if network == 'mainnet':
config = MAINNET_DEFAULT_CUSTOM_OVERLAY
elif network == 'testnet':
config = TESTNET_DEFAULT_CUSTOM_OVERLAY
else:
return None
return config
4 changes: 2 additions & 2 deletions mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import requests
import re
from mypylib.mypylib import *
from custom_overlays import deploy_custom_overlays
from custom_overlays import custom_overlays

local = MyPyClass(__file__)

Expand Down Expand Up @@ -4312,7 +4312,7 @@ def General():
local.start_cycle(Telemetry, sec=60, args=(ton, ))
local.start_cycle(OverlayTelemetry, sec=7200, args=(ton, ))
local.start_cycle(ScanLiteServers, sec=60, args=(ton,))
local.start_cycle(deploy_custom_overlays, sec=60, args=(local, ton,))
local.start_cycle(custom_overlays, sec=60, args=(local, ton,))
thr_sleep()
#end define

Expand Down
14 changes: 14 additions & 0 deletions mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def Init(argv):
console.AddItem("add_custom_overlay", add_custom_overlay, local.translate("add_custom_overlay_cmd"))
console.AddItem("list_custom_overlays", list_custom_overlays, local.translate("list_custom_overlays_cmd"))
console.AddItem("delete_custom_overlay", delete_custom_overlay, local.translate("delete_custom_overlay_cmd"))
console.AddItem("set_archive_ttl", set_archive_ttl, local.translate("set_archive_ttl_cmd"))

console.AddItem("nw", CreatNewWallet, local.translate("nw_cmd"))
console.AddItem("aw", ActivateWallet, local.translate("aw_cmd"))
Expand Down Expand Up @@ -1213,6 +1214,19 @@ def UpdateValidatorSet(args):
#end define


def set_archive_ttl(args):
if len(args) != 1:
color_print("{red}Bad args. Usage:{endc} set_archive_ttl <ttl>")
return
ttl = args[0]
result = run_as_root(['python3', '/usr/src/mytonctrl/scripts/set_archive_ttl.py', ttl])
if result:
color_print("set_archive_ttl - {red}Error{endc}")
return
color_print("set_archive_ttl - {green}OK{endc}")
#end define


###
### Start of the program
###
Expand Down
37 changes: 37 additions & 0 deletions scripts/set_archive_ttl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import subprocess
import sys

with open('/etc/systemd/system/validator.service', 'r') as file:
service = file.read()


for line in service.split('\n'):
if line.startswith('ExecStart'):
exec_start = line
break


if '--archive-ttl' in exec_start:
print('Archive TTL is already set')
sys.exit(100)

default_command = 'ExecStart = /usr/bin/ton/validator-engine/validator-engine --threads --daemonize --global-config /usr/bin/ton/global.config.json --db /var/ton-work/db/ --logname /var/ton-work/log --state-ttl 604800 --verbosity 1'

# ExecStart = /usr/bin/ton/validator-engine/validator-engine --threads 31 --daemonize --global-config /usr/bin/ton/global.config.json --db /var/ton-work/db/ --logname /var/ton-work/log --state-ttl 604800 --verbosity 1

t = exec_start.split(' ')
t.pop(t.index('--threads') + 1) # pop threads value since it's different for each node

if ' '.join(t) != default_command:
print('ExecStart is not default. Please set archive-ttl manually in `/etc/systemd/system/validator.service`.')
sys.exit(101)

archive_ttl = sys.argv[1]

new_exec_start = exec_start + f' --archive-ttl {archive_ttl}'

with open('/etc/systemd/system/validator.service', 'w') as file:
file.write(service.replace(exec_start, new_exec_start))

subprocess.run(['systemctl', 'daemon-reload'])
subprocess.run(['systemctl', 'restart', 'validator'])