Skip to content

Commit cc5da94

Browse files
authored
Modify harvester pool - update migrate for introducer - Merge pull request #198 from Chia-Network/ms.migrate-intro
Support not migrating some variables
2 parents 7ec6408 + 8232d63 commit cc5da94

File tree

5 files changed

+50
-30
lines changed

5 files changed

+50
-30
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: 41 additions & 22 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, 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,26 @@
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+
):
2732
for k, v in default.items():
2833
if isinstance(v, dict) and k in updated:
29-
dict_add_new_default(updated[k], default[k])
30-
elif k not in updated:
31-
updated[k] = default[k]
34+
# If there is an intermediate key with empty string value, do not migrate all decendants
35+
if do_not_migrate_keys.get(k, None) == "":
36+
do_not_migrate_keys[k] = v
37+
dict_add_new_default(updated[k], default[k], do_not_migrate_keys.get(k, {}))
38+
elif k not in updated or k in do_not_migrate_keys:
39+
updated[k] = v
3240

3341

34-
def migrate_from(old_root, new_root, manifest):
42+
def migrate_from(
43+
old_root: Path, new_root: Path, manifest: List[str], do_not_migrate_keys: List[str]
44+
):
3545
"""
3646
Copy all the files in "manifest" to the new config directory.
3747
"""
@@ -55,26 +65,28 @@ def migrate_from(old_root, new_root, manifest):
5565
not_found.append(f)
5666
print(f"{old_path} not found, skipping")
5767
# 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)
68+
config: Dict = load_config(new_root, "config.yaml")
69+
config_str: str = initial_config_file("config.yaml")
70+
default_config: Dict = yaml.safe_load(config_str)
71+
flattened_keys = unflatten_properties({k: "" for k in do_not_migrate_keys})
72+
dict_add_new_default(config, default_config, flattened_keys)
6273

6374
save_config(new_root, "config.yaml", config)
75+
6476
# migrate plots
6577
# for now, we simply leave them where they are
6678
# and make what may have been relative paths absolute
6779
if "config/trusted.key" in not_found or "config/trusted.key" in not_found:
6880
initialize_ssl(new_root)
6981

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

7284
plot_root = (
7385
load_config(new_root, "config.yaml").get("harvester", {}).get("plot_root", ".")
7486
)
7587

76-
old_plots_root = path_from_root(old_root, plot_root)
77-
new_plots_root = path_from_root(new_root, plot_root)
88+
old_plots_root: Path = path_from_root(old_root, plot_root)
89+
new_plots_root: Path = path_from_root(new_root, plot_root)
7890

7991
old_plot_paths = plots_config.get("plots", {})
8092
if len(old_plot_paths) == 0:
@@ -83,13 +95,13 @@ def migrate_from(old_root, new_root, manifest):
8395

8496
print("\nmigrating plots.yaml")
8597

86-
new_plot_paths = {}
98+
new_plot_paths: Dict = {}
8799
for path, values in old_plot_paths.items():
88100
old_path_full = path_from_root(old_plots_root, path)
89101
new_path_relative = make_path_relative(old_path_full, new_plots_root)
90102
print(f"rewriting {path}\n as {new_path_relative}")
91103
new_plot_paths[str(new_path_relative)] = values
92-
plots_config_new = {"plots": new_plot_paths}
104+
plots_config_new: Dict = {"plots": new_plot_paths}
93105
save_config(new_root, "plots.yaml", plots_config_new)
94106
print("\nUpdated plots.yaml to point to where your existing plots are.")
95107
print(
@@ -117,7 +129,7 @@ def migrate_from(old_root, new_root, manifest):
117129
return 1
118130

119131

120-
def initialize_ssl(root_path):
132+
def initialize_ssl(root_path: Path):
121133
cert, key = generate_selfsigned_cert()
122134
path_crt = config_path_for_filename(root_path, "trusted.crt")
123135
path_key = config_path_for_filename(root_path, "trusted.key")
@@ -127,32 +139,39 @@ def initialize_ssl(root_path):
127139
f.write(key)
128140

129141

130-
def init(args, parser):
142+
def init(args: Namespace, parser: ArgumentParser):
131143
return chia_init(args)
132144

133145

134-
def chia_init(args):
135-
root_path = args.root_path
146+
def chia_init(args: Namespace):
147+
root_path: Path = args.root_path
136148
print(f"migrating to {root_path}")
137149
if root_path.is_dir():
138150
print(f"{root_path} already exists, no action taken")
139151
return -1
140152

141-
MANIFEST = [
153+
# These are the config keys that will not be migrated, and instead the default is used
154+
DO_NOT_MIGRATE_KEYS: List[str] = [
155+
"full_node.introducer_peer",
156+
"wallet.introducer_peer",
157+
]
158+
159+
# These are the files that will be migrated
160+
MANIFEST: List[str] = [
142161
"config/config.yaml",
143162
"config/plots.yaml",
144163
"config/keys.yaml",
145164
"config/trusted.crt",
146165
"config/trusted.key",
147166
]
148167

149-
PATH_MANIFEST_LIST = [
168+
PATH_MANIFEST_LIST: List[Tuple[Path, List[str]]] = [
150169
(Path(os.path.expanduser("~/.chia/beta-%s" % _)), MANIFEST)
151170
for _ in ["1.0b3", "1.0b2", "1.0b1"]
152171
]
153172

154173
for old_path, manifest in PATH_MANIFEST_LIST:
155-
r = migrate_from(old_path, root_path, manifest)
174+
r = migrate_from(old_path, root_path, manifest, DO_NOT_MIGRATE_KEYS)
156175
if r:
157176
break
158177
else:

src/harvester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def new_challenge(self, new_challenge: harvester_protocol.NewChallenge):
161161
)
162162

163163
loop = asyncio.get_running_loop()
164-
executor = concurrent.futures.ThreadPoolExecutor(max_workers=50)
164+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
165165

166166
def blocking_lookup(filename: Path, prover: DiskProver) -> Optional[List]:
167167
# Uses the DiskProver object to lookup qualities. This is a blocking call,

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)