Skip to content

Commit

Permalink
Merge branch 'master' into piper/remove-multi-trie-support
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam authored Apr 30, 2018
2 parents 48d09d8 + e6f6a7a commit f3183af
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
6 changes: 5 additions & 1 deletion evm/chains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
from evm.rlp.headers import (
BlockHeader,
)
from evm.utils.db import (
apply_state_dict,
)
from evm.utils.chain import (
generate_vms_by_range,
)
Expand Down Expand Up @@ -439,7 +442,8 @@ def from_genesis(cls,
if genesis_state is None:
genesis_state = {}

state_db.apply_state_dict(genesis_state)
# mutation
apply_state_dict(state_db, genesis_state)

if 'state_root' not in genesis_params:
# If the genesis state_root was not specified, use the value
Expand Down
13 changes: 0 additions & 13 deletions evm/db/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def __init__(self) -> None:
"Must be implemented by subclasses"
)

@abstractmethod
def apply_state_dict(self, state_dict):
raise NotImplementedError("Must be implemented by subclasses")

@abstractmethod
def decommission(self):
raise NotImplementedError("Must be implemented by subclasses")
Expand Down Expand Up @@ -167,15 +163,6 @@ def _trie(self):
def _trie(self, value):
self.__trie = value

def apply_state_dict(self, state_dict):
for account, account_data in state_dict.items():
self.set_balance(account, account_data["balance"])
self.set_nonce(account, account_data["nonce"])
self.set_code(account, account_data["code"])

for slot, value in account_data["storage"].items():
self.set_storage(account, slot, value)

def decommission(self):
self.db = None
self.__trie = None
Expand Down
6 changes: 5 additions & 1 deletion evm/tools/test_builder/builder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
to_text,
int_to_big_endian,
)

from evm.utils.db import (
apply_state_dict,
)
from evm.utils.padding import (
pad32,
)
Expand Down Expand Up @@ -111,7 +115,7 @@ def get_version_from_git():

def calc_state_root(state, account_state_db_class):
state_db = account_state_db_class(MemoryDB())
state_db.apply_state_dict(state)
apply_state_dict(state_db, state)
return state_db.root_hash


Expand Down
12 changes: 12 additions & 0 deletions evm/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ def get_block_header_by_hash(block_hash: BlockHeader, db: 'BaseChainDB') -> Bloc
Returns the header for the parent block.
"""
return db.get_block_header_by_hash(block_hash)


def apply_state_dict(account_db, state_dict):
for account, account_data in state_dict.items():
account_db.set_balance(account, account_data["balance"])
account_db.set_nonce(account, account_data["nonce"])
account_db.set_code(account, account_data["code"])

for slot, value in account_data["storage"].items():
account_db.set_storage(account, slot, value)

return account_db
5 changes: 4 additions & 1 deletion tests/json-fixtures/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
normalize_statetest_fixture,
should_run_slow_tests,
)
from evm.utils.db import (
apply_state_dict,
)

from eth_typing.enums import (
ForkName
Expand Down Expand Up @@ -270,7 +273,7 @@ def test_state_fixtures(fixture, fixture_vm_class):

state = vm.state
with state.mutable_state_db() as state_db:
state_db.apply_state_dict(fixture['pre'])
apply_state_dict(state_db, fixture['pre'])
# Update state_root manually
vm.block = vm.block.copy(header=vm.block.header.copy(state_root=state.state_root))
if 'secretKey' in fixture['transaction']:
Expand Down

0 comments on commit f3183af

Please sign in to comment.