Skip to content

Commit ad99ed0

Browse files
committed
Support not migrating some variables
1 parent 7ec6408 commit ad99ed0

File tree

4 files changed

+53
-28
lines changed

4 files changed

+53
-28
lines changed

electron-ui/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmds/chia.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import argparse
21
import importlib
32
import pathlib
3+
from argparse import Namespace, ArgumentParser
44

55
from src import __version__
66
from src.util.default_root import DEFAULT_ROOT_PATH
@@ -9,8 +9,8 @@
99
SUBCOMMANDS = ["init", "generate", "show", "start", "stop", "version", "netspace"]
1010

1111

12-
def create_parser():
13-
parser = argparse.ArgumentParser(
12+
def create_parser() -> ArgumentParser:
13+
parser: ArgumentParser = ArgumentParser(
1414
description="Manage chia blockchain infrastructure (%s)." % __version__,
1515
epilog="Try 'chia start node', 'chat netspace -d 48', or 'chia show -s'.",
1616
)
@@ -38,7 +38,7 @@ def create_parser():
3838
return parser
3939

4040

41-
def chia(args, parser):
41+
def chia(args: Namespace, parser: ArgumentParser):
4242
return args.function(args, parser)
4343

4444

src/cmds/init.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os
22
import shutil
33

4+
from argparse import Namespace, ArgumentParser
5+
from typing import List, Tuple, Dict, Optional, Any
46
from blspy import ExtendedPrivateKey
57
from src.types.BLSSignature import BLSPublicKey
68
from src.consensus.coinbase import create_puzzlehash_for_pk
9+
from src.util.config import unflatten_properties
710
from pathlib import Path
811

912
from src.util.config import (
@@ -19,19 +22,30 @@
1922
from src.ssl.create_ssl import generate_selfsigned_cert
2023

2124

22-
def make_parser(parser):
25+
def make_parser(parser: ArgumentParser):
2326
parser.set_defaults(function=init)
2427

2528

26-
def dict_add_new_default(updated, default):
29+
def dict_add_new_default(
30+
updated: Dict, default: Dict, do_not_migrate_keys: Dict[str, Any]
31+
):
32+
print(
33+
"Calling with ",
34+
updated.keys(),
35+
"and",
36+
default.keys(),
37+
do_not_migrate_keys.keys(),
38+
)
2739
for k, v in default.items():
2840
if isinstance(v, dict) and k in updated:
29-
dict_add_new_default(updated[k], default[k])
30-
elif k not in updated:
41+
dict_add_new_default(updated[k], default[k], do_not_migrate_keys.get(k, {}))
42+
elif k not in updated or k in do_not_migrate_keys:
3143
updated[k] = default[k]
3244

3345

34-
def migrate_from(old_root, new_root, manifest):
46+
def migrate_from(
47+
old_root: Path, new_root: Path, manifest: List[str], do_not_migrate_keys: List[str]
48+
):
3549
"""
3650
Copy all the files in "manifest" to the new config directory.
3751
"""
@@ -55,26 +69,29 @@ def migrate_from(old_root, new_root, manifest):
5569
not_found.append(f)
5670
print(f"{old_path} not found, skipping")
5771
# update config yaml with new keys
58-
config = load_config(new_root, "config.yaml")
59-
config_str = initial_config_file("config.yaml")
60-
default_config = yaml.safe_load(config_str)
61-
dict_add_new_default(config, default_config)
72+
config: Dict = load_config(new_root, "config.yaml")
73+
config_str: str = initial_config_file("config.yaml")
74+
default_config: Dict = yaml.safe_load(config_str)
75+
flattened_keys = unflatten_properties({k: "" for k in do_not_migrate_keys})
76+
print("FLATTENED", flattened_keys)
77+
dict_add_new_default(config, default_config, flattened_keys)
6278

6379
save_config(new_root, "config.yaml", config)
80+
6481
# migrate plots
6582
# for now, we simply leave them where they are
6683
# and make what may have been relative paths absolute
6784
if "config/trusted.key" in not_found or "config/trusted.key" in not_found:
6885
initialize_ssl(new_root)
6986

70-
plots_config = load_config(new_root, "plots.yaml")
87+
plots_config: Dict = load_config(new_root, "plots.yaml")
7188

7289
plot_root = (
7390
load_config(new_root, "config.yaml").get("harvester", {}).get("plot_root", ".")
7491
)
7592

76-
old_plots_root = path_from_root(old_root, plot_root)
77-
new_plots_root = path_from_root(new_root, plot_root)
93+
old_plots_root: Path = path_from_root(old_root, plot_root)
94+
new_plots_root: Path = path_from_root(new_root, plot_root)
7895

7996
old_plot_paths = plots_config.get("plots", {})
8097
if len(old_plot_paths) == 0:
@@ -83,13 +100,13 @@ def migrate_from(old_root, new_root, manifest):
83100

84101
print("\nmigrating plots.yaml")
85102

86-
new_plot_paths = {}
103+
new_plot_paths: Dict = {}
87104
for path, values in old_plot_paths.items():
88105
old_path_full = path_from_root(old_plots_root, path)
89106
new_path_relative = make_path_relative(old_path_full, new_plots_root)
90107
print(f"rewriting {path}\n as {new_path_relative}")
91108
new_plot_paths[str(new_path_relative)] = values
92-
plots_config_new = {"plots": new_plot_paths}
109+
plots_config_new: Dict = {"plots": new_plot_paths}
93110
save_config(new_root, "plots.yaml", plots_config_new)
94111
print("\nUpdated plots.yaml to point to where your existing plots are.")
95112
print(
@@ -117,7 +134,7 @@ def migrate_from(old_root, new_root, manifest):
117134
return 1
118135

119136

120-
def initialize_ssl(root_path):
137+
def initialize_ssl(root_path: Path):
121138
cert, key = generate_selfsigned_cert()
122139
path_crt = config_path_for_filename(root_path, "trusted.crt")
123140
path_key = config_path_for_filename(root_path, "trusted.key")
@@ -127,32 +144,39 @@ def initialize_ssl(root_path):
127144
f.write(key)
128145

129146

130-
def init(args, parser):
147+
def init(args: Namespace, parser: ArgumentParser):
131148
return chia_init(args)
132149

133150

134-
def chia_init(args):
135-
root_path = args.root_path
151+
def chia_init(args: Namespace):
152+
root_path: Path = args.root_path
136153
print(f"migrating to {root_path}")
137154
if root_path.is_dir():
138155
print(f"{root_path} already exists, no action taken")
139156
return -1
140157

141-
MANIFEST = [
158+
# These are the config keys that will not be migrated, and instead the default is used
159+
DO_NOT_MIGRATE_KEYS: List[str] = [
160+
"full_node.introducer_peer.host",
161+
"wallet.introducer_peer.host",
162+
]
163+
164+
# These are the files that will be migrated
165+
MANIFEST: List[str] = [
142166
"config/config.yaml",
143167
"config/plots.yaml",
144168
"config/keys.yaml",
145169
"config/trusted.crt",
146170
"config/trusted.key",
147171
]
148172

149-
PATH_MANIFEST_LIST = [
173+
PATH_MANIFEST_LIST: List[Tuple[Path, List[str]]] = [
150174
(Path(os.path.expanduser("~/.chia/beta-%s" % _)), MANIFEST)
151175
for _ in ["1.0b3", "1.0b2", "1.0b1"]
152176
]
153177

154178
for old_path, manifest in PATH_MANIFEST_LIST:
155-
r = migrate_from(old_path, root_path, manifest)
179+
r = migrate_from(old_path, root_path, manifest, DO_NOT_MIGRATE_KEYS)
156180
if r:
157181
break
158182
else:

src/util/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ def unflatten_properties(config: Dict):
9999

100100

101101
def add_property(d: Dict, partial_key: str, value: Any):
102-
key_1, key_2 = partial_key.split(".")
102+
key_1, key_2 = partial_key.split(".", maxsplit=1)
103103
if key_1 not in d:
104104
d[key_1] = {}
105105
if "." in key_2:
106-
add_property(d, key_2, value)
106+
add_property(d[key_1], key_2, value)
107107
else:
108108
d[key_1][key_2] = value
109109

0 commit comments

Comments
 (0)