def database_server_ipc_path(): core_db = MemoryDB() core_db[b'key-a'] = b'value-a' chaindb = ChainDB(core_db) # TODO: use a custom chain class only for testing. chaindb.persist_header(ROPSTEN_GENESIS_HEADER) with tempfile.TemporaryDirectory() as temp_dir: chain_config = ChainConfig(network_id=ROPSTEN_NETWORK_ID, data_dir=temp_dir) chaindb_server_process = multiprocessing.Process( target=serve_chaindb, args=(chain_config, core_db), ) chaindb_server_process.start() wait_for_ipc(chain_config.database_ipc_path) try: yield chain_config.database_ipc_path finally: kill_process_gracefully(chaindb_server_process, logging.getLogger())
def initialize_database(chain_config: ChainConfig, chaindb: ChainDB) -> None: try: chaindb.get_canonical_head() except CanonicalHeadNotFound: if chain_config.chain_identifier == ROPSTEN: # We're starting with a fresh DB. # TODO: log that we initialized the chain chaindb.persist_header(ROPSTEN_GENESIS_HEADER) else: # TODO: add genesis data to ChainConfig and if it's present, use it # here to initialize the chain. raise NotImplementedError("Not implemented for other chains yet")
def initialize_database(chain_config: ChainConfig, chaindb: ChainDB) -> None: try: chaindb.get_canonical_head() except CanonicalHeadNotFound: if chain_config.network_id == ROPSTEN_NETWORK_ID: # We're starting with a fresh DB. chaindb.persist_header(ROPSTEN_GENESIS_HEADER) elif chain_config.network_id == MAINNET_NETWORK_ID: chaindb.persist_header(MAINNET_GENESIS_HEADER) else: # TODO: add genesis data to ChainConfig and if it's present, use it # here to initialize the chain. raise NotImplementedError( "Only the mainnet and ropsten chains are currently supported")
def get_server(privkey, address, peer_class): base_db = MemoryDB() headerdb = HeaderDB(base_db) chaindb = ChainDB(base_db) chaindb.persist_header(ROPSTEN_GENESIS_HEADER) chain = RopstenChain(base_db) server = Server( privkey, address.tcp_port, chain, chaindb, headerdb, base_db, network_id=NETWORK_ID, peer_class=peer_class, ) return server
def get_server(privkey, address, peer_class): db = MemoryDB() headerdb = HeaderDB(db) chaindb = ChainDB(db) chaindb.persist_header(ROPSTEN_GENESIS_HEADER) chain = RopstenChain(chaindb) server = Server( privkey, address, chain, chaindb, headerdb, db, network_id=1, min_peers=1, peer_class=peer_class, ) return server
def database_server_ipc_path(): core_db = MemoryDB() core_db[b'key-a'] = b'value-a' chaindb = ChainDB(core_db) # TODO: use a custom chain class only for testing. chaindb.persist_header(ROPSTEN_GENESIS_HEADER) with tempfile.TemporaryDirectory() as temp_dir: ipc_path = os.path.join(temp_dir, 'chaindb.ipc') chaindb_server_process = multiprocessing.Process( target=serve_chaindb, args=(core_db, ipc_path), ) chaindb_server_process.start() wait_for_ipc(ipc_path) try: yield ipc_path finally: kill_process_gracefully(chaindb_server_process)