@@ -330,7 +330,7 @@ def seed(self):
330
330
seed = utils .sha3 (seed )
331
331
return seed
332
332
333
- def check_pow (self , db = None , nonce = None ):
333
+ def check_pow (self , nonce = None , debugmode = False ):
334
334
"""Check if the proof-of-work of the block is valid.
335
335
336
336
:param nonce: if given the proof of work function will be evaluated
@@ -339,9 +339,6 @@ def check_pow(self, db=None, nonce=None):
339
339
:returns: `True` or `False`
340
340
"""
341
341
nonce = nonce or self .nonce
342
- if db is None :
343
- assert self .block is not None
344
- db = self .block .db
345
342
if len (self .mixhash ) != 32 or len (self .nonce ) != 8 :
346
343
raise ValueError ("Bad mixhash or nonce length" )
347
344
# exclude mixhash and nonce
@@ -354,6 +351,11 @@ def check_pow(self, db=None, nonce=None):
354
351
current_full_size = get_full_size (self .number )
355
352
mining_output = hashimoto_light (current_full_size , cache , header_hash , nonce )
356
353
diff = self .difficulty
354
+ if debugmode :
355
+ print 'Mining hash: %s' % encode_hex (header_hash )
356
+ print 'Seed: %s' % encode_hex (seed )
357
+ print 'Mixhash: %s' % encode_hex (mining_output ['mix digest' ])
358
+ print 'Result: %s' % encode_hex (mining_output ['result' ])
357
359
if mining_output ['mix digest' ] != self .mixhash :
358
360
return False
359
361
return utils .big_endian_to_int (mining_output ['result' ]) <= 2 ** 256 / (diff or 1 )
@@ -552,7 +554,7 @@ def __init__(self, header, transaction_list=[], uncles=[], db=None,
552
554
raise ValueError ("State Merkle root of block %r not found in "
553
555
"database" % self )
554
556
if (not self .is_genesis () and self .nonce and
555
- not self .header .check_pow (self . db )):
557
+ not self .header .check_pow ()):
556
558
raise ValueError ("PoW check failed" )
557
559
self .db .put ('validated:' + self .hash , '1' )
558
560
@@ -673,7 +675,7 @@ def validate_uncles(self, db=None):
673
675
ineligible .extend ([b .header for b in ancestor_chain ])
674
676
eligible_ancestor_hashes = [x .hash for x in ancestor_chain [2 :]]
675
677
for uncle in self .uncles :
676
- if not uncle .check_pow (db = db ):
678
+ if not uncle .check_pow ():
677
679
return False
678
680
if uncle .prevhash not in eligible_ancestor_hashes :
679
681
log .error ("Uncle does not have a valid ancestor" , block = self ,
0 commit comments