Exemplo n.º 1
0
async def main():
    timelord = Timelord()
    host, port = parse_host_port(timelord)
    server = ChiaServer(port, timelord, NodeType.TIMELORD)
    _ = await server.start_server(host, None)

    def signal_received():
        server.close_all()
        asyncio.create_task(timelord._shutdown())

    asyncio.get_running_loop().add_signal_handler(signal.SIGINT,
                                                  signal_received)
    asyncio.get_running_loop().add_signal_handler(signal.SIGTERM,
                                                  signal_received)

    full_node_peer = PeerInfo(
        timelord.config["full_node_peer"]["host"],
        timelord.config["full_node_peer"]["port"],
    )

    await asyncio.sleep(1)  # Prevents TCP simultaneous connect with full node
    await server.start_client(full_node_peer, None)

    async for msg in timelord._manage_discriminant_queue():
        server.push_message(msg)

    await server.await_closed()
Exemplo n.º 2
0
async def main():
    config = load_config_cli("config.yaml", "timelord")

    initialize_logging("Timelord %(name)-23s", config["logging"])
    log = logging.getLogger(__name__)
    setproctitle("chia_timelord")

    timelord = Timelord(config)
    server = ChiaServer(config["port"], timelord, NodeType.TIMELORD)
    _ = await server.start_server(config["host"], None)

    def signal_received():
        server.close_all()
        asyncio.create_task(timelord._shutdown())

    asyncio.get_running_loop().add_signal_handler(signal.SIGINT, signal_received)
    asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, signal_received)

    full_node_peer = PeerInfo(
        timelord.config["full_node_peer"]["host"],
        timelord.config["full_node_peer"]["port"],
    )

    await asyncio.sleep(1)  # Prevents TCP simultaneous connect with full node
    await server.start_client(full_node_peer, None)

    async for msg in timelord._manage_discriminant_queue():
        server.push_message(msg)

    await server.await_closed()
    log.info("Timelord fully closed.")
Exemplo n.º 3
0
async def async_main():
    root_path = DEFAULT_ROOT_PATH
    net_config = load_config(root_path, "config.yaml")
    config = load_config_cli(root_path, "config.yaml", "timelord")
    initialize_logging("Timelord %(name)-23s", config["logging"], root_path)
    log = logging.getLogger(__name__)
    setproctitle("chia_timelord")

    timelord = Timelord(config, constants)
    ping_interval = net_config.get("ping_interval")
    network_id = net_config.get("network_id")
    assert ping_interval is not None
    assert network_id is not None
    server = ChiaServer(
        config["port"],
        timelord,
        NodeType.TIMELORD,
        ping_interval,
        network_id,
        DEFAULT_ROOT_PATH,
        config,
    )
    timelord.set_server(server)

    coro = asyncio.start_server(
        timelord._handle_client,
        config["vdf_server"]["host"],
        config["vdf_server"]["port"],
        loop=asyncio.get_running_loop(),
    )

    def stop_all():
        server.close_all()
        timelord._shutdown()

    try:
        asyncio.get_running_loop().add_signal_handler(signal.SIGINT, stop_all)
        asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, stop_all)
    except NotImplementedError:
        log.info("signal handlers unsupported")

    await asyncio.sleep(10)  # Allows full node to startup

    peer_info = PeerInfo(config["full_node_peer"]["host"],
                         config["full_node_peer"]["port"])
    bg_task = start_timelord_bg_task(server, peer_info, log)

    vdf_server = asyncio.ensure_future(coro)

    await timelord._manage_discriminant_queue()

    log.info("Closed discriminant queue.")
    log.info("Shutdown timelord.")

    await server.await_closed()
    vdf_server.cancel()
    bg_task.cancel()
    log.info("Timelord fully closed.")
Exemplo n.º 4
0
async def main():
    root_path = DEFAULT_ROOT_PATH
    net_config = load_config(root_path, "config.yaml")
    config = load_config_cli(root_path, "config.yaml", "timelord")
    initialize_logging("Timelord %(name)-23s", config["logging"])
    log = logging.getLogger(__name__)
    setproctitle("chia_timelord")

    timelord = Timelord(config, constants)
    ping_interval = net_config.get("ping_interval")
    network_id = net_config.get("network_id")
    assert ping_interval is not None
    assert network_id is not None
    server = ChiaServer(config["port"], timelord, NodeType.TIMELORD,
                        ping_interval, network_id)
    _ = await server.start_server(None, config)

    timelord_shutdown_task: Optional[asyncio.Task] = None

    coro = asyncio.start_server(
        timelord._handle_client,
        config["vdf_server"]["host"],
        config["vdf_server"]["port"],
        loop=asyncio.get_running_loop(),
    )

    def signal_received():
        nonlocal timelord_shutdown_task
        server.close_all()
        timelord_shutdown_task = asyncio.create_task(timelord._shutdown())

    asyncio.get_running_loop().add_signal_handler(signal.SIGINT,
                                                  signal_received)
    asyncio.get_running_loop().add_signal_handler(signal.SIGTERM,
                                                  signal_received)

    full_node_peer = PeerInfo(
        timelord.config["full_node_peer"]["host"],
        timelord.config["full_node_peer"]["port"],
    )

    await asyncio.sleep(1)  # Prevents TCP simultaneous connect with full node
    await server.start_client(full_node_peer, None, config)

    vdf_server = asyncio.ensure_future(coro)

    async for msg in timelord._manage_discriminant_queue():
        server.push_message(msg)

    log.info("Closed discriminant queue.")
    if timelord_shutdown_task is not None:
        await timelord_shutdown_task
    log.info("Shutdown timelord.")

    await server.await_closed()
    vdf_server.cancel()
    log.info("Timelord fully closed.")
