Exemplo n.º 1
0
def node_probe():
    count = 10
    num = 5
    block_num = None
    
    while True:
        time.sleep(1)
        
        try:
            import eosfactory.core.cleos_get as cleos_get
            head_block_num = cleos_get.GetInfo(is_verbose=0).head_block
        except:
            head_block_num = 0
        finally:
            print(".", end="", flush=True)

        if block_num is None:
            block_num = head_block_num

        if head_block_num - block_num >= num:
            print()
            logger.INFO('''
            Local node is running. Block number is {}
            '''.format(head_block_num))
            break

        count = count - 1        
        if count <= 0:
            raise errors.Error('''
            The local node does not respond.
            ''')
Exemplo n.º 2
0
def is_head_block_num():
    '''
    Check if testnet is running.
    '''
    try: # if running, json is produced
        head_block_num = cleos_get.GetInfo(is_verbose=False).head_block
    except:
        head_block_num = -1
    return head_block_num > 0
Exemplo n.º 3
0
def status():
    '''
    Display EOS node status.
    '''

    logger.INFO('''
    ######### Node ``{}``, head block number ``{}``.
    '''.format(setup.nodeos_address(),
               cleos_get.GetInfo(is_verbose=0).head_block))
Exemplo n.º 4
0
def verify_testnet_production():
    head_block_num = 0
    try: # if running, json is produced
        head_block_num = cleos_get.GetInfo(is_verbose=False).head_block
    except:
        pass

    domain = "LOCAL" if is_local_testnet() else "REMOTE"
    if not head_block_num:
        raise errors.Error('''
        {} testnet is not running or is not responding @ {}.
        '''.format(domain, setup.nodeos_address()))
    else:
        logger.INFO('''
        {} testnet is active @ {}.
        '''.format(domain, setup.nodeos_address()))

    return head_block_num
Exemplo n.º 5
0
def node_probe():
    DELAY_TIME = 4
    WAIT_TIME = 1

    NUMBER_BLOCKS_ADDED = 3
    NUMBER_GET_INFO_CALLS = 7
    CHECK_COUNT = 2
    RATIO_THRESHOLD = 2.5
    NODEOS = "nodeos"

    count = NUMBER_GET_INFO_CALLS
    block_num = None

    pid = None
    for i in range(0, 5):
        pids = [p.info for p in psutil.process_iter(attrs=["pid", "name"]) \
                                        if p.info["name"] and NODEOS in p.info["name"]]
        if pids and pids[0]["name"] == NODEOS:
            pid = pids[0]["pid"]
            break
        time.sleep(0.5)
    if not pid:
        raise errors.Error('''
Local node has failed to start.
            ''')
    proc = psutil.Process(pid)
    cpu_percent_start = proc.cpu_percent(interval=WAIT_TIME)

    print("Starting nodeos, cpu percent: ", end="", flush=True)
    for i in range(0, int(DELAY_TIME / WAIT_TIME)):
        cpu_percent = proc.cpu_percent(interval=WAIT_TIME)
        print("{:.0f}, ".format(cpu_percent), end="", flush=True)

    while True:

        if not proc.is_running():
            raise errors.Error('''
Local node has stopped.
''')
        count = count - 1

        cpu_percent = proc.cpu_percent(interval=WAIT_TIME)
        
        try:
            import eosfactory.core.cleos_get as cleos_get
            head_block_num = cleos_get.GetInfo(is_verbose=0).head_block
            if block_num is None:
                block_num = head_block_num
                count = int(NUMBER_BLOCKS_ADDED * 0.5/WAIT_TIME) + 1
        except:
            head_block_num = 0
            pass
        
        if block_num:
            print("{:.0f}* ".format(cpu_percent), end="", flush=True)
        else:
            print("{:.0f}; ".format(cpu_percent), end="", flush=True)

        if count == CHECK_COUNT and not block_num and \
                            cpu_percent_start / cpu_percent < RATIO_THRESHOLD:
            print(" stuck.")
            raise errors.Error(ERR_MSG_IS_STUCK)        

        if block_num and head_block_num - block_num >= NUMBER_BLOCKS_ADDED:
            print()
            logger.INFO('''
            Local node is running. Block number is {}
            '''.format(head_block_num))
            break

        if count <= 0:
            print()
            raise errors.Error('''
The local node does not respond.
            ''')
Exemplo n.º 6
0
def info():
    '''
    Display EOS node info.
    '''
    logger.INFO(str(cleos_get.GetInfo(is_verbose=False)))