Example #1
0
def database_server_ipc_path():
    core_db = AtomicDB()
    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:
        trinity_config = TrinityConfig(
            network_id=ROPSTEN_NETWORK_ID,
            trinity_root_dir=temp_dir,
        )
        trinity_config.add_app_config(Eth1AppConfig(trinity_config, None))
        initialize_data_dir(trinity_config)

        manager = create_db_server_manager(trinity_config, core_db)
        chaindb_server_process = multiprocessing.Process(
            target=serve_chaindb,
            args=(manager, ),
        )
        chaindb_server_process.start()

        wait_for_ipc(trinity_config.database_ipc_path)

        try:
            yield trinity_config.database_ipc_path
        finally:
            kill_process_gracefully(chaindb_server_process,
                                    logging.getLogger())
Example #2
0
def test_sync_mode_effect_on_db_and_node_type(sync_mode, expected_full_db,
                                              expected_node_class):

    trinity_config = TrinityConfig(network_id=1)
    eth1_app_config = Eth1AppConfig(trinity_config, sync_mode)
    assert eth1_app_config.sync_mode == sync_mode
    assert eth1_app_config.node_class == expected_node_class
    if expected_full_db:
        assert eth1_app_config.database_mode is Eth1DbMode.FULL
    else:
        assert eth1_app_config.database_mode is Eth1DbMode.LIGHT
Example #3
0
    def chain_for_eth1_config(self, trinity_config: TrinityConfig,
                              eth1_app_config: Eth1AppConfig) -> AsyncChainAPI:
        chain_config = eth1_app_config.get_chain_config()

        db = DBClient.connect(trinity_config.database_ipc_path)

        if eth1_app_config.database_mode is Eth1DbMode.LIGHT:
            header_db = HeaderDB(db)
            event_bus_light_peer_chain = EventBusLightPeerChain(self.event_bus)
            return chain_config.light_chain_class(
                header_db, peer_chain=event_bus_light_peer_chain)
        elif eth1_app_config.database_mode is Eth1DbMode.FULL:
            return chain_config.full_chain_class(db)
        else:
            raise Exception(
                f"Unsupported Database Mode: {eth1_app_config.database_mode}")
Example #4
0
def chain_for_eth1_config(trinity_config: TrinityConfig,
                          eth1_app_config: Eth1AppConfig,
                          event_bus: EndpointAPI) -> Iterator[AsyncChainAPI]:
    chain_config = eth1_app_config.get_chain_config()

    db = DBClient.connect(trinity_config.database_ipc_path)

    with db:
        if eth1_app_config.database_mode is Eth1DbMode.LIGHT:
            header_db = HeaderDB(db)
            event_bus_light_peer_chain = EventBusLightPeerChain(event_bus)
            yield chain_config.light_chain_class(
                header_db, peer_chain=event_bus_light_peer_chain
            )
        elif eth1_app_config.database_mode is Eth1DbMode.FULL:
            yield chain_config.full_chain_class(db)
        else:
            raise Exception(f"Unsupported Database Mode: {eth1_app_config.database_mode}")
Example #5
0
def eth1_app_config(trinity_config):
    eth1_app_config = Eth1AppConfig(trinity_config, None)
    ensure_eth1_dirs(eth1_app_config)
    return eth1_app_config
Example #6
0
def test_computed_database_dir(app_identifier, sync_mode, expected_db_path,
                               expected_db_name):
    trinity_config = TrinityConfig(network_id=1, app_identifier=app_identifier)
    eth1_app_config = Eth1AppConfig(trinity_config, sync_mode)

    assert eth1_app_config.database_dir == trinity_config.data_dir / expected_db_path / expected_db_name  # noqa: E501