Exemplo n.º 5
0
def service_kwargs_for_timelord(root_path):
    service_name = "timelord"
    config = load_config_cli(root_path, "config.yaml", service_name)

    connect_peers = [
        PeerInfo(config["full_node_peer"]["host"],
                 config["full_node_peer"]["port"])
    ]

    api = Timelord(config, constants["DISCRIMINANT_SIZE_BITS"])

    async def start_callback():
        await api._start()

    def stop_callback():
        api._close()

    async def await_closed_callback():
        await api._await_closed()

    kwargs = dict(
        root_path=root_path,
        api=api,
        node_type=NodeType.TIMELORD,
        advertised_port=config["port"],
        service_name=service_name,
        server_listen_ports=[config["port"]],
        start_callback=start_callback,
        stop_callback=stop_callback,
        await_closed_callback=await_closed_callback,
        connect_peers=connect_peers,
        auth_connect_peers=False,
    )
    return kwargs
Exemplo n.º 6
0
async def setup_timelord(port, full_node_port, sanitizer,
                         consensus_constants: ConsensusConstants):
    config = load_config(bt.root_path, "config.yaml", "timelord")
    config["sanitizer_mode"] = sanitizer
    if sanitizer:
        config["vdf_server"]["port"] = 7999

    api = Timelord(config, consensus_constants.DISCRIMINANT_SIZE_BITS)

    started = asyncio.Event()

    async def start_callback():
        await api._start()
        nonlocal started
        started.set()

    def stop_callback():
        api._close()

    async def await_closed_callback():
        await api._await_closed()

    service = Service(
        root_path=bt.root_path,
        api=api,
        node_type=NodeType.TIMELORD,
        advertised_port=port,
        service_name="timelord",
        server_listen_ports=[port],
        connect_peers=[PeerInfo(self_hostname, full_node_port)],
        auth_connect_peers=False,
        start_callback=start_callback,
        stop_callback=stop_callback,
        await_closed_callback=await_closed_callback,
        parse_cli_args=False,
    )

    run_task = asyncio.create_task(service.run())
    await started.wait()

    yield api, api.server

    service.stop()
    await run_task
Exemplo n.º 7
0
async def setup_timelord(port, dic={}):
    config = load_config(root_path, "config.yaml", "timelord")

    test_constants_copy = test_constants.copy()
    for k in dic.keys():
        test_constants_copy[k] = dic[k]
    timelord = Timelord(config, test_constants_copy)

    net_config = load_config(root_path, "config.yaml")
    ping_interval = net_config.get("ping_interval")
    network_id = net_config.get("network_id")
    assert ping_interval is not None
    assert network_id is not None
    server = ChiaServer(
        port,
        timelord,
        NodeType.TIMELORD,
        ping_interval,
        network_id,
        bt.root_path,
        config,
        f"timelord_server_{port}",
    )

    coro = asyncio.start_server(
        timelord._handle_client,
        config["vdf_server"]["host"],
        config["vdf_server"]["port"],
        loop=asyncio.get_running_loop(),
    )

    vdf_server = asyncio.ensure_future(coro)

    timelord.set_server(server)
    timelord._start_bg_tasks()

    async def run_timelord():
        async for msg in timelord._manage_discriminant_queue():
            server.push_message(msg)

    timelord_task = asyncio.create_task(run_timelord())

    yield (timelord, server)

    vdf_server.cancel()
    server.close_all()
    await timelord._shutdown()
    await timelord_task
    await server.await_closed()
Exemplo n.º 8
0
def service_kwargs_for_timelord(
    root_path: pathlib.Path, config: Dict, discriminant_size_bits: int
) -> Dict:

    connect_peers = [
        PeerInfo(config["full_node_peer"]["host"], config["full_node_peer"]["port"])
    ]

    api = Timelord(config, discriminant_size_bits)

    kwargs = dict(
        root_path=root_path,
        api=api,
        node_type=NodeType.TIMELORD,
        advertised_port=config["port"],
        service_name=SERVICE_NAME,
        server_listen_ports=[config["port"]],
        connect_peers=connect_peers,
        auth_connect_peers=False,
    )
    return kwargs