Skip to content

Commit cdd64e4

Browse files
authored
Merge pull request #956 from skalenetwork/update-settings-structure
New settings structure, migrate to toml configs
2 parents 9741c4e + a31d653 commit cdd64e4

45 files changed

Lines changed: 922 additions & 1279 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
- no redundant code - move repeated logic into helper functions
1212
- use type hints to specify the expected types of function arguments and return values
1313

14-
- check `ruff.toml` for formatting rules
15-
- always lint changes using `ruff check`
14+
- check `pyproject.toml` for formatting rules
15+
- always lint changes using `uv run ruff check`
1616
- tests should be placed in `tests/` directory, follow the existing structure and code style
17-
- to run a test always use `bash scripts/run_tests.sh tests/path_to_test.py -k [TEST_NAME]` command
17+
- always use `uv` to run all commands in the repo (e.g., `uv run ruff`, `uv run pytest`, etc.)
18+
- for running tests, export environment variables in the terminal before running the tests: `. ./scripts/export_env.sh`
19+
20+
- additional external context is located in context directory

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,4 @@ tests/.skale/node_data/node_options.json
125125
tests/.skale/config/nginx.conf.j2
126126

127127
.zed
128+
uv.lock

node_cli/cli/fair_boot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ def signature_boot(validator_id):
8888
@streamed_cmd
8989
def update_node(env_file, pull_config_for_schain):
9090
update(
91-
env_filepath=env_file,
91+
config_file=env_file,
9292
pull_config_for_schain=pull_config_for_schain,
9393
)

node_cli/cli/fair_node.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def fair_node_info(format):
5757

5858

5959
@node.command('init', help='Initialize regular Fair node')
60-
@click.argument('env_filepath')
60+
@click.argument('config_file')
6161
@streamed_cmd
62-
def init_node(env_filepath: str):
63-
init_fair(node_mode=NodeMode.ACTIVE, env_filepath=env_filepath)
62+
def init_node(config_file: str):
63+
init_fair(node_mode=NodeMode.ACTIVE, config_file=config_file)
6464

6565

6666
@node.command('register', help=TEXTS['fair']['node']['register']['help'])
@@ -70,7 +70,7 @@ def register(ip: str) -> None:
7070

7171

7272
@node.command('update', help='Update Fair node')
73-
@click.argument('env_filepath')
73+
@click.argument('config_file')
7474
@click.option(
7575
'--yes',
7676
is_flag=True,
@@ -88,10 +88,10 @@ def register(ip: str) -> None:
8888
is_flag=True,
8989
)
9090
@streamed_cmd
91-
def update_node(env_filepath: str, pull_config_for_schain, force_skaled_start: bool):
91+
def update_node(config_file: str, pull_config_for_schain, force_skaled_start: bool):
9292
update_fair(
9393
node_mode=NodeMode.ACTIVE,
94-
env_filepath=env_filepath,
94+
config_file=config_file,
9595
pull_config_for_schain=pull_config_for_schain,
9696
force_skaled_start=force_skaled_start,
9797
)
@@ -106,20 +106,20 @@ def backup_node(backup_folder_path):
106106

107107
@node.command('restore', help='Restore Fair node from a backup file.')
108108
@click.argument('backup_path')
109-
@click.argument('env_file')
109+
@click.argument('config_file')
110110
@click.option(
111111
'--config-only',
112112
help='Only restore configuration files in .skale and artifacts',
113113
is_flag=True,
114114
hidden=True,
115115
)
116116
@streamed_cmd
117-
def restore_node(backup_path, env_file, config_only):
118-
restore_fair(backup_path, env_file, config_only)
117+
def restore_node(backup_path, config_file, config_only):
118+
restore_fair(backup_path, config_file, config_only)
119119

120120

121121
@node.command('migrate', help='Switch from boot to regular Fair node.')
122-
@click.argument('env_filepath')
122+
@click.argument('config_file')
123123
@click.option(
124124
'--yes',
125125
is_flag=True,
@@ -128,8 +128,8 @@ def restore_node(backup_path, env_file, config_only):
128128
prompt='Are you sure you want to migrate to regular Fair node? The action cannot be undone',
129129
)
130130
@streamed_cmd
131-
def migrate_node(env_filepath: str) -> None:
132-
migrate_from_boot(env_filepath=env_filepath)
131+
def migrate_node(config_file: str) -> None:
132+
migrate_from_boot(config_file=config_file)
133133

134134

135135
@node.command('repair', help='Toggle fair chain repair mode')
@@ -221,7 +221,7 @@ def turn_off_node() -> None:
221221
expose_value=False,
222222
prompt='Are you sure you want to turn on the node?',
223223
)
224-
@click.argument('env_filepath')
224+
@click.argument('config_file')
225225
@streamed_cmd
226-
def turn_on_node(env_filepath: str) -> None:
227-
turn_on_fair(env_file=env_filepath, node_type=TYPE)
226+
def turn_on_node(config_file: str) -> None:
227+
turn_on_fair(env_file=config_file, node_type=TYPE)

