Skip to content

Commit

Permalink
add root_path parameter to initialize_service_logging()
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Dec 2, 2024
1 parent 61703ce commit f87fa62
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 76 deletions.
8 changes: 5 additions & 3 deletions chia/daemon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ async def async_run_daemon(root_path: Path, wait_for_unlock: bool = False) -> in
chia_init(root_path, should_check_keys=(not wait_for_unlock))
config = load_config(root_path, "config.yaml")
setproctitle("chia_daemon")
initialize_service_logging("daemon", config)
initialize_service_logging("daemon", config, root_path=root_path)
crt_path = root_path / config["daemon_ssl"]["private_crt"]
key_path = root_path / config["daemon_ssl"]["private_key"]
ca_crt_path = root_path / config["private_ssl_ca"]["crt"]
Expand Down Expand Up @@ -1589,11 +1589,13 @@ def run_daemon(root_path: Path, wait_for_unlock: bool = False) -> int:


def main() -> int:
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.keychain import Keychain

root_path = resolve_root_path(override=None)

wait_for_unlock = "--wait-for-unlock" in sys.argv[1:] and Keychain.is_keyring_locked()
return run_daemon(DEFAULT_ROOT_PATH, wait_for_unlock)
return run_daemon(root_path, wait_for_unlock)


if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions chia/seeder/dns_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from chia.server.signal_handlers import SignalHandlers
from chia.util.chia_logging import initialize_service_logging
from chia.util.config import load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.path import path_from_root

SERVICE_NAME = "seeder"
Expand Down Expand Up @@ -577,12 +577,13 @@ def create_dns_server_service(config: dict[str, Any], root_path: Path) -> DNSSer

def main() -> None: # pragma: no cover
freeze_support()
root_path = DEFAULT_ROOT_PATH
root_path = resolve_root_path(override=None)

# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
config = load_config(root_path, "config.yaml")
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME)
config[SERVICE_NAME] = service_config
initialize_service_logging(service_name=SERVICE_NAME, config=config)
initialize_service_logging(service_name=SERVICE_NAME, config=config, root_path=root_path)

dns_server = create_dns_server_service(config, root_path)
asyncio.run(run_dns_server(dns_server))
Expand Down
16 changes: 9 additions & 7 deletions chia/seeder/start_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from chia.types.aliases import CrawlerService
from chia.util.chia_logging import initialize_service_logging
from chia.util.config import load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path

# See: https://bugs.python.org/issue29288
"".encode("idna")
Expand Down Expand Up @@ -65,15 +65,15 @@ def create_full_node_crawler_service(
)


async def async_main() -> int:
async def async_main(root_path: pathlib.Path) -> int:
# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
config = load_config(root_path, "config.yaml")
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME)
config[SERVICE_NAME] = service_config
overrides = service_config["network_overrides"]["constants"][service_config["selected_network"]]
updated_constants = replace_str_to_bytes(DEFAULT_CONSTANTS, **overrides)
initialize_service_logging(service_name=SERVICE_NAME, config=config)
service = create_full_node_crawler_service(DEFAULT_ROOT_PATH, config, updated_constants)
initialize_service_logging(service_name=SERVICE_NAME, config=config, root_path=root_path)
service = create_full_node_crawler_service(root_path, config, updated_constants)
async with SignalHandlers.manage() as signal_handlers:
await service.setup_process_global_state(signal_handlers=signal_handlers)
await service.run()
Expand All @@ -83,7 +83,9 @@ async def async_main() -> int:

def main() -> int:
freeze_support()
return async_run(async_main())
root_path = resolve_root_path(override=None)

return async_run(async_main(root_path=root_path))


if __name__ == "__main__":
Expand Down
20 changes: 11 additions & 9 deletions chia/server/start_data_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from chia.types.aliases import DataLayerService, WalletService
from chia.util.chia_logging import initialize_logging
from chia.util.config import load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.ints import uint16
from chia.util.task_timing import maybe_manage_task_instrumentation

Expand Down Expand Up @@ -91,26 +91,26 @@ def create_data_layer_service(
)


async def async_main() -> int:
async def async_main(root_path: pathlib.Path) -> int:
# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml", fill_missing_services=True)
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME, fill_missing_services=True)
config = load_config(root_path, "config.yaml", fill_missing_services=True)
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME, fill_missing_services=True)
config[SERVICE_NAME] = service_config
initialize_logging(
service_name=SERVICE_NAME,
logging_config=service_config["logging"],
root_path=DEFAULT_ROOT_PATH,
root_path=root_path,
)

create_all_ssl(
root_path=DEFAULT_ROOT_PATH,
root_path=root_path,
private_node_names=["data_layer"],
public_node_names=["data_layer"],
overwrite=False,
)

plugins_config = config["data_layer"].get("plugins", {})
service_dir = DEFAULT_ROOT_PATH / SERVICE_NAME
service_dir = root_path / SERVICE_NAME

