Skip to content

Commit 69971c0

Browse files
Merge pull request #848 from skalenetwork/beta
Beta 4.0 to stable
2 parents 9e28bc2 + 53658e2 commit 69971c0

14 files changed

Lines changed: 429 additions & 504 deletions

File tree

README.md

Lines changed: 115 additions & 103 deletions
Large diffs are not rendered by default.

node_cli/cli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '2.6.1'
1+
__version__ = '2.6.2'
22

3-
if __name__ == "__main__":
3+
if __name__ == '__main__':
44
print(__version__)

node_cli/cli/sync_node.py

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
import click
2323

24-
from node_cli.core.node import init_sync, update_sync, repair_sync
24+
from node_cli.core.node import init_sync, update_sync, cleanup_sync
2525
from node_cli.utils.helper import (
2626
abort_if_false,
2727
error_exit,
2828
safe_load_texts,
2929
streamed_cmd,
30-
URL_TYPE
30+
URL_TYPE,
3131
)
3232
from node_cli.utils.exit_codes import CLIExitCodes
3333

@@ -41,86 +41,54 @@ def sync_node_cli():
4141
pass
4242

4343

44-
@sync_node_cli.group(help="SKALE sync node commands")
44+
@sync_node_cli.group(help='SKALE sync node commands')
4545
def sync_node():
4646
pass
4747

4848

4949
@sync_node.command('init', help=TEXTS['init']['help'])
5050
@click.argument('env_file')
51+
@click.option('--indexer', help=TEXTS['init']['indexer'], is_flag=True)
52+
@click.option('--archive', help=TEXTS['init']['archive'], is_flag=True)
53+
@click.option('--snapshot', help=TEXTS['init']['snapshot'], is_flag=True)
5154
@click.option(
52-
'--archive',
53-
help=TEXTS['init']['archive'],
54-
is_flag=True
55-
)
56-
@click.option(
57-
'--historic-state',
58-
help=TEXTS['init']['historic_state'],
59-
is_flag=True
60-
)
61-
@click.option(
62-
'--snapshot-from',
63-
type=URL_TYPE,
64-
default=None,
65-
hidden=True,
66-
help='Ip of the node from to download snapshot from'
55+
'--snapshot-from', type=URL_TYPE, default=None, hidden=True, help=TEXTS['init']['snapshot_from']
6756
)
6857
@streamed_cmd
69-
def _init_sync(env_file, archive, historic_state, snapshot_from: Optional[str]):
70-
if historic_state and not archive:
58+
def _init_sync(
59+
env_file, indexer: bool, archive: bool, snapshot: bool, snapshot_from: Optional[str]
60+
) -> None:
61+
if indexer and archive:
7162
error_exit(
72-
'--historic-state can be used only is combination with --archive',
73-
exit_code=CLIExitCodes.FAILURE
63+
'Cannot use both --indexer and --archive options',
64+
exit_code=CLIExitCodes.FAILURE,
7465
)
75-
init_sync(env_file, archive, historic_state, snapshot_from)
66+
init_sync(env_file, indexer, archive, snapshot, snapshot_from)
7667

7768

7869
@sync_node.command('update', help='Update sync node from .env file')
79-
@click.option('--yes', is_flag=True, callback=abort_if_false,
80-
expose_value=False,
81-
prompt='Are you sure you want to update SKALE node software?')
8270
@click.option(
83-
'--unsafe',
84-
'unsafe_ok',
85-
help='Allow unsafe update',
86-
hidden=True,
87-
is_flag=True
71+
'--yes',
72+
is_flag=True,
73+
callback=abort_if_false,
74+
expose_value=False,
75+
prompt='Are you sure you want to update SKALE node software?',
8876
)
77+
@click.option('--unsafe', 'unsafe_ok', help='Allow unsafe update', hidden=True, is_flag=True)
8978
@click.argument('env_file')
9079
@streamed_cmd
9180
def _update_sync(env_file, unsafe_ok):
9281
update_sync(env_file)
9382

9483

95-
@sync_node.command('repair', help='Start sync node from empty database')
96-
@click.option('--yes', is_flag=True, callback=abort_if_false,
97-
expose_value=False,
98-
prompt='Are you sure you want to start sync node from empty database?')
84+
@sync_node.command('cleanup', help='Remove sync node data and containers')
9985
@click.option(
100-
'--archive',
101-
help=TEXTS['init']['archive'],
102-
is_flag=True
103-
)
104-
@click.option(
105-
'--historic-state',
106-
help=TEXTS['init']['historic_state'],
107-
is_flag=True
108-
)
109-
@click.option(
110-
'--snapshot-from',
111-
type=URL_TYPE,
112-
default=None,
113-
hidden=True,
114-
help='Ip of the node from to download snapshot from'
86+
'--yes',
87+
is_flag=True,
88+
callback=abort_if_false,
89+
expose_value=False,
90+
prompt='Are you sure you want to remove all node containers and data?',
11591
)
11692
@streamed_cmd
117-
def _repair_sync(
118-
archive: str,
119-
historic_state: str,
120-
snapshot_from: Optional[str] = None
121-
) -> None:
122-
repair_sync(
123-
archive=archive,
124-
historic_state=historic_state,
125-
snapshot_from=snapshot_from
126-
)
93+
def _cleanup_sync() -> None:
94+
cleanup_sync()

