Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Jan 12, 2018
1 parent 4f0b493 commit a8b3719
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
17 changes: 8 additions & 9 deletions evm/vm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions evm/vm/forks/byzantium/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@


EIP649_BLOCK_REWARD = 3 * denoms.ether

EIP658_TRANSACTION_STATUS_CODE_FAILURE = b'\x00'
EIP658_TRANSACTION_STATUS_CODE_SUCCESS = b'\x01'
11 changes: 10 additions & 1 deletion evm/vm/forks/byzantium/vm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
)
Expand Down
2 changes: 0 additions & 2 deletions evm/vm/forks/frontier/vm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
21 changes: 4 additions & 17 deletions evm/vm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a8b3719

Please sign in to comment.