diff --git a/evm/vm/base.py b/evm/vm/base.py index 377af865d2..567c2ef25d 100644 --- a/evm/vm/base.py +++ b/evm/vm/base.py @@ -163,8 +163,7 @@ def import_block(self, block): def mine_block(self, *args, **kwargs): """ - Mine the current block. Proxies to the current block's mine method. - See example with FrontierBlock. :meth:`~evm.vm.forks.frontier.blocks.FrontierBlock.mine` + Mine the current block. Proxies to self.pack_block method. """ block = self.block self.pack_block(block, *args, **kwargs) @@ -460,18 +459,18 @@ def get_state_class(cls): return cls._state_class - def get_state(self, chaindb=None, block_header=None, prev_headers=None): + def get_state(self, chaindb=None, block_header=None): """Return state object """ if chaindb is None: chaindb = self.chaindb - if block_header is None: # TODO: remove + if block_header is None: block_header = self.block.header - if prev_headers is None: - prev_headers = self.get_prev_headers( - last_block_hash=self.block.header.parent_hash, - db=self.chaindb, - ) + + prev_headers = self.get_prev_headers( + last_block_hash=self.block.header.parent_hash, + db=self.chaindb, + ) receipts = self.block.get_receipts(self.chaindb) return self.get_state_class()( chaindb, diff --git a/evm/vm/forks/byzantium/constants.py b/evm/vm/forks/byzantium/constants.py index 4b4688dc82..579a78a232 100644 --- a/evm/vm/forks/byzantium/constants.py +++ b/evm/vm/forks/byzantium/constants.py @@ -7,3 +7,6 @@ EIP649_BLOCK_REWARD = 3 * denoms.ether + +EIP658_TRANSACTION_STATUS_CODE_FAILURE = b'\x00' +EIP658_TRANSACTION_STATUS_CODE_SUCCESS = b'\x01' diff --git a/evm/vm/forks/byzantium/vm_state.py b/evm/vm/forks/byzantium/vm_state.py index ec728ca451..17b4041bb9 100644 --- a/evm/vm/forks/byzantium/vm_state.py +++ b/evm/vm/forks/byzantium/vm_state.py @@ -5,6 +5,10 @@ from evm.vm.forks.spurious_dragon.vm_state import SpuriousDragonVMState from .computation import ByzantiumComputation +from .constants import ( + EIP658_TRANSACTION_STATUS_CODE_FAILURE, + EIP658_TRANSACTION_STATUS_CODE_SUCCESS, +) class ByzantiumVMState(SpuriousDragonVMState): @@ -13,8 +17,13 @@ class ByzantiumVMState(SpuriousDragonVMState): def make_receipt(self, transaction, computation): old_receipt = _make_frontier_receipt(self, transaction, computation) + if computation.is_error: + state_root = EIP658_TRANSACTION_STATUS_CODE_FAILURE + else: + state_root = EIP658_TRANSACTION_STATUS_CODE_SUCCESS + receipt = Receipt( - state_root=b'' if computation.is_error else b'\x01', + state_root=state_root, gas_used=old_receipt.gas_used, logs=old_receipt.logs, ) diff --git a/evm/vm/forks/frontier/vm_state.py b/evm/vm/forks/frontier/vm_state.py index c160dd199f..612323877f 100644 --- a/evm/vm/forks/frontier/vm_state.py +++ b/evm/vm/forks/frontier/vm_state.py @@ -248,8 +248,6 @@ def validate_block(self, block): ) ) - # XXX: Should these and some other checks be moved into - # VM.validate_block(), as they apply to all block flavours? if len(block.uncles) > MAX_UNCLES: raise ValidationError( "Blocks may have a maximum of {0} uncles. Found " diff --git a/evm/vm_state.py b/evm/vm_state.py index 5a2cebf96c..edd60a74cd 100644 --- a/evm/vm_state.py +++ b/evm/vm_state.py @@ -77,16 +77,6 @@ def difficulty(self): def gas_limit(self): return self.block_header.gas_limit - # - # chaindb - # - # @property - # def chaindb(self): - # return self._chaindb - - def set_chaindb(self, db): - self._chaindb = db - # # state_db # @@ -132,8 +122,8 @@ def revert(self, snapshot): with self.state_db() as state_db: # first revert the database state root. state_db.root_hash = state_root - # now roll the underlying database back + # now roll the underlying database back self._chaindb.revert(checkpoint_id) def commit(self, snapshot): @@ -205,11 +195,9 @@ def apply_transaction( """ Apply transaction to the given block - :param vm_state: the VMState object :param transaction: the transaction need to be applied :param block: the block which the transaction applies on - :param is_stateless: if is_stateless, call VMState.add_transactionto set block - :type vm_state: VMState + :param is_stateless: if is_stateless, call self.add_transaction to set block :type transaction: Transaction :type block: Block :type is_stateless: bool @@ -234,16 +222,15 @@ def apply_transaction( def add_transaction(self, transaction, computation, block): """ - Add a transaction to the given block and save the block data into chaindb. + Add a transaction to the given block and + return `trie_data` to store the transaction data in chaindb in VM layer. Update the bloom_filter, transaction trie and receipt trie roots, bloom_filter, bloom, and used_gas of the block. - :param vm_state: the VMState object :param transaction: the executed transaction :param computation: the Computation object with executed result :param block: the Block which the transaction is added in - :type vm_state: VMState :type transaction: Transaction :type computation: Computation :type block: Block