2022-09-30 11:40:22 +03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-11-28 05:30:25 +03:00
|
|
|
import logging
|
|
|
|
import pathlib
|
2022-07-13 19:43:48 +03:00
|
|
|
import sys
|
2021-11-28 05:30:25 +03:00
|
|
|
from multiprocessing import freeze_support
|
2023-08-11 13:25:19 +03:00
|
|
|
from typing import Any, Dict, Optional
|
2021-11-28 05:30:25 +03:00
|
|
|
|
|
|
|
from chia.consensus.constants import ConsensusConstants
|
|
|
|
from chia.consensus.default_constants import DEFAULT_CONSTANTS
|
2022-02-14 22:48:35 +03:00
|
|
|
from chia.rpc.crawler_rpc_api import CrawlerRpcApi
|
2021-11-28 05:30:25 +03:00
|
|
|
from chia.seeder.crawler import Crawler
|
|
|
|
from chia.seeder.crawler_api import CrawlerAPI
|
|
|
|
from chia.server.outbound_message import NodeType
|
2022-07-13 19:43:48 +03:00
|
|
|
from chia.server.start_service import RpcInfo, Service, async_run
|
2023-11-30 22:38:38 +03:00
|
|
|
from chia.types.aliases import CrawlerService
|
2022-09-13 00:57:31 +03:00
|
|
|
from chia.util.chia_logging import initialize_service_logging
|
2022-07-08 03:57:08 +03:00
|
|
|
from chia.util.config import load_config, load_config_cli
|
2021-11-28 05:30:25 +03:00
|
|
|
from chia.util.default_root import DEFAULT_ROOT_PATH
|
2023-09-06 21:01:11 +03:00
|
|
|
from chia.util.misc import SignalHandlers
|
2021-11-28 05:30:25 +03:00
|
|
|
|
|
|
|
# See: https://bugs.python.org/issue29288
|
|
|
|
"".encode("idna")
|
|
|
|
|
2022-07-02 09:08:13 +03:00
|
|
|
SERVICE_NAME = "seeder"
|
2021-11-28 05:30:25 +03:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-07-13 19:43:48 +03:00
|
|
|
def create_full_node_crawler_service(
|
|
|
|
root_path: pathlib.Path,
|
2023-08-11 13:25:19 +03:00
|
|
|
config: Dict[str, Any],
|
2022-07-13 19:43:48 +03:00
|
|
|
consensus_constants: ConsensusConstants,
|
|
|
|
connect_to_daemon: bool = True,
|
2023-11-30 22:38:38 +03:00
|
|
|
) -> CrawlerService:
|
2022-07-08 03:57:08 +03:00
|
|
|
service_config = config[SERVICE_NAME]
|
2023-08-11 13:25:19 +03:00
|
|
|
crawler_config = service_config["crawler"]
|
2022-07-08 03:57:08 +03:00
|
|
|
|
2021-11-28 05:30:25 +03:00
|
|
|
crawler = Crawler(
|
2022-07-08 03:57:08 +03:00
|
|
|
service_config,
|
2021-11-28 05:30:25 +03:00
|
|
|
root_path=root_path,
|
2023-08-11 13:25:19 +03:00
|
|
|
constants=consensus_constants,
|
2021-11-28 05:30:25 +03:00
|
|
|
)
|
|
|
|
api = CrawlerAPI(crawler)
|
|
|
|
|
2022-07-08 03:57:08 +03:00
|
|
|
network_id = service_config["selected_network"]
|
2022-07-13 19:43:48 +03:00
|
|
|
|
2023-12-05 22:30:56 +03:00
|
|
|
rpc_info: Optional[RpcInfo[CrawlerRpcApi]] = None
|
2023-08-11 13:25:19 +03:00
|
|
|
if crawler_config.get("start_rpc_server", True):
|
|
|
|
rpc_info = (CrawlerRpcApi, crawler_config.get("rpc_port", 8561))
|
2022-07-13 19:43:48 +03:00
|
|
|
|
|
|
|
return Service(
|
2021-11-28 05:30:25 +03:00
|
|
|
root_path=root_path,
|
2022-07-08 03:57:08 +03:00
|
|
|
config=config,
|
2021-11-28 05:30:25 +03:00
|
|
|
node=api.crawler,
|
|
|
|
peer_api=api,
|
|
|
|
node_type=NodeType.FULL_NODE,
|
2022-07-08 03:57:08 +03:00
|
|
|
advertised_port=service_config["port"],
|
2022-07-13 23:02:08 +03:00
|
|
|
service_name="full_node",
|
2021-11-28 05:30:25 +03:00
|
|
|
upnp_ports=[],
|
|
|
|
on_connect_callback=crawler.on_connect,
|
|
|
|
network_id=network_id,
|
2022-07-13 19:43:48 +03:00
|
|
|
rpc_info=rpc_info,
|
|
|
|
connect_to_daemon=connect_to_daemon,
|
2021-11-28 05:30:25 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-13 19:43:48 +03:00
|
|
|
async def async_main() -> int:
|
2022-07-08 03:57:08 +03:00
|
|
|
# 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[SERVICE_NAME] = service_config
|
|
|
|
overrides = service_config["network_overrides"]["constants"][service_config["selected_network"]]
|
2021-11-28 05:30:25 +03:00
|
|
|
updated_constants = DEFAULT_CONSTANTS.replace_str_to_bytes(**overrides)
|
2022-09-13 00:57:31 +03:00
|
|
|
initialize_service_logging(service_name=SERVICE_NAME, config=config)
|
2022-07-13 19:43:48 +03:00
|
|
|
service = create_full_node_crawler_service(DEFAULT_ROOT_PATH, config, updated_constants)
|
2023-09-06 21:01:11 +03:00
|
|
|
async with SignalHandlers.manage() as signal_handlers:
|
|
|
|
await service.setup_process_global_state(signal_handlers=signal_handlers)
|
|
|
|
await service.run()
|
2021-11-28 05:30:25 +03:00
|
|
|
|
2022-07-13 19:43:48 +03:00
|
|
|
return 0
|
2021-11-28 05:30:25 +03:00
|
|
|
|
2022-07-13 19:43:48 +03:00
|
|
|
|
|
|
|
def main() -> int:
|
2021-11-28 05:30:25 +03:00
|
|
|
freeze_support()
|
2022-07-13 19:43:48 +03:00
|
|
|
return async_run(async_main())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|