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

Commit 29c77b6

Browse files
committed
Fixed test chain
1 parent 360f6e1 commit 29c77b6

File tree

3 files changed

+32
-47
lines changed

3 files changed

+32
-47
lines changed

ethereum/chain.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -271,32 +271,31 @@ def add_transaction(self, transaction):
271271
assert self.head_candidate is not None
272272
_log = log.bind(tx_hash=transaction)
273273
_log.debug("add transaction")
274-
with self.lock:
275-
old_state_root = self.head_candidate.state_root
276-
# revert finalization
277-
self.head_candidate.state_root = self.pre_finalize_state_root
278-
try:
279-
success, output = processblock.apply_transaction(self.head_candidate, transaction)
280-
except processblock.InvalidTransaction as e:
281-
# if unsuccessful the prerequisites were not fullfilled
282-
# and the tx is invalid, state must not have changed
283-
log.debug('invalid tx', tx_hash=transaction, errors=e)
284-
success = False
285-
286-
# finalize
287-
self.pre_finalize_state_root = self.head_candidate.state_root
288-
self.head_candidate.finalize()
289-
290-
if not success:
291-
log.debug('tx not applied', tx_hash=transaction)
292-
assert old_state_root == self.head_candidate.state_root
293-
return False
294-
else:
295-
assert transaction in self.get_transactions()
296-
log.debug('transaction applied', tx_hash=transaction,
297-
block_hash=self.head_candidate, result=output)
298-
assert old_state_root != self.head_candidate.state_root
299-
return True
274+
old_state_root = self.head_candidate.state_root
275+
# revert finalization
276+
self.head_candidate.state_root = self.pre_finalize_state_root
277+
try:
278+
success, output = processblock.apply_transaction(self.head_candidate, transaction)
279+
except processblock.InvalidTransaction as e:
280+
# if unsuccessful the prerequisites were not fullfilled
281+
# and the tx is invalid, state must not have changed
282+
log.debug('invalid tx', tx_hash=transaction, errors=e)
283+
success = False
284+
285+
# finalize
286+
self.pre_finalize_state_root = self.head_candidate.state_root
287+
self.head_candidate.finalize()
288+
289+
if not success:
290+
log.debug('tx not applied', tx_hash=transaction)
291+
assert old_state_root == self.head_candidate.state_root
292+
return False
293+
else:
294+
assert transaction in self.get_transactions()
295+
log.debug('transaction applied', tx_hash=transaction,
296+
block_hash=self.head_candidate, result=output)
297+
assert old_state_root != self.head_candidate.state_root
298+
return True
300299

301300
def get_transactions(self):
302301
"""Get a list of new transactions not yet included in a mined block

ethereum/miner.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,17 @@ def mine(self, steps=1000):
6363
nonce = utils.big_endian_to_int(self.block.nonce)
6464
TT64M1 = 2**64 - 1
6565
target = utils.zpad(utils.int_to_big_endian(2**256 // (self.block.difficulty or 1)), 32)
66-
near_target = target[1:] + '\x00'
67-
dtarget = utils.big_endian_to_int(target)
6866
found = False
6967
sys.stderr.write("Starting mining\n")
70-
near_misses = 0
71-
start_time = time.time()
7268
for i in range(1, steps + 1):
7369
self.block.nonce = utils.zpad(utils.int_to_big_endian((nonce + i) & TT64M1), 8)
7470
o = blocks.hashimoto_light(fsz, cache, self.block.mining_hash,
7571
self.block.nonce)
76-
if o["result"] <= near_target:
77-
if o["result"] <= target:
78-
sys.stderr.write("Success!\n")
79-
self.block.mixhash = o["mix digest"]
80-
found = True
81-
break
82-
else:
83-
r = utils.big_endian_to_int(o["result"])
84-
near_misses += 1
85-
elapsed = time.time() - start_time
86-
sys.stderr.write('Near miss, %f %% of threshold! Elapsed: '
87-
'%f, estimated time remaining: %f\n' %
88-
(dtarget * 100.0 / r, elapsed,
89-
elapsed * 256. / near_misses))
90-
steps -= 1
72+
if o["result"] <= target:
73+
sys.stderr.write("Success!\n")
74+
self.block.mixhash = o["mix digest"]
75+
found = True
76+
break
9177
if not found:
9278
return False
9379

ethereum/tests/test_chain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def __contains__(self, key):
4141
@pytest.fixture(scope="module")
4242
def accounts():
4343
k = utils.sha3(b'cow')
44-
v = decode_hex(utils.privtoaddr(k))
44+
v = utils.privtoaddr(k)
4545
k2 = utils.sha3(b'horse')
46-
v2 = decode_hex(utils.privtoaddr(k2))
46+
v2 = utils.privtoaddr(k2)
4747
return k, v, k2, v2
4848

4949

0 commit comments

Comments
 (0)