Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 633aa1d

Browse files
committed
PoW checking fixes
1 parent 6b1c094 commit 633aa1d

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

ethereum/blocks.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def seed(self):
330330
seed = utils.sha3(seed)
331331
return seed
332332

333-
def check_pow(self, db=None, nonce=None):
333+
def check_pow(self, nonce=None, debugmode=False):
334334
"""Check if the proof-of-work of the block is valid.
335335
336336
:param nonce: if given the proof of work function will be evaluated
@@ -339,9 +339,6 @@ def check_pow(self, db=None, nonce=None):
339339
:returns: `True` or `False`
340340
"""
341341
nonce = nonce or self.nonce
342-
if db is None:
343-
assert self.block is not None
344-
db = self.block.db
345342
if len(self.mixhash) != 32 or len(self.nonce) != 8:
346343
raise ValueError("Bad mixhash or nonce length")
347344
# exclude mixhash and nonce
@@ -354,6 +351,11 @@ def check_pow(self, db=None, nonce=None):
354351
current_full_size = get_full_size(self.number)
355352
mining_output = hashimoto_light(current_full_size, cache, header_hash, nonce)
356353
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'])
357359
if mining_output['mix digest'] != self.mixhash:
358360
return False
359361
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,
552554
raise ValueError("State Merkle root of block %r not found in "
553555
"database" % self)
554556
if (not self.is_genesis() and self.nonce and
555-
not self.header.check_pow(self.db)):
557+
not self.header.check_pow()):
556558
raise ValueError("PoW check failed")
557559
self.db.put('validated:'+self.hash, '1')
558560

@@ -673,7 +675,7 @@ def validate_uncles(self, db=None):
673675
ineligible.extend([b.header for b in ancestor_chain])
674676
eligible_ancestor_hashes = [x.hash for x in ancestor_chain[2:]]
675677
for uncle in self.uncles:
676-
if not uncle.check_pow(db=db):
678+
if not uncle.check_pow():
677679
return False
678680
if uncle.prevhash not in eligible_ancestor_hashes:
679681
log.error("Uncle does not have a valid ancestor", block=self,

ethereum/chain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def _update_head(self, block):
158158
uncles.discard(self.get(u))
159159
if blk.has_parent():
160160
blk = blk.get_parent()
161-
uncles = list(uncles)
161+
# TODO: make this work
162+
uncles = list(uncles)[:0]
162163
ts = max(int(time.time()), block.timestamp + 1)
163164
self.head_candidate = blocks.Block.init_from_parent(block, coinbase=self._coinbase,
164165
timestamp=ts, uncles=uncles)

ethereum/tests/benchmark_db.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ def benchmark(size):
88
t.update(utils.sha3('k'+str(i)), utils.sha3('v'+str(i)))
99
sz = sum([len(v) for k, v in t.db.db.items()])
1010
nsz = []
11+
ldb = db.ListeningDB(t.db.db)
1112
for i in range(min(size, 100)):
12-
ldb = db.ListeningDB(t.db.db)
13+
ldb2 = db.ListeningDB(ldb)
1314
odb = t.db
14-
t.db = ldb
15+
t.db = ldb2
1516
t.get(utils.sha3('k'+str(i)))
16-
nsz.append(sum([len(v) for k, v in ldb.kv.items()]))
17+
nsz.append(sum([len(v) for k, v in ldb2.kv.items()]))
1718
t.db = odb
18-
print sz, sum(nsz) // len(nsz)
19+
ldbsz = sum([len(v) for k, v in ldb.kv.items()])
20+
print sz, sum(nsz) // len(nsz), ldbsz
1921

2022
benchmark(int(sys.argv[1]) if len(sys.argv) > 1 else 1000)

0 commit comments

Comments
 (0)