@@ -89,22 +89,26 @@ def mine(self, steps=1000):
89
89
BE(X) evaluates to the value equal to X when interpreted as a
90
90
big-endian-encoded integer.
91
91
"""
92
- b = self .block
93
- sz = blocks .get_cache_size (b .number )
94
- cache = blocks .get_cache_memoized (b . db , b .header .seed , sz )
95
- fsz = blocks .get_full_size (b .number )
96
- nonce = utils .big_endian_to_int (b .nonce )
92
+ # b = self.block
93
+ sz = blocks .get_cache_size (self . block .number )
94
+ cache = blocks .get_cache_memoized (self . block . db , self . block .header .seed , sz )
95
+ fsz = blocks .get_full_size (self . block .number )
96
+ nonce = utils .big_endian_to_int (self . block .nonce )
97
97
TT64M1 = 2 ** 64 - 1
98
- target = utils .zpad (utils .int_to_big_endian (2 ** 256 // (b .difficulty or 1 )), 32 )
98
+ target = utils .zpad (utils .int_to_big_endian (2 ** 256 // (self .block .difficulty or 1 )), 32 )
99
+ found = False
99
100
for i in range (1 , steps + 1 ):
100
- b .nonce = utils .zpad (utils .int_to_big_endian ((nonce + i ) & TT64M1 ), 8 )
101
- o = blocks .hashimoto_light (fsz , cache , b . mining_hash , b .nonce )
101
+ self . block .nonce = utils .zpad (utils .int_to_big_endian ((nonce + i ) & TT64M1 ), 8 )
102
+ o = blocks .hashimoto_light (fsz , cache , self . block . mining_hash , self . block .nonce )
102
103
if o ["result" ] <= target :
103
- b .mixhash = o ["mix digest" ]
104
+ self .block .mixhash = o ["mix digest" ]
105
+ found = True
104
106
break
105
107
steps -= 1
106
- if b . header . check_pow () :
107
- return self . block
108
+ if not found :
109
+ return False
108
110
109
- self .nonce = nonce
110
- return False
111
+ assert len (self .block .nonce ) == 8
112
+ assert len (self .block .mixhash ) == 32
113
+ assert self .block .header .check_pow ()
114
+ return self .block
0 commit comments