Exemplo n.º 1
0
async def round_start():
    print("Round Start")
    print("--------------------------")
    print("Last Round broadhash", config.POC_LAST_BROADHASH)
    print("{} candidates, {} slots".format(len(config.POC_HYPER_NODES_LIST), config.MAX_ROUND_SLOTS))
    tickets = await determine.hn_list_to_tickets(config.POC_HYPER_NODES_LIST)
    print("Tickets\n", tickets)
    slots = await determine.tickets_to_jurors(tickets, config.POC_LAST_BROADHASH)
    print("Slots\n", slots)
    test_slots = await determine.hn_list_to_test_slots(config.POC_HYPER_NODES_LIST, slots)
    print("Tests Slots\n", test_slots)
    print("")
    print("Timeslots test")
    print("--------------------------")
    expected = [(config.ORIGIN_OF_TIME, 0, 0),
                (config.ORIGIN_OF_TIME + config.POS_SLOT_TIME_SEC * 1.5, 0, 1),
                (config.ORIGIN_OF_TIME + config.ROUND_TIME_SEC + config.POS_SLOT_TIME_SEC * 0.5, 1, 0),
                (config.ORIGIN_OF_TIME + config.ROUND_TIME_SEC + config.POS_SLOT_TIME_SEC * 1.5, 1, 1),
                (config.ORIGIN_OF_TIME + config.ROUND_TIME_SEC + config.POS_SLOT_TIME_SEC * 2.5, 1, 2),
                (config.ORIGIN_OF_TIME + config.ROUND_TIME_SEC + config.POS_SLOT_TIME_SEC * 3.5, 1, 3)
                ]
    for (test, expected_round, expected_slot) in expected:
        calc_round, calc_slot = determine.timestamp_to_round_slot(test)
        print("Time {}: Round {} - Slot {} (expected {} - {})".format(test, calc_round, calc_slot, expected_round, expected_slot))
    print("Basic forge simulation - 1/min")
    print("--------------------------")
    try:
        while True:
            test = round(time.time())
            calc_round, calc_slot = determine.timestamp_to_round_slot(test)
            print("Current Time {}: Round {} - Slot {}".format(test, calc_round, calc_slot))
            if calc_slot < len(slots):
                print("Forger is {}".format(slots[calc_slot][0]))
                print("Tests:", test_slots[calc_slot])
            else:
                print("End of round...")
            time.sleep(60)
    except Exception as e:
        print(e)
        pass
Exemplo n.º 2
0
    async def load_hn_remote_url(
        self,
        a_round: int = 0,
        datadir: str = "",
        inactive_last_round=None,
        force_all: bool = False,
        no_cache: bool = False,
        ignore_config: bool = False,
        ip="",
        balance_check=False,
        url="",
    ):
        """
        Load from an external url. Fallback for weak nodes that can't properly handle sqlite db sharing across processes.

        :param a_round:
        :param datadir:
        :param inactive_last_round:
        :param force_all:
        :param no_cache:
        :param ignore_config:
        :param ip:
        :param balance_check: Force balance check for all HN at the end of the call
        :param url the base url to fetch json from
        :return:
        """
        if balance_check:
            self.app_log.error(
                "load_hn_remote_url Error, can't do balance check.")
            sys.exit()
        if ip:
            self.app_log.error("load_hn_remote_url Error, can't do ip.")
            sys.exit()
        if a_round <= 0:
            a_round, a_slot = timestamp_to_round_slot(time.time())
        try:
            a_round = str(a_round)
            # self.app_log.info("load_hn_remote_url around {}".format(a_round))
            http_client = AsyncHTTPClient()
            try:
                full_url = "{}{}/{}/{}.json".format(url, a_round[0],
                                                    a_round[1], a_round)
                self.app_log.info("load_hn_remote_url {}".format(full_url))
                response = await http_client.fetch(full_url)
                self.regs = json.loads(response.body.decode("utf-8"))
                self.app_log.info("load_hn_remote_urlok")
            except HTTPError as e:
                # HTTPError is raised for non-200 responses; the response
                # can be found in e.response.
                self.app_log.error("load_hn_remote_url http Error {}".format(
                    str(e)))
                self.regs = False
            except Exception as e:
                # Other errors are possible, such as IOError.
                self.app_log.error("load_hn_remote_url other Error {}".format(
                    str(e)))
                self.regs = False
            # http_client.close()  # unneeded for async
            if self.verbose:
                count = 0
                if self.regs:
                    count = len(self.regs)
                # self.app_log.info("{} PoW Valid HN :{}".format(count, json.dumps(self.regs)))
                self.app_log.info("{} PoW Valid HN".format(count))
        except Exception as e:
            self.app_log.error("load_hn_remote_url Error {}".format(e))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            self.app_log.error("detail {} {} {}".format(
                exc_type, fname, exc_tb.tb_lineno))
            sys.exit()
Exemplo n.º 3
0
                        help='Return json content (WIP)')
    args = parser.parse_args()
    verbose = True if args.verbose else False
    config.load('../main/')
    config.COMPUTING_REWARD = True
    pow = None
    if args.action in ['ts2powheight', 'powheight2ts', 'hnbalance', 'week']:
        if not path.isfile(config.POW_LEDGER_DB):
            raise ValueError("Bismuth Full ledger not found at {}".format(
                config.POW_LEDGER_DB))
        pow = pow_interface.PowInterface(verbose=verbose)

    if args.action == 'ts2posround':
        # TODO: json output if --json
        ts = int(args.param)
        a_round, a_slot = timestamp_to_round_slot(ts)
        print("TS", args.param)
        print("-------------")
        print("UTC  ", ts2utc(ts))
        print("Round", a_round)
        print("Slot ", a_slot)

    elif args.action == 'week':
        week = int(args.param)
        if week < 2:
            print("Not less than Week 2")
            sys.exit()
        end_of_week_ts = 1536998400 + (week - 2) * 604800
        print("Week", week)
        print("-------------")
        print("TS  ", end_of_week_ts)
Exemplo n.º 4
0
                        default=False,
                        help='Return json content (WIP)')
    args = parser.parse_args()
    verbose = True if args.verbose else False
    config.load('../main/')
    config.COMPUTING_REWARD = True
    pow = None
    if args.action in ['ts2powheight', 'powheight2ts', 'hnbalance']:
        if not path.isfile(config.POW_LEDGER_DB):
            raise ValueError("Bismuth Full ledger not found at {}".format(
                config.POW_LEDGER_DB))
        pow = pow_interface.PowInterface(verbose=verbose)

    if args.action == 'ts2posround':
        ts = int(args.param)
        a_round, a_slot = timestamp_to_round_slot(ts)
        print("TS", args.param)
        print("-------------")
        print("UTC  ", ts2utc(ts))
        print("Round", a_round)
        print("Slot ", a_slot)

    elif args.action == 'posround2ts':
        round = int(args.param)
        ts = round_to_timestamp(round)
        print("Round", args.param)
        print("-------------")
        print("UTC ", ts2utc(ts))
        print("TS  ", ts)

    elif args.action == 'ts2powheight':