old_uploaders = config["data_layer"].get("uploaders", [])
new_uploaders = plugins_config.get("uploaders", [])
Expand All @@ -130,7 +130,7 @@ async def async_main() -> int:
*conf_file_uploaders,
]

service = create_data_layer_service(DEFAULT_ROOT_PATH, config, downloaders, uploaders)
service = create_data_layer_service(root_path, config, downloaders, uploaders)
async with SignalHandlers.manage() as signal_handlers:
await service.setup_process_global_state(signal_handlers=signal_handlers)
await service.run()
Expand All @@ -139,10 +139,12 @@ async def async_main() -> int:


def main() -> int:
root_path = resolve_root_path(override=None)

with maybe_manage_task_instrumentation(
enable=os.environ.get(f"CHIA_INSTRUMENT_{SERVICE_NAME.upper()}") is not None
):
return async_run(coro=async_main())
return async_run(coro=async_main(root_path=root_path))


if __name__ == "__main__":
Expand Down
18 changes: 10 additions & 8 deletions chia/server/start_farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from chia.types.aliases import FarmerService
from chia.util.chia_logging import initialize_service_logging
from chia.util.config import get_unresolved_peer_infos, load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.keychain import Keychain
from chia.util.task_timing import maybe_manage_task_instrumentation

Expand Down Expand Up @@ -68,16 +68,16 @@ def create_farmer_service(
)


async def async_main() -> int:
async def async_main(root_path: pathlib.Path) -> int:
# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
config = load_config(root_path, "config.yaml")
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME)
config[SERVICE_NAME] = service_config
config_pool = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", "pool")
config_pool = load_config_cli(root_path, "config.yaml", "pool")
config["pool"] = config_pool
initialize_service_logging(service_name=SERVICE_NAME, config=config)
initialize_service_logging(service_name=SERVICE_NAME, config=config, root_path=root_path)

service = create_farmer_service(DEFAULT_ROOT_PATH, config, config_pool, DEFAULT_CONSTANTS)
service = create_farmer_service(root_path, config, config_pool, DEFAULT_CONSTANTS)
async with SignalHandlers.manage() as signal_handlers:
await service.setup_process_global_state(signal_handlers=signal_handlers)
await service.run()
Expand All @@ -86,10 +86,12 @@ async def async_main() -> int:


def main() -> int:
root_path = resolve_root_path(override=None)

with maybe_manage_task_instrumentation(
enable=os.environ.get(f"CHIA_INSTRUMENT_{SERVICE_NAME.upper()}") is not None
):
return async_run(coro=async_main())
return async_run(coro=async_main(root_path=root_path))


if __name__ == "__main__":
Expand Down
15 changes: 8 additions & 7 deletions chia/server/start_full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from chia.types.aliases import FullNodeService
from chia.util.chia_logging import initialize_service_logging
from chia.util.config import get_unresolved_peer_infos, load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.ints import uint16
from chia.util.task_timing import maybe_manage_task_instrumentation

Expand Down Expand Up @@ -72,17 +72,17 @@ async def create_full_node_service(
)


async def async_main(service_config: dict[str, Any]) -> int:
async def async_main(service_config: dict[str, Any], root_path: pathlib.Path) -> int:
# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
config = load_config(root_path, "config.yaml")
config[SERVICE_NAME] = service_config
network_id = service_config["selected_network"]
overrides = service_config["network_overrides"]["constants"][network_id]
update_testnet_overrides(network_id, overrides)
updated_constants = replace_str_to_bytes(DEFAULT_CONSTANTS, **overrides)
initialize_service_logging(service_name=SERVICE_NAME, config=config)
initialize_service_logging(service_name=SERVICE_NAME, config=config, root_path=root_path)

service = await create_full_node_service(DEFAULT_ROOT_PATH, config, updated_constants)
service = await create_full_node_service(root_path, config, updated_constants)
async with SignalHandlers.manage() as signal_handlers:
await service.setup_process_global_state(signal_handlers=signal_handlers)
await service.run()
Expand All @@ -92,19 +92,20 @@ async def async_main(service_config: dict[str, Any]) -> int:

def main() -> int:
freeze_support()
root_path = resolve_root_path(override=None)

with maybe_manage_task_instrumentation(
enable=os.environ.get(f"CHIA_INSTRUMENT_{SERVICE_NAME.upper()}") is not None
):
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME)
target_peer_count = service_config.get("target_peer_count", 40) - service_config.get(
"target_outbound_peer_count", 8
)
if target_peer_count < 0:
target_peer_count = None
if not service_config.get("use_chia_loop_policy", True):
target_peer_count = None
return async_run(coro=async_main(service_config), connection_limit=target_peer_count)
return async_run(coro=async_main(service_config, root_path=root_path), connection_limit=target_peer_count)


