async def do_run(self, event_bus: EndpointAPI) -> None: boot_info = self._boot_info trinity_config = boot_info.trinity_config with chain_for_config(trinity_config, event_bus) as chain: if trinity_config.has_app_config(Eth1AppConfig): modules = initialize_eth1_modules(chain, event_bus, trinity_config) elif trinity_config.has_app_config(BeaconAppConfig): modules = initialize_beacon_modules(chain, event_bus) else: raise Exception("Unsupported Node Type") rpc = RPCServer(modules, chain, event_bus) # Run IPC Server ipc_server = IPCServer(rpc, boot_info.trinity_config.jsonrpc_ipc_path) services_to_exit: Tuple[Service, ...] = (ipc_server, ) # Run HTTP Server if boot_info.args.enable_http: http_server = HTTPServer( handler=RPCHandler.handle(rpc.execute), port=boot_info.args.rpcport, ) services_to_exit += (http_server, ) async with contextlib.AsyncExitStack() as stack: managers = tuple([ await stack.enter_async_context( background_asyncio_service(service)) for service in services_to_exit ]) await managers[0].wait_finished()
def do_start(self) -> None: trinity_config = self.boot_info.trinity_config chain = self.chain_for_config(trinity_config) if trinity_config.has_app_config(Eth1AppConfig): modules = initialize_eth1_modules(chain, self.event_bus) elif trinity_config.has_app_config(BeaconAppConfig): modules = initialize_beacon_modules(chain, self.event_bus) else: raise Exception("Unsupported Node Type") rpc = RPCServer(modules, chain, self.event_bus) # Run IPC Server ipc_server = IPCServer(rpc, self.boot_info.trinity_config.jsonrpc_ipc_path) asyncio.ensure_future(ipc_server.run()) services_to_exit: Tuple[BaseService, ...] = ( ipc_server, self._event_bus_service, ) # Run HTTP Server if self.boot_info.args.enable_http: http_server = HTTPServer(rpc, port=self.boot_info.args.rpcport) asyncio.ensure_future(http_server.run()) services_to_exit += (http_server, ) asyncio.ensure_future(exit_with_services(*services_to_exit))
async def do_run(self, event_bus: EndpointAPI) -> None: boot_info = self._boot_info trinity_config = boot_info.trinity_config with chain_for_config(trinity_config, event_bus) as chain: if trinity_config.has_app_config(Eth1AppConfig): modules = initialize_eth1_modules(chain, event_bus, trinity_config) elif trinity_config.has_app_config(BeaconAppConfig): modules = initialize_beacon_modules(chain, event_bus) else: raise Exception("Unsupported Node Type") rpc = RPCServer(modules, chain, event_bus) # Run IPC Server ipc_server = IPCServer(rpc, boot_info.trinity_config.jsonrpc_ipc_path) services_to_exit: Tuple[Service, ...] = (ipc_server, ) # Run HTTP Server if boot_info.args.enable_http: http_server = HTTPServer( host=boot_info.args.http_listen_address, handler=RPCHandler.handle(rpc.execute), port=boot_info.args.http_port, ) services_to_exit += (http_server, ) await run_background_asyncio_services(services_to_exit)
async def do_run(cls, boot_info: BootInfo, event_bus: EndpointAPI) -> None: trinity_config = boot_info.trinity_config chain = chain_for_config(trinity_config, event_bus) if trinity_config.has_app_config(Eth1AppConfig): modules = initialize_eth1_modules(chain, event_bus) elif trinity_config.has_app_config(BeaconAppConfig): modules = initialize_beacon_modules(chain, event_bus) else: raise Exception("Unsupported Node Type") rpc = RPCServer(modules, chain, event_bus) # Run IPC Server ipc_server = IPCServer(rpc, boot_info.trinity_config.jsonrpc_ipc_path) services_to_exit: Tuple[BaseService, ...] = (ipc_server, ) # Run HTTP Server if boot_info.args.enable_http: http_server = HTTPServer(rpc, port=boot_info.args.rpcport) services_to_exit += (http_server, ) async with AsyncExitStack() as stack: for service in services_to_exit: await stack.enter_async_context(run_service(service)) await ipc_server.cancellation()
async def test_json_rpc_http_server(aiohttp_raw_server, aiohttp_client, event_bus, base_db, ipc_path): manager = DBManager(base_db) with manager.run(ipc_path): # Set chaindb override_lengths(SERENITY_CONFIG) db = DBClient.connect(ipc_path) genesis_config = SERENITY_CONFIG chaindb = AsyncBeaconChainDB(db, genesis_config) fork_choice_scoring = HigherSlotScoring() genesis_state, genesis_block = create_mock_genesis( pubkeys=(), config=SERENITY_CONFIG, keymap=dict(), genesis_block_class=BeaconBlock, genesis_time=0, ) chaindb.persist_state(genesis_state) chaindb.persist_block( SignedBeaconBlock.create(message=genesis_block), SignedBeaconBlock, fork_choice_scoring, ) try: rpc = RPCServer(initialize_beacon_modules(chaindb, event_bus), chaindb, event_bus) raw_server = await aiohttp_raw_server( RPCHandler.handle(rpc.execute)) client = await aiohttp_client(raw_server) request_id = 1 request_data = { "jsonrpc": "2.0", "method": "beacon_head", "params": [], "id": request_id, } response = await client.post("/", json=request_data) response_data = await response.json() assert response_data["id"] == request_id result = response_data["result"] assert result["slot"] == 0 assert decode_hex( result["block_root"]) == genesis_block.hash_tree_root assert decode_hex( result["state_root"]) == genesis_state.hash_tree_root except KeyboardInterrupt: pass finally: await raw_server.close() db.close()
def do_start(self) -> None: trinity_config = self.boot_info.trinity_config chain = self.chain_for_config(trinity_config) if trinity_config.has_app_config(Eth1AppConfig): modules = initialize_eth1_modules(chain, self.event_bus) elif trinity_config.has_app_config(BeaconAppConfig): modules = initialize_beacon_modules(chain, self.event_bus) else: raise Exception("Unsupported Node Type") rpc = RPCServer(modules, chain, self.event_bus) ipc_server = IPCServer(rpc, self.boot_info.trinity_config.jsonrpc_ipc_path) asyncio.ensure_future(exit_with_services( ipc_server, self._event_bus_service, )) asyncio.ensure_future(ipc_server.run())
async def do_run(self, event_bus: EndpointAPI) -> None: boot_info = self._boot_info trinity_config = boot_info.trinity_config with chain_for_config(trinity_config, event_bus) as chain: if trinity_config.has_app_config(Eth1AppConfig): modules = initialize_eth1_modules(chain, event_bus, trinity_config) elif trinity_config.has_app_config(BeaconAppConfig): modules = initialize_beacon_modules(chain, event_bus) else: raise Exception("Unsupported Node Type") rpc = RPCServer(modules, chain, event_bus) # Run IPC Server ipc_server = IPCServer(rpc, boot_info.trinity_config.jsonrpc_ipc_path) services_to_exit: Tuple[Service, ...] = ( ipc_server, ) try: http_modules = get_http_enabled_modules(boot_info.args.enable_http_apis, modules) except ValidationError as error: self.logger.error(error) return # Run HTTP Server if there are http enabled APIs if len(http_modules) > 0: enabled_module_names = tuple(mod.get_name() for mod in http_modules) self.logger.info("JSON-RPC modules exposed via HTTP: %s", enabled_module_names) non_http_modules = set(type(mod) for mod in modules) - set(http_modules) exec = rpc.execute_with_access_control(non_http_modules) http_server = HTTPServer( host=boot_info.args.http_listen_address, handler=RPCHandler.handle(exec), port=boot_info.args.http_port, ) services_to_exit += (http_server,) await run_background_asyncio_services(services_to_exit)
def setup_beacon_modules(self) -> Tuple[BeaconChainRPCModule, ...]: return initialize_beacon_modules(None, self.event_bus)