Beispiel #1
0
    def check_network_info(block_num, boundary, timeout):
        if not utils.Zilliqa.is_pow_window():
            logging.warning(f"The network is not in pow window")
            return False

        network_ds_block = utils.Zilliqa.cur_ds_block
        if block_num < network_ds_block:
            logging.warning(f"Got wrong block number: {block_num} < {network_ds_block}")
            return False
        if block_num > network_ds_block + 1:
            logging.warning(f"Got wrong block number: {block_num} > {network_ds_block} + 1")
            return False

        difficulty = ethash.boundary_to_difficulty(boundary)
        network_difficulty = [
            utils.Zilliqa.shard_difficulty,
            utils.Zilliqa.ds_difficulty
        ]
        if difficulty not in network_difficulty:
            logging.warning(f"Got wrong difficulty {difficulty}")
            return False

        if timeout > config["zilliqa"]["POW_WINDOW_IN_SECONDS"]:
            logging.warning(f"Got wrong timeout {timeout}")
            return False

        return True
Beispiel #2
0
def current_work():
    latest_work = pow.PowWork.get_latest_work()

    block_num = 0
    difficulty = 0
    start_time = None
    if latest_work:
        block_num = latest_work.block_num
        start_time = latest_work.start_time
        difficulty = ethash.boundary_to_difficulty(
            crypto.hex_str_to_bytes(latest_work.boundary))

    now = datetime.utcnow()
    secs_next_pow = pow.PowWork.calc_seconds_to_next_pow()
    next_pow_time = now + timedelta(seconds=secs_next_pow)

    return {
        "block_num": block_num,
        "difficulty": difficulty,
        "utc_time": utils.iso_format(now),
        "start_time": utils.iso_format(start_time),
        "next_pow_time": utils.iso_format(next_pow_time),
        "avg_hashrate": miner.HashRate.epoch_hashrate(block_num),
        "avg_pow_fee": pow.PowWork.avg_pow_fee(block_num),
    }
Beispiel #3
0
    def check_network_info(block_num, boundary, timeout):
        if not blockchain.Zilliqa.is_pow_window():
            logging.warning(f"The network is not in pow window")
            return False

        network_ds_block = blockchain.Zilliqa.cur_ds_block
        if block_num < network_ds_block:
            logging.warning(
                f"Got wrong block number: {block_num} < {network_ds_block}")
            return False
        if block_num > network_ds_block + 1:
            logging.warning(
                f"Got wrong block number: {block_num} > {network_ds_block} + 1"
            )
            return False

        network_difficulty = [blockchain.Zilliqa.shard_difficulty]
        if config.site_settings.allow_ds_pow:
            network_difficulty.append(blockchain.Zilliqa.ds_difficulty)

        # try divided difficulty
        difficulty = ethash.boundary_to_difficulty_divided(
            boundary,
            n_divided=config["zilliqa"]["POW_BOUNDARY_N_DIVIDED"],
            n_divided_start=config["zilliqa"]["POW_BOUNDARY_N_DIVIDED_START"])
        if difficulty not in network_difficulty:
            # try original difficulty
            old_difficulty = ethash.boundary_to_difficulty(boundary)
            if old_difficulty not in network_difficulty:
                logging.warning(f"Got wrong difficulty {difficulty}")
                return False

        if timeout > config["zilliqa"]["POW_WINDOW_IN_SECONDS"]:
            logging.warning(f"Got wrong timeout {timeout}")
            return False

        return True
 def test_tools(self):
     for i in range(256):
         assert ethash.boundary_to_difficulty(ethash.difficulty_to_boundary(i)) == i