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

Commit 034a0a8

Browse files
committed
fix: tx validation and success mix-up
1 parent c8d0777 commit 034a0a8

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

ethereum/chain.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,31 +294,29 @@ def add_transaction(self, transaction):
294294
# if unsuccessful the prerequisites were not fullfilled
295295
# and the tx is invalid, state must not have changed
296296
log.debug('invalid tx', error=e)
297-
success = False
297+
assert transaction not in self.get_transactions()
298+
head_candidate.state_root = old_state_root # reset
299+
return False
300+
301+
log.debug('valid tx')
298302

299303
# we might have a new head_candidate (due to ctx switches in pyethapp)
300304
if self.head_candidate != head_candidate:
301305
log.debug('head_candidate changed during validation, trying again')
302306
self.add_transaction(transaction)
303307
return
304308

305-
if success:
306-
assert transaction in self.get_transactions()
307-
self.pre_finalize_state_root = head_candidate.state_root
308-
head_candidate.finalize()
309-
log.debug('tx applied', result=output)
310-
assert old_state_root != head_candidate.state_root
311-
return True
312-
else:
313-
log.debug('tx failed')
314-
head_candidate.state_root = old_state_root # reset
315-
return False
309+
assert transaction in self.get_transactions()
310+
self.pre_finalize_state_root = head_candidate.state_root
311+
head_candidate.finalize()
312+
log.debug('tx applied', result=output)
313+
assert old_state_root != head_candidate.state_root
314+
return True
316315

317316
def get_transactions(self):
318317
"""Get a list of new transactions not yet included in a mined block
319318
but known to the chain.
320319
"""
321-
log.debug("get_transactions called")
322320
if self.head_candidate:
323321
return self.head_candidate.get_transactions()
324322
else:

0 commit comments

Comments
 (0)