if __name__ == "__main__":
Expand Down
16 changes: 9 additions & 7 deletions chia/server/start_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from chia.types.peer_info import UnresolvedPeerInfo
from chia.util.chia_logging import initialize_service_logging
from chia.util.config import get_unresolved_peer_infos, load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.task_timing import maybe_manage_task_instrumentation

# See: https://bugs.python.org/issue29288
Expand Down Expand Up @@ -64,15 +64,15 @@ def create_harvester_service(
)


async def async_main() -> int:
async def async_main(root_path: pathlib.Path) -> int:
# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
config = load_config(root_path, "config.yaml")
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME)
config[SERVICE_NAME] = service_config
initialize_service_logging(service_name=SERVICE_NAME, config=config)
initialize_service_logging(service_name=SERVICE_NAME, config=config, root_path=root_path)
farmer_peers = get_unresolved_peer_infos(service_config, NodeType.FARMER)

service = create_harvester_service(DEFAULT_ROOT_PATH, config, DEFAULT_CONSTANTS, farmer_peers)
service = create_harvester_service(root_path, config, DEFAULT_CONSTANTS, farmer_peers)
async with SignalHandlers.manage() as signal_handlers:
await service.setup_process_global_state(signal_handlers=signal_handlers)
await service.run()
Expand All @@ -81,10 +81,12 @@ async def async_main() -> int:


def main() -> int:
root_path = resolve_root_path(override=None)

with maybe_manage_task_instrumentation(
enable=os.environ.get(f"CHIA_INSTRUMENT_{SERVICE_NAME.upper()}") is not None
):
return async_run(coro=async_main())
return async_run(coro=async_main(root_path=root_path))


if __name__ == "__main__":
Expand Down
16 changes: 9 additions & 7 deletions chia/server/start_introducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from chia.types.aliases import IntroducerService
from chia.util.chia_logging import initialize_service_logging
from chia.util.config import load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.task_timing import maybe_manage_task_instrumentation

# See: https://bugs.python.org/issue29288
Expand Down Expand Up @@ -53,14 +53,14 @@ def create_introducer_service(
)


async def async_main() -> int:
async def async_main(root_path: pathlib.Path) -> int:
# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
config = load_config(root_path, "config.yaml")
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME)
config[SERVICE_NAME] = service_config
initialize_service_logging(service_name=SERVICE_NAME, config=config)
initialize_service_logging(service_name=SERVICE_NAME, config=config, root_path=root_path)

service = create_introducer_service(DEFAULT_ROOT_PATH, config)
service = create_introducer_service(root_path, config)
async with SignalHandlers.manage() as signal_handlers:
await service.setup_process_global_state(signal_handlers=signal_handlers)
await service.run()
Expand All @@ -69,10 +69,12 @@ async def async_main() -> int:


def main() -> int:
root_path = resolve_root_path(override=None)

with maybe_manage_task_instrumentation(
enable=os.environ.get(f"CHIA_INSTRUMENT_{SERVICE_NAME.upper()}") is not None
):
return async_run(coro=async_main())
return async_run(coro=async_main(root_path=root_path))


if __name__ == "__main__":
Expand Down
16 changes: 9 additions & 7 deletions chia/server/start_timelord.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from chia.types.aliases import TimelordService
from chia.util.chia_logging import initialize_service_logging
from chia.util.config import get_unresolved_peer_infos, load_config, load_config_cli
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.default_root import resolve_root_path
from chia.util.task_timing import maybe_manage_task_instrumentation

# See: https://bugs.python.org/issue29288
Expand Down Expand Up @@ -61,14 +61,14 @@ def create_timelord_service(
)


async def async_main() -> int:
async def async_main(root_path: pathlib.Path) -> int:
# TODO: refactor to avoid the double load
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
service_config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
config = load_config(root_path, "config.yaml")
service_config = load_config_cli(root_path, "config.yaml", SERVICE_NAME)
config[SERVICE_NAME] = service_config
initialize_service_logging(service_name=SERVICE_NAME, config=config)
initialize_service_logging(service_name=SERVICE_NAME, config=config, root_path=root_path)

service = create_timelord_service(DEFAULT_ROOT_PATH, config, DEFAULT_CONSTANTS)
service = create_timelord_service(root_path, config, DEFAULT_CONSTANTS)
async with SignalHandlers.manage() as signal_handlers:
await service.setup_process_global_state(signal_handlers=signal_handlers)
await service.run()
Expand All @@ -77,10 +77,12 @@ async def async_main() -> int:


def main() -> int:
root_path = resolve_root_path(override=None)

with maybe_manage_task_instrumentation(
enable=os.environ.get(f"CHIA_INSTRUMENT_{SERVICE_NAME.upper()}") is not None
):
return async_run(coro=async_main())
return async_run(coro=async_main(root_path=root_path))


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit f87fa62

Please sign in to comment.