Ejemplo n.º 1
0
def wait_for_geth_to_start(proc, max_wait=10):
    start = time.time()
    while time.time() < start + max_wait:
        output = []
        line = proc.get_output_nowait()
        if line:
            output.append(line)

        if line is None:
            continue
        if 'Starting mining operation' in line:
            break
        elif "Still generating DAG" in line:
            print(line[line.index("Still generating DAG"):])
        elif line.startswith('Fatal:'):
            utils.kill_proc(proc)
            raise ValueError(
                "Geth Errored while starting\nerror: {0}\n\nFull Output{1}".
                format(
                    line,
                    ''.join(output),
                ))
    else:
        utils.kill_proc(proc)
        raise ValueError("Geth process never started\n\n{0}".format(
            ''.join(output)))
Ejemplo n.º 2
0
def geth_node(request, populus_config):
    from populus.geth import (
        run_geth_node,
        get_geth_data_dir,
        get_geth_logfile_path,
        ensure_account_exists,
        create_geth_account,
        reset_chain,
        wait_for_geth_to_start,
    )
    from populus.utils import (
        ensure_path_exists,
        kill_proc,
    )

    project_dir = populus_config.get_value(request, 'geth_project_dir')
    chain_name = populus_config.get_value(request, 'geth_chain_name')

    data_dir = get_geth_data_dir(project_dir, chain_name)

    logfile_name_fmt = "geth-{0}-{{0}}.log".format(request.module.__name__)
    logfile_path = get_geth_logfile_path(data_dir, logfile_name_fmt)

    ensure_path_exists(data_dir)
    ensure_account_exists(data_dir)

    num_accounts = populus_config.get_value(request, 'geth_num_accounts')
    if num_accounts > 1:
        for _ in range(num_accounts - 1):
            create_geth_account(data_dir)

    should_reset_chain = populus_config.get_value(request, 'geth_reset_chain')

    if should_reset_chain:
        reset_chain(data_dir)

    rpc_port = populus_config.get_value(request, 'geth_rpc_port')
    rpc_host = populus_config.get_value(request, 'geth_rpc_host')

    geth_max_wait = int(populus_config.get_value(request, 'geth_max_wait'))

    command, proc = run_geth_node(data_dir, rpc_addr=rpc_host,
                                  rpc_port=rpc_port, logfile=logfile_path,
                                  verbosity="6")

    wait_for_geth_to_start(proc, max_wait=geth_max_wait)

    yield proc
    kill_proc(proc)
Ejemplo n.º 3
0
def wait_for_geth_to_start(proc, max_wait=10):
    start = time.time()
    while time.time() < start + max_wait:
        output = []
        line = proc.get_output_nowait()
        if line:
            output.append(line)

        if line is None:
            continue
        if "Starting mining operation" in line:
            break
        elif "Still generating DAG" in line:
            print(line[line.index("Still generating DAG") :])
        elif line.startswith("Fatal:"):
            utils.kill_proc(proc)
            raise ValueError("Geth Errored while starting\nerror: {0}\n\nFull Output{1}".format(line, "".join(output)))
    else:
        utils.kill_proc(proc)
        raise ValueError("Geth process never started\n\n{0}".format("".join(output)))