node_cli/cli/node.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
# You should have received a copy of the GNU Affero General Public License
1818
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1919

20+
from typing import get_args
21+
2022
import click
2123

24+
from skale_core.types import EnvType
2225
from node_cli.cli.info import TYPE
2326
from node_cli.core.node import (
2427
cleanup as cleanup_skale,
@@ -38,7 +41,6 @@
3841
run_checks,
3942
)
4043
from node_cli.configs import DEFAULT_NODE_BASE_PORT
41-
from node_cli.configs.user import ALLOWED_ENV_TYPES
4244
from node_cli.core.node_options import upsert_node_mode
4345
from node_cli.utils.decorators import check_inited
4446
from node_cli.utils.helper import abort_if_false, streamed_cmd, IP_TYPE
@@ -85,10 +87,10 @@ def register_node(name, ip, port, domain):
8587

8688

8789
@node.command('init', help='Initialize SKALE node')
88-
@click.argument('env_file')
90+
@click.argument('config_file')
8991
@streamed_cmd
90-
def init_node(env_file):
91-
init(env_filepath=env_file, node_type=TYPE)
92+
def init_node(config_file):
93+
init(config_file=config_file, node_type=TYPE)
9294

9395

9496
@node.command('update', help='Update node from .env file')
@@ -101,12 +103,12 @@ def init_node(env_file):
101103
)
102104
@click.option('--pull-config', 'pull_config_for_schain', hidden=True, type=str)
103105
@click.option('--unsafe', 'unsafe_ok', help='Allow unsafe update', hidden=True, is_flag=True)
104-
@click.argument('env_file')
106+
@click.argument('config_file')
105107
@streamed_cmd
106-
def update_node(env_file, pull_config_for_schain, unsafe_ok):
108+
def update_node(config_file, pull_config_for_schain, unsafe_ok):
107109
update(
108110
node_mode=NodeMode.ACTIVE,
109-
env_filepath=env_file,
111+
config_file=config_file,
110112
pull_config_for_schain=pull_config_for_schain,
111113
node_type=TYPE,
112114
unsafe_ok=unsafe_ok,
@@ -143,7 +145,7 @@ def backup_node(backup_folder_path):
143145
def restore_node(backup_path, env_file, no_snapshot, config_only):
144146
restore(
145147
backup_path=backup_path,
146-
env_filepath=env_file,
148+
config_file=env_file,
147149
no_snapshot=no_snapshot,
148150
config_only=config_only,
149151
node_type=TYPE,
@@ -227,7 +229,7 @@ def _set_domain_name(domain):
227229
@click.option(
228230
'--network',
229231
'-n',
230-
type=click.Choice(ALLOWED_ENV_TYPES),
232+
type=click.Choice(get_args(EnvType)),
231233
default='mainnet',
232234
help='Network to check',
233235
)

node_cli/cli/passive_fair_node.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def passive_node():
4949

5050

5151
@passive_node.command('init', help='Initialize a passive Fair node')
52-
@click.argument('env_filepath')
52+
@click.argument('config_file')
5353
@click.option('--id', required=True, type=int, help=TEXTS['fair']['node']['setup']['id'])
5454
@click.option('--indexer', help=TEXTS['passive_node']['init']['indexer'], is_flag=True)
5555
@click.option('--archive', help=TEXTS['passive_node']['init']['archive'], is_flag=True)
@@ -61,15 +61,15 @@ def passive_node():
6161
)
6262
@streamed_cmd
6363
def init_passive_node(
64-
env_filepath: str, id: int, indexer: bool, archive: bool, snapshot: str | None
64+
config_file: str, id: int, indexer: bool, archive: bool, snapshot: str | None
6565
):
6666
if indexer and archive:
6767
error_exit('Cannot use both --indexer and --archive options')
6868
if (indexer or archive) and snapshot == 'any':
6969
error_exit('Cannot use any for indexer/archive node')
7070
init_fair(
7171
node_mode=NodeMode.PASSIVE,
72-
env_filepath=env_filepath,
72+
config_file=config_file,
7373
node_id=id,
7474
indexer=indexer,
7575
archive=archive,
@@ -78,7 +78,7 @@ def init_passive_node(
7878

7979

8080
@passive_node.command('update', help='Update Fair node')
81-
@click.argument('env_filepath')
81+
@click.argument('config_file')
8282
@click.option(
8383
'--yes',
8484
is_flag=True,
@@ -96,10 +96,10 @@ def init_passive_node(
9696
is_flag=True,
9797
)
9898
@streamed_cmd
99-
def update_node(env_filepath: str, pull_config_for_schain, force_skaled_start: bool):
99+
def update_node(config_file: str, pull_config_for_schain, force_skaled_start: bool):
100100
update_fair(
101101
node_mode=NodeMode.PASSIVE,
102-
env_filepath=env_filepath,
102+
config_file=config_file,
103103
pull_config_for_schain=pull_config_for_schain,
104104
force_skaled_start=force_skaled_start,
105105
)
@@ -146,7 +146,7 @@ def turn_off_node() -> None:
146146
expose_value=False,
147147
prompt='Are you sure you want to turn on the node?',
148148
)
149-
@click.argument('env_filepath')
149+
@click.argument('config_file')
150150
@streamed_cmd
151-
def turn_on_node(env_filepath: str) -> None:
152-
turn_on_fair(env_file=env_filepath, node_type=TYPE)
151+
def turn_on_node(config_file: str) -> None:
152+
turn_on_fair(env_file=config_file, node_type=TYPE)

node_cli/cli/schains.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import click
2323

24+
from skale_core.settings import get_settings
25+
2426
from node_cli.utils.helper import abort_if_false, URL_TYPE
2527
from node_cli.core.schains import (
2628
describe,
@@ -104,8 +106,12 @@ def info_(schain_name: str, json_format: bool) -> None:
104106
@click.argument('schain_name')
105107
@click.argument('snapshot_path')
106108
@click.option('--schain-type', default='medium')
107-
@click.option('--env-type', default=None)
108-
def restore(
109-
schain_name: str, snapshot_path: str, schain_type: str, env_type: Optional[str]
110-
) -> None:
111-
restore_schain_from_snapshot(schain_name, snapshot_path, node_type=TYPE)
109+
def restore(schain_name: str, snapshot_path: str, schain_type: str) -> None:
110+
settings = get_settings()
111+
restore_schain_from_snapshot(
112+
schain_name,
113+
snapshot_path,
114+
node_type=TYPE,
115+
env_type=settings.env_type,
116+
schain_type=schain_type,
117+
)

node_cli/configs/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import os
2121
import sys
22+
from pathlib import Path
2223

2324
from node_cli.utils.global_config import read_g_config
2425

@@ -43,17 +44,19 @@
4344
NODE_DATA_PATH = os.path.join(SKALE_DIR, 'node_data')
4445
SCHAIN_NODE_DATA_PATH = os.path.join(NODE_DATA_PATH, 'schains')
4546
NODE_CLI_STATUS_FILENAME = 'node_cli.status'
47+
48+
SETTINGS_DIR = Path(NODE_DATA_PATH) / 'settings'
49+
NODE_SETTINGS_PATH = SETTINGS_DIR / 'node.toml'
50+
INTERNAL_SETTINGS_PATH = SETTINGS_DIR / 'internal.toml'
51+
4652
NODE_CONFIG_PATH = os.path.join(NODE_DATA_PATH, 'node_config.json')
4753
CONTAINER_CONFIG_PATH = os.path.join(SKALE_DIR, 'config')
4854
CONTAINER_CONFIG_TMP_PATH = os.path.join(SKALE_TMP_DIR, 'config')
4955
CONTRACTS_PATH = os.path.join(SKALE_DIR, 'contracts_info')
5056
REPORTS_PATH = os.path.join(SKALE_DIR, 'reports')
5157
BACKUP_CONTRACTS_PATH = os.path.join(SKALE_DIR, '.old_contracts_info')
52-
INIT_ENV_FILEPATH = os.path.join(SKALE_DIR, '.env')
5358
SKALE_RUN_DIR = '/var/run/skale'
5459

55-
SGX_CERTIFICATES_DIR_NAME = 'sgx_certs'
56-
5760
COMPOSE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'docker-compose.yml')
5861
FAIR_COMPOSE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'docker-compose-fair.yml')
5962
STATIC_PARAMS_FILEPATH = os.path.join(CONTAINER_CONFIG_PATH, 'static_params.yaml')
@@ -73,9 +76,6 @@
7376
SGX_CERTS_PATH = os.path.join(NODE_DATA_PATH, 'sgx_certs')
7477
SCHAINS_DATA_PATH = os.path.join(NODE_DATA_PATH, 'schains')
7578

76-
CURRENT_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__))
77-
DOTENV_FILEPATH = os.path.join(os.path.dirname(CURRENT_FILE_LOCATION), '.env')
78-
7979
SRC_FILEBEAT_CONFIG_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'filebeat.yml')
8080
FILEBEAT_CONFIG_PATH = os.path.join(NODE_DATA_PATH, 'filebeat.yml')
8181

@@ -95,9 +95,6 @@
9595
IPTABLES_RULES_STATE_FILEPATH = os.path.join(IPTABLES_DIR, 'rules.v4')
9696
DEFAULT_SSH_PORT = 22
9797

98-
FLASK_SECRET_KEY_FILENAME = 'flask_db_key.txt'
99-
FLASK_SECRET_KEY_FILE = os.path.join(NODE_DATA_PATH, FLASK_SECRET_KEY_FILENAME)
100-
10198
DOCKER_CONFIG_FILEPATH = '/etc/docker/daemon.json'
10299
HIDE_STREAM_LOG = os.getenv('HIDE_STREAM_LOG')
103100

0 commit comments

Comments
 (0)