Esempio n. 1
0
def calculate_min_iters_from_iterations(
    proof_of_space: ProofOfSpace,
    difficulty: uint64,
    iterations: uint64,
) -> uint64:
    """
    Using the total number of iterations on a block (which is encoded in the block) along with
    other details, we can calculate the constant factor in iterations, which is not written into
    the block.
    """
    quality: bytes32 = proof_of_space.verify_and_get_quality_string()
    iters_rounded = (int(difficulty) << 32) // quality_str_to_quality(
        quality, proof_of_space.size)
    min_iterations = uint64(iterations - iters_rounded)
    assert min_iterations >= 1
    return min_iterations
def calculate_iterations_quality(
    quality_string: bytes32,
    size: int,
    difficulty: int,
    cc_sp_output_hash: bytes32,
) -> uint64:
    """
    Calculates the number of iterations from the quality. The quality is converted to a number
    between 0 and 1, then divided by expected plot size, and finally multiplied by the
    difficulty.
    """
    sp_quality_string: bytes32 = std_hash(quality_string + cc_sp_output_hash)
    iters = uint64(
        uint128(int(difficulty) << 25) //
        quality_str_to_quality(sp_quality_string, size))
    return max(iters, uint64(1))
def calculate_iterations_quality(
    quality: bytes32,
    size: uint8,
    difficulty: uint64,
    min_iterations: uint64,
) -> uint64:
    """
    Calculates the number of iterations from the quality. The quality is converted to a number
    between 0 and 1, then divided by expected plot size, and finally multiplied by the
    difficulty.
    """
    iters_rounded = (int(difficulty) << 32) // quality_str_to_quality(
        quality, size)

    iters_final = uint64(min_iterations + iters_rounded)
    assert iters_final >= 1
    return iters_final