def loop(): global f_changed_status, f_working failed = 5 while f_working: check_connection() try: if P.F_NOW_BOOTING: if fast_sync_chain(): P.F_NOW_BOOTING = False if builder.best_block: update_mining_staking_all_info() builder.remove_failmark() elif failed < 0: exit_msg = 'Failed sync.' builder.make_failemark(exit_msg) logging.critical(exit_msg) system_exit() f_working = False elif f_changed_status is False: failed -= 1 elif f_changed_status is True: f_changed_status = False reset_good_node() sleep(5) except BlockChainError as e: reset_good_node() logging.warning('Update chain failed "{}"'.format(e)) sleep(5) except BaseException as e: reset_good_node() logging.error('Update chain failed "{}"'.format(e), exc_info=True) sleep(5) # out of loop logging.debug("Close sync loop.")
def add_failed_mark(): failed_deque.append(time.time()) if min(failed_deque) < time.time() - 3600: return elif len(failed_deque) >= 10: builder.make_failemark("Too many block check fail.") failed_deque.clear() P.F_NOW_BOOTING = True
def add_failed_mark(error=None): failed_deque.append(time.time()) if min(failed_deque) < time.time() - 7200: return elif len(failed_deque) >= 10: builder.make_failemark(error) failed_deque.clear() P.F_NOW_BOOTING = True
def add_failed_mark(): failed_deque.append(time()) if min(failed_deque) < time() - 3600: return elif len(failed_deque) >= 10: builder.make_failemark("Too many block check fail.") failed_deque.clear() logging.warning("22 Set booting mode.") P.F_NOW_BOOTING = True
def loop(): global f_changed_status failed = 5 while not P.F_STOP: check_network_connection() try: if P.F_NOW_BOOTING: if fast_sync_chain(): logging.warning("Reset booting mode.") P.F_NOW_BOOTING = False if builder.best_block: update_mining_staking_all_info() failed = 0 builder.remove_failmark() elif failed < 0: exit_msg = 'Failed sync.' builder.make_failemark(exit_msg) logging.critical(exit_msg) system_exit() # out of loop logging.debug("Close sync loop.") return elif f_changed_status is False: logging.warning( "Resync mode failed, retry={}".format(failed)) failed -= 1 elif f_changed_status is True: f_changed_status = False reset_good_node() sleep(5) except BlockChainError as e: reset_good_node() logging.warning('Update chain failed "{}"'.format(e)) sleep(5) except Exception as e: reset_good_node() logging.error('Update chain failed "{}"'.format(e), exc_info=True) sleep(5)