node_cli/core/node.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
turn_on_op,
5757
restore_op,
5858
init_sync_op,
59-
repair_sync_op,
6059
update_sync_op,
60+
cleanup_sync_op,
6161
)
6262
from node_cli.utils.print_formatters import (
6363
print_failed_requirements_checks,
@@ -176,11 +176,14 @@ def restore(backup_path, env_filepath, no_snapshot=False, config_only=False):
176176
print('Node is restored from backup')
177177

178178

179-
def init_sync(env_filepath: str, archive: bool, historic_state: bool, snapshot_from: str) -> None:
179+
@check_not_inited
180+
def init_sync(
181+
env_filepath: str, indexer: bool, archive: bool, snapshot: bool, snapshot_from: Optional[str]
182+
) -> None:
180183
env = compose_node_env(env_filepath, sync_node=True)
181184
if env is None:
182185
return
183-
inited_ok = init_sync_op(env_filepath, env, archive, historic_state, snapshot_from)
186+
inited_ok = init_sync_op(env_filepath, env, indexer, archive, snapshot, snapshot_from)
184187
if not inited_ok:
185188
error_exit('Init operation failed', exit_code=CLIExitCodes.OPERATION_EXECUTION_ERROR)
186189
logger.info('Waiting for containers initialization')
@@ -212,16 +215,11 @@ def update_sync(env_filepath: str, unsafe_ok: bool = False) -> None:
212215

213216
@check_inited
214217
@check_user
215-
def repair_sync(archive: bool, historic_state: bool, snapshot_from: str) -> None:
216-
env_params = extract_env_params(INIT_ENV_FILEPATH, sync_node=True)
217-
schain_name = env_params['SCHAIN_NAME']
218-
repair_sync_op(
219-
schain_name=schain_name,
220-
archive=archive,
221-
historic_state=historic_state,
222-
snapshot_from=snapshot_from,
223-
)
224-
logger.info('Schain was started from scratch')
218+
def cleanup_sync() -> None:
219+
env = compose_node_env(SKALE_DIR_ENV_FILEPATH, save=False, sync_node=True)
220+
schain_name = env['SCHAIN_NAME']
221+
cleanup_sync_op(env, schain_name)
222+
logger.info('Sync node was cleaned up, all containers and data removed')
225223

226224

227225
def compose_node_env(
@@ -230,7 +228,7 @@ def compose_node_env(
230228
sync_schains=None,
231229
pull_config_for_schain=None,
232230
sync_node=False,
233-
save: bool = True
231+
save: bool = True,
234232
):
235233
if env_filepath is not None:
236234
env_params = extract_env_params(env_filepath, sync_node=sync_node, raise_for_status=True)

node_cli/core/schains.py

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@
1313
NODE_CONFIG_PATH,
1414
NODE_CLI_STATUS_FILENAME,
1515
SCHAIN_NODE_DATA_PATH,
16-
SCHAINS_MNT_DIR_SYNC
16+
SCHAINS_MNT_DIR_SYNC,
1717
)
1818
from node_cli.configs.env import get_env_config
1919

20-
from node_cli.utils.helper import (
21-
get_request,
22-
error_exit,
23-
safe_load_yml
24-
)
20+
from node_cli.utils.helper import get_request, error_exit, safe_load_yml
2521
from node_cli.utils.exit_codes import CLIExitCodes
2622
from node_cli.utils.print_formatters import (
2723
print_dkg_statuses,
2824
print_firewall_rules,
2925
print_schain_info,
30-
print_schains
26+
print_schains,
3127
)
3228
from node_cli.utils.docker_utils import ensure_volume, is_volume_exists
3329
from node_cli.utils.helper import read_json, run_cmd, save_json
@@ -41,9 +37,7 @@
4137

4238
def get_schain_firewall_rules(schain: str) -> None:
4339
status, payload = get_request(
44-
blueprint=BLUEPRINT_NAME,
45-
method='firewall-rules',
46-
params={'schain_name': schain}
40+
blueprint=BLUEPRINT_NAME, method='firewall-rules', params={'schain_name': schain}
4741
)
4842
if status == 'ok':
4943
print_firewall_rules(payload['endpoints'])
@@ -52,10 +46,7 @@ def get_schain_firewall_rules(schain: str) -> None:
5246

5347

5448
def show_schains() -> None:
55-
status, payload = get_request(
56-
blueprint=BLUEPRINT_NAME,
57-
method='list'
58-
)
49+
status, payload = get_request(blueprint=BLUEPRINT_NAME, method='list')
5950
if status == 'ok':
6051
schains = payload
6152
if not schains:
@@ -69,11 +60,7 @@ def show_schains() -> None:
6960

7061
def show_dkg_info(all_: bool = False) -> None:
7162
params = {'all': all_}
72-
status, payload = get_request(
73-
blueprint=BLUEPRINT_NAME,
74-
method='dkg-statuses',
75-
params=params
76-
)
63+
status, payload = get_request(blueprint=BLUEPRINT_NAME, method='dkg-statuses', params=params)
7764
if status == 'ok':
7865
print_dkg_statuses(payload)
7966
else:
@@ -82,9 +69,7 @@ def show_dkg_info(all_: bool = False) -> None:
8269

8370
def show_config(name: str) -> None:
8471
status, payload = get_request(
85-
blueprint=BLUEPRINT_NAME,
86-
method='config',
87-
params={'schain_name': name}
72+
blueprint=BLUEPRINT_NAME, method='config', params={'schain_name': name}
8873
)
8974
if status == 'ok':
9075
pprint.pprint(payload)
@@ -97,9 +82,7 @@ def get_node_cli_schain_status_filepath(schain_name: str) -> str:
9782

9883

9984
def update_node_cli_schain_status(
100-
schain_name: str,
101-
repair_ts: Optional[int] = None,
102-
snapshot_from: Optional[str] = None
85+
schain_name: str, repair_ts: Optional[int] = None, snapshot_from: Optional[str] = None
10386
) -> None:
10487
path = get_node_cli_schain_status_filepath(schain_name)
10588
if os.path.isdir(path):
@@ -110,7 +93,7 @@ def update_node_cli_schain_status(
11093
status = {
11194
'schain_name': schain_name,
11295
'repair_ts': repair_ts,
113-
'snapshot_from': snapshot_from
96+
'snapshot_from': snapshot_from,
11497
}
11598
os.makedirs(os.path.dirname(path), exist_ok=True)
11699
save_json(path, status)
@@ -121,20 +104,15 @@ def get_node_cli_schain_status(schain_name: str) -> dict:
121104
return read_json(path)
122105

123106

124-
def toggle_schain_repair_mode(
125-
schain: str,
126-
snapshot_from: Optional[str] = None
127-
) -> None:
107+
def toggle_schain_repair_mode(schain: str, snapshot_from: Optional[str] = None) -> None:
128108
ts = int(time.time())
129109
update_node_cli_schain_status(schain_name=schain, repair_ts=ts, snapshot_from=snapshot_from)
130110
print('Schain has been set for repair')
131111

132112

133113
def describe(schain: str, raw=False) -> None:
134114
status, payload = get_request(
135-
blueprint=BLUEPRINT_NAME,
136-
method='get',
137-
params={'schain_name': schain}
115+
blueprint=BLUEPRINT_NAME, method='get', params={'schain_name': schain}
138116
)
139117
if status == 'ok':
140118
print_schain_info(payload, raw=raw)
@@ -193,23 +171,18 @@ def rm_btrfs_subvolume(subvolume: str) -> None:
193171

194172
def fillin_snapshot_folder(src_path: str, block_number: int) -> None:
195173
snapshots_dirname = 'snapshots'
196-
snapshot_folder_path = os.path.join(
197-
src_path, snapshots_dirname, str(block_number))
174+
snapshot_folder_path = os.path.join(src_path, snapshots_dirname, str(block_number))
198175
os.makedirs(snapshot_folder_path, exist_ok=True)
199176
for subvolume in os.listdir(src_path):
200177
if subvolume != snapshots_dirname:
201178
logger.debug('Copying %s to %s', subvolume, snapshot_folder_path)
202179
subvolume_path = os.path.join(src_path, subvolume)
203-
subvolume_snapshot_path = os.path.join(
204-
snapshot_folder_path, subvolume)
180+
subvolume_snapshot_path = os.path.join(snapshot_folder_path, subvolume)
205181
make_btrfs_snapshot(subvolume_path, subvolume_snapshot_path)
206182

207183

208184
def restore_schain_from_snapshot(
209-
schain: str,
210-
snapshot_path: str,
211-
env_type: Optional[str] = None,
212-
schain_type: str = 'medium'
185+
schain: str, snapshot_path: str, env_type: Optional[str] = None, schain_type: str = 'medium'
213186
) -> None:
214187
if env_type is None:
215188
env_config = get_env_config()

node_cli/operations/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
turn_off as turn_off_op,
2626
turn_on as turn_on_op,
2727
restore as restore_op,
28-
repair_sync as repair_sync_op,
29-
configure_nftables
28+
cleanup_sync as cleanup_sync_op,
29+
configure_nftables,
3030
)

0 commit comments

Comments
 (0)