Created
February 3, 2019 19:42
-
-
Save yyforyongyu/02fc007e28e41dc885ca2a5cb84f1943 to your computer and use it in GitHub Desktop.
a partial copy from https://github.com/ethereum/py-evm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX_TEST_MINE_ATTEMPTS = 1000 | |
def mine_pow_nonce(block_number: int, mining_hash: Hash32, difficulty: int) -> Tuple[bytes, bytes]: | |
cache = get_cache(block_number) | |
for nonce in range(MAX_TEST_MINE_ATTEMPTS): | |
mining_output = hashimoto_light(block_number, cache, mining_hash, nonce) | |
result = big_endian_to_int(mining_output[b'result']) | |
result_cap = 2**256 // difficulty | |
if result <= result_cap: | |
return nonce.to_bytes(8, 'big'), mining_output[b'mix digest'] | |
raise Exception("Too many attempts at POW mining, giving up") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment