def main(): base_db = LevelDB(test_directory / "leveldb_multiprocess3") base_db = MemoryDB() database_server_process = ctx.Process( target=run_database_process, args=(base_db, ), ) print('1') # start the processes database_server_process.start() print('2') try: print('3') wait_for_ipc(db_ipc_path) except TimeoutError as e: print("Timeout when starting db process") db_manager = create_db_manager(db_ipc_path) db_manager.connect() mp_db = db_manager.get_db() db = LevelDB(test_directory / "leveldb") speed_test(db) speed_test(mp_db) database_server_process.join()
def get_chain(self) -> BaseChain: db_manager = create_db_manager( self.context.chain_config.database_ipc_path) db_manager.connect() chain_class = self.context.chain_config.node_class.chain_class if self.context.chain_config.sync_mode == SYNC_LIGHT: header_db = db_manager.get_headerdb() # type: ignore chain = chain_class(header_db, peer_chain=EventBusLightPeerChain( self.context.event_bus)) else: db = db_manager.get_db() # type: ignore chain = chain_class(db) return chain
def __init__(self, plugin_manager: PluginManager, chain_config: ChainConfig) -> None: super().__init__() self.chain_config: ChainConfig = chain_config self.private_helios_key = chain_config.node_private_helios_key self.wallet_address = chain_config.node_wallet_address self._plugin_manager = plugin_manager self._db_manager = create_db_manager(chain_config.database_ipc_path) self._db_manager.connect() # type: ignore for i in range(chain_config.num_chain_processes): chain_manager = create_chain_manager( chain_config.get_chain_ipc_path(i)) chain_manager.connect() self._chain_managers.append(chain_manager) self._chain_head_db = self._db_manager.get_chain_head_db( ) # type: ignore self._jsonrpc_ipc_path: Path = chain_config.jsonrpc_ipc_path
def start(self) -> None: self.logger.info('JSON-RPC Server started') self.context.event_bus.connect() db_manager = create_db_manager( self.context.chain_config.database_ipc_path) db_manager.connect() chain_class = self.context.chain_config.node_class.chain_class db = db_manager.get_db() # type: ignore chain = chain_class( db, wallet_address=self.context.chain_config.node_wallet_address) rpc_context = RPCContext( enable_private_modules=self.context.args.enable_private_rpc, keystore_dir=self.context.chain_config.keystore_dir) rpc = RPCServer(chain, rpc_context, self.context.event_bus, chain_class) ipc_server = IPCServer(rpc, self.context.chain_config.jsonrpc_ipc_path) loop = asyncio.get_event_loop() asyncio.ensure_future( exit_with_service_and_endpoint(ipc_server, self.context.event_bus)) asyncio.ensure_future(ipc_server.run()) if (not self.context.args.disable_rpc_websocket_proxy ) and self.context.chain_config.is_main_instance: # start websocket proxy self.logger.info('RPC Websocket proxy started') proxy_url = "ws://0.0.0.0:" + str( self.context.chain_config.rpc_port) rpc_websocket_service = rpc_websocket_server( proxy_url, rpc.execute) #rpc_websocket_service.run() asyncio.ensure_future(rpc_websocket_service.run()) loop.run_forever() loop.close()
def run_chain_process(chain_config: ChainConfig, instance = 0) -> None: with chain_config.process_id_file('database_{}'.format(instance)): # connect with database process db_manager = create_db_manager(chain_config.database_ipc_path) db_manager.connect() base_db = db_manager.get_db() # start chain process manager = get_chain_manager(chain_config, base_db, instance) server = manager.get_server() # type: ignore def _sigint_handler(*args: Any) -> None: server.stop_event.set() signal.signal(signal.SIGINT, _sigint_handler) try: server.serve_forever() except SystemExit: server.stop_event.set() raise
def start(self) -> None: self.logger.info('JSON-RPC Server started') self.context.event_bus.connect() db_manager = create_db_manager( self.context.chain_config.database_ipc_path) db_manager.connect() chain_class = self.context.chain_config.node_class.chain_class db = db_manager.get_db() # type: ignore chain = chain_class( db, wallet_address=self.context.chain_config.node_wallet_address) rpc_context = RPCContext( enable_private_modules=self.context.args.enable_private_rpc, enable_admin_module=self.context.args.enable_admin_rpc, keystore_dir=self.context.chain_config.keystore_dir, admin_rpc_password_config_path=self.context.chain_config. rpc_login_config_path) rpc = RPCServer(chain, rpc_context, self.context.event_bus, chain_class) ipc_server = IPCServer(rpc, self.context.chain_config.jsonrpc_ipc_path) loop = asyncio.get_event_loop() asyncio.ensure_future( exit_with_service_and_endpoint(ipc_server, self.context.event_bus)) asyncio.ensure_future(ipc_server.run()) if self.context.args.use_synchronous_rpc: use_async = False else: use_async = True if self.context.args.enable_rpc_http_proxy and ( not self.context.args.disable_rpc_websocket_proxy): raise Exception( "Cannot run websocket and http proxy at the same time.") if (not self.context.args.disable_rpc_websocket_proxy ) and self.context.chain_config.is_main_instance: self.logger.info('RPC Websocket proxy started') proxy_url = "ws://0.0.0.0:" + str( self.context.chain_config.rpc_port) rpc_websocket_service = rpc_websocket_server( proxy_url, rpc.execute, use_async) asyncio.ensure_future(rpc_websocket_service.run()) elif self.context.args.enable_rpc_http_proxy and self.context.chain_config.is_main_instance: self.logger.info('RPC HTTP REST proxy started') proxy_url = "http://0.0.0.0:" + str( self.context.chain_config.rpc_port) rpc_websocket_service = rpc_http_server(proxy_url, rpc.execute, use_async) asyncio.ensure_future(rpc_websocket_service.run()) loop.run_forever() loop.close()