|
1 |
| -from ethereum.pow import ethash |
2 | 1 | from ethereum import utils
|
3 |
| -import time |
4 | 2 | import sys
|
5 |
| -import warnings |
6 | 3 | from collections import OrderedDict
|
7 |
| -from ethereum import utils |
8 | 4 | from ethereum.slogging import get_logger
|
9 |
| -import rlp |
| 5 | +import pyethash |
10 | 6 |
|
11 | 7 | log = get_logger('eth.pow')
|
12 | 8 |
|
|
15 | 11 | else:
|
16 | 12 | from functools import lru_cache
|
17 | 13 |
|
18 |
| -try: |
19 |
| - import pyethash |
20 |
| - ETHASH_LIB = 'pyethash' # the C++ based implementation |
21 |
| -except ImportError: |
22 |
| - ETHASH_LIB = 'ethash' |
23 |
| - warnings.warn('using pure python implementation', ImportWarning) |
24 |
| - |
25 |
| -if ETHASH_LIB == 'ethash': |
26 |
| - mkcache = ethash.mkcache |
27 |
| - EPOCH_LENGTH = 30000 |
28 |
| - hashimoto_light = ethash.hashimoto_light |
29 |
| -elif ETHASH_LIB == 'pyethash': |
30 |
| - mkcache = pyethash.mkcache_bytes |
31 |
| - EPOCH_LENGTH = 30000 |
32 |
| - hashimoto_light = lambda s, c, h, n: \ |
33 |
| - pyethash.hashimoto_light(s, c, h, utils.big_endian_to_int(n)) |
34 |
| -else: |
35 |
| - raise Exception("invalid ethash library set") |
| 14 | +mkcache = pyethash.mkcache_bytes |
| 15 | +EPOCH_LENGTH = 30000 |
| 16 | +def hashimoto_light(s, c, h, n): |
| 17 | + return pyethash.hashimoto_light(s, c, h, utils.big_endian_to_int(n)) |
36 | 18 |
|
37 | 19 | TT64M1 = 2**64 - 1
|
38 | 20 | cache_seeds = ['\x00' * 32]
|
|
41 | 23 |
|
42 | 24 |
|
43 | 25 | def get_cache(block_number):
|
44 |
| - import sha3 |
45 | 26 | while len(cache_seeds) <= block_number // EPOCH_LENGTH:
|
46 | 27 | cache_seeds.append(utils.sha3(cache_seeds[-1]))
|
47 | 28 | seed = cache_seeds[block_number // EPOCH_LENGTH]
|
@@ -124,5 +105,3 @@ def mine(block_number, difficulty, mining_hash, start_nonce=0, rounds=1000):
|
124 | 105 | assert len(o[b"mix digest"]) == 32
|
125 | 106 | return bin_nonce, o[b"mix digest"]
|
126 | 107 | return None, None
|
127 |
| - |
128 |
| - |
0 commit comments