示例#1
0
文件: main.py 项目: Flamboy78/trinity
async def launch_node_coro(args: Namespace,
                           trinity_config: TrinityConfig) -> None:
    endpoint = TrinityEventBusEndpoint()
    NodeClass = trinity_config.get_app_config(Eth1AppConfig).node_class
    node = NodeClass(endpoint, trinity_config)

    networking_connection_config = ConnectionConfig.from_name(
        NETWORKING_EVENTBUS_ENDPOINT, trinity_config.ipc_dir)

    await endpoint.start_serving(networking_connection_config)
    endpoint.auto_connect_new_announced_endpoints()
    await endpoint.connect_to_endpoints(
        ConnectionConfig.from_name(MAIN_EVENTBUS_ENDPOINT,
                                   trinity_config.ipc_dir),
        # Plugins that run within the networking process broadcast and receive on the
        # the same endpoint
        networking_connection_config,
    )
    await endpoint.announce_endpoint()

    # This is a second PluginManager instance governing plugins in a shared process.
    plugin_manager = PluginManager(SharedProcessScope(endpoint),
                                   get_all_plugins())
    plugin_manager.prepare(args, trinity_config)

    asyncio.ensure_future(
        handle_networking_exit(node, plugin_manager, endpoint))
    asyncio.ensure_future(node.run())
示例#2
0
def launch_node(args: Namespace, trinity_config: TrinityConfig) -> None:
    with trinity_config.process_id_file('networking'):

        endpoint = TrinityEventBusEndpoint()
        NodeClass = trinity_config.get_app_config(Eth1AppConfig).node_class
        node = NodeClass(endpoint, trinity_config)
        # The `networking` process creates a process pool executor to offload cpu intensive
        # tasks. We should revisit that when we move the sync in its own process
        ensure_global_asyncio_executor()
        loop = node.get_event_loop()

        networking_connection_config = ConnectionConfig.from_name(
            NETWORKING_EVENTBUS_ENDPOINT, trinity_config.ipc_dir)
        endpoint.start_serving_nowait(
            networking_connection_config,
            loop,
        )
        endpoint.auto_connect_new_announced_endpoints()
        endpoint.connect_to_endpoints_blocking(
            ConnectionConfig.from_name(MAIN_EVENTBUS_ENDPOINT,
                                       trinity_config.ipc_dir),
            # Plugins that run within the networking process broadcast and receive on the
            # the same endpoint
            networking_connection_config,
        )
        endpoint.announce_endpoint()
        # This is a second PluginManager instance governing plugins in a shared process.
        plugin_manager = setup_plugins(SharedProcessScope(endpoint),
                                       get_all_plugins())
        plugin_manager.prepare(args, trinity_config)

        asyncio.ensure_future(handle_networking_exit(node, plugin_manager,
                                                     endpoint),
                              loop=loop)
        asyncio.ensure_future(node.run(), loop=loop)
        loop.run_forever()
        loop.close()
示例#3
0
async def monitoring(normalized_name: str,
                     trinity_config: TrinityConfig) -> None:
    event_bus = TrinityEventBusEndpoint("monitoring_ui")
    connection_config = ConnectionConfig.from_name(
        normalized_name,
        trinity_config.ipc_dir,
    )
    await event_bus.start()
    await event_bus.start_server(connection_config.path)
    await event_bus.connect_to_endpoints(
        ConnectionConfig.from_name(MAIN_EVENTBUS_ENDPOINT,
                                   trinity_config.ipc_dir))
    await event_bus.announce_endpoint()
    await event_bus.broadcast(PluginStartedEvent(type(MonitoringPlugin)))

    asyncio.ensure_future(event_bus.auto_connect_new_announced_endpoints())
    event_bus.subscribe(NewBlockHashesEvent,
                        lambda event: logging.info(event.msg))