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

Commit c58f1b7

Browse files
committed
fix: add_transaction
1 parent f89042b commit c58f1b7

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

ethereum/chain.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,6 @@ def add_transaction(self, transaction):
270270
if the transaction was invalid
271271
"""
272272
assert self.head_candidate is not None
273-
_log = log.bind(tx_hash=transaction)
274-
_log.debug("add transaction")
275273
old_state_root = self.head_candidate.state_root
276274
# revert finalization
277275
self.head_candidate.state_root = self.pre_finalize_state_root
@@ -283,20 +281,18 @@ def add_transaction(self, transaction):
283281
log.debug('invalid tx', tx_hash=transaction, errors=e)
284282
success = False
285283

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:
284+
if success:
295285
assert transaction in self.get_transactions()
296-
log.debug('transaction applied', tx_hash=transaction,
286+
self.pre_finalize_state_root = self.head_candidate.state_root
287+
self.head_candidate.finalize()
288+
log.debug('tx applied', tx_hash=transaction,
297289
block_hash=self.head_candidate, result=output)
298290
assert old_state_root != self.head_candidate.state_root
299291
return True
292+
else:
293+
log.debug('tx not applied', tx_hash=transaction)
294+
self.head_candidate.state_root = old_state_root # reset
295+
return False
300296

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

0 commit comments

Comments
 (0)