Skip to content

Commit

Permalink
Relocate and rename AccountDB
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam committed Apr 30, 2018
1 parent 18f3b0f commit 18258e6
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 43 deletions.
8 changes: 4 additions & 4 deletions evm/db/state.py → evm/db/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from evm.db.immutable import (
ImmutableDB,
)
from evm.exceptions import DecommissionedStateDB
from evm.exceptions import DecommissionedAccountDB
from evm.rlp.accounts import (
Account,
)
Expand All @@ -49,7 +49,7 @@
account_cache = LRU(2048)


class BaseAccountStateDB(metaclass=ABCMeta):
class BaseAccountDB(metaclass=ABCMeta):

@abstractmethod
def __init__(self) -> None:
Expand Down Expand Up @@ -147,7 +147,7 @@ def clear(self) -> None:
raise NotImplementedError("Must be implemented by subclass")


class MainAccountStateDB(BaseAccountStateDB):
class AccountDB(BaseAccountDB):

def __init__(self, db, root_hash=BLANK_ROOT_HASH, read_only=False):
# Keep a reference to the original db instance to use it as part of _get_account()'s cache
Expand All @@ -162,7 +162,7 @@ def __init__(self, db, root_hash=BLANK_ROOT_HASH, read_only=False):
@property
def _trie(self):
if self.__trie is None:
raise DecommissionedStateDB()
raise DecommissionedAccountDB()
return self.__trie

@_trie.setter
Expand Down
12 changes: 6 additions & 6 deletions evm/db/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
from evm.db.journal import (
JournalDB,
)
from evm.db.state import (
BaseAccountStateDB,
MainAccountStateDB,
from evm.db.account import (
BaseAccountDB,
AccountDB,
)
from evm.rlp.headers import (
BlockHeader,
Expand Down Expand Up @@ -110,7 +110,7 @@ def set_trie(self, trie_class: Union[Type[HexaryTrie], Type[BinaryTrie]]) -> Non

def __init__(self,
db: BaseDB,
account_state_class: Type[BaseAccountStateDB] = MainAccountStateDB,
account_state_class: Type[BaseAccountDB] = AccountDB,
trie_class: Type[HexaryTrie] = HexaryTrie) -> None:

self.db = db
Expand Down Expand Up @@ -248,7 +248,7 @@ def persist_trie_data_dict(self, trie_data_dict: Dict[bytes, bytes]) -> None:
@abstractmethod
def get_state_db(self,
state_root: bytes,
read_only: bool) -> BaseAccountStateDB:
read_only: bool) -> BaseAccountDB:
raise NotImplementedError("ChainDB classes must implement this method")


Expand Down Expand Up @@ -573,7 +573,7 @@ def persist_trie_data_dict(self, trie_data_dict: Dict[bytes, bytes]) -> None:
#
def get_state_db(self,
state_root: bytes,
read_only: bool) -> BaseAccountStateDB:
read_only: bool) -> BaseAccountDB:
return self.account_state_class(
db=self.journal_db,
root_hash=state_root,
Expand Down
5 changes: 3 additions & 2 deletions evm/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class OutOfBoundsRead(VMError):
pass


class DecommissionedStateDB(Exception):
class DecommissionedAccountDB(Exception):
"""
Raised when an attempt was made to use a StateDB object used after leaving the context.
Raised when an attempt was made to use a AccountDB object used after
leaving the context.
"""
14 changes: 7 additions & 7 deletions evm/tools/test_builder/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
List,
)

from evm.db.state import (
MainAccountStateDB,
from evm.db.account import (
AccountDB,
)
from evm.tools.fixture_tests import (
hash_log_entries,
Expand Down Expand Up @@ -108,11 +108,11 @@ def get_default_transaction(networks):
]

ACCOUNT_STATE_DB_CLASSES = {
"Frontier": MainAccountStateDB,
"Homestead": MainAccountStateDB,
"EIP150": MainAccountStateDB,
"EIP158": MainAccountStateDB,
"Byzantium": MainAccountStateDB,
"Frontier": AccountDB,
"Homestead": AccountDB,
"EIP150": AccountDB,
"EIP158": AccountDB,
"Byzantium": AccountDB,
}
assert all(network in ACCOUNT_STATE_DB_CLASSES for network in ALL_NETWORKS)

Expand Down
6 changes: 3 additions & 3 deletions evm/vm/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
Address
)

from evm.db.state import (
BaseAccountStateDB
from evm.db.account import (
BaseAccountDB
)
from evm.constants import (
GAS_MEMORY,
Expand Down Expand Up @@ -372,7 +372,7 @@ def get_gas_remaining(self) -> int:
return self._gas_meter.gas_remaining

@contextmanager
def state_db(self, read_only: bool = False) -> Iterator[BaseAccountStateDB]:
def state_db(self, read_only: bool = False) -> Iterator[BaseAccountDB]:
with self.state.state_db(read_only) as state_db:
yield state_db

Expand Down
1 change: 0 additions & 1 deletion tests/core/chain-object/test_build_block_incrementally.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_building_block_incrementally_with_single_transaction(
funded_address,
funded_address_private_key):
head_hash = chain.get_canonical_head().hash

tx = new_transaction(
chain.get_vm(),
from_=funded_address,
Expand Down
4 changes: 2 additions & 2 deletions tests/core/vm/test_vm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
decode_hex,
)

from evm.exceptions import DecommissionedStateDB
from evm.exceptions import DecommissionedAccountDB
from evm.vm.forks.spurious_dragon.state import SpuriousDragonState

from tests.core.helpers import new_transaction
Expand Down Expand Up @@ -37,7 +37,7 @@ def test_state_db(state):
with state.mutable_state_db() as state_db:
pass

with pytest.raises(DecommissionedStateDB):
with pytest.raises(DecommissionedAccountDB):
state_db.increment_nonce(address)

state.read_only_state_db.get_balance(address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
)

from evm.db.backends.memory import MemoryDB
from evm.db.state import (
MainAccountStateDB,
from evm.db.account import (
AccountDB,
)

from evm.constants import (
Expand All @@ -24,7 +24,7 @@


@pytest.mark.parametrize("state", [
MainAccountStateDB(MemoryDB()),
AccountDB(MemoryDB()),
])
def test_balance(state):
assert state.get_balance(ADDRESS) == 0
Expand All @@ -50,7 +50,7 @@ def test_balance(state):


@pytest.mark.parametrize("state", [
MainAccountStateDB(MemoryDB()),
AccountDB(MemoryDB()),
])
def test_nonce(state):
assert state.get_nonce(ADDRESS) == 0
Expand All @@ -74,7 +74,7 @@ def test_nonce(state):


@pytest.mark.parametrize("state", [
MainAccountStateDB(MemoryDB()),
AccountDB(MemoryDB()),
])
def test_code(state):
assert state.get_code(ADDRESS) == b''
Expand All @@ -94,7 +94,7 @@ def test_code(state):


@pytest.mark.parametrize("state", [
MainAccountStateDB(MemoryDB()),
AccountDB(MemoryDB()),
])
def test_storage(state):
assert state.get_storage(ADDRESS, 0) == 0
Expand All @@ -117,7 +117,7 @@ def test_storage(state):


@pytest.mark.parametrize("state", [
MainAccountStateDB(MemoryDB()),
AccountDB(MemoryDB()),
])
def test_storage_deletion(state):
state.set_storage(ADDRESS, 0, 123)
Expand All @@ -131,7 +131,7 @@ def test_storage_deletion(state):


@pytest.mark.parametrize("state", [
MainAccountStateDB(MemoryDB()),
AccountDB(MemoryDB()),
])
def test_accounts(state):
assert not state.account_exists(ADDRESS)
Expand Down
8 changes: 4 additions & 4 deletions tests/database/test_chaindb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from evm.db.chain import (
ChainDB,
)
from evm.db.state import (
MainAccountStateDB,
from evm.db.account import (
AccountDB,
)
from evm.exceptions import (
BlockNotFound,
Expand Down Expand Up @@ -60,9 +60,9 @@ def set_empty_root(chaindb, header):
)


@pytest.fixture(params=[MainAccountStateDB])
@pytest.fixture(params=[AccountDB])
def chaindb(request):
if request.param is MainAccountStateDB:
if request.param is AccountDB:
trie_class = HexaryTrie
else:
trie_class = BinaryTrie
Expand Down
6 changes: 3 additions & 3 deletions tests/json-fixtures/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
)

from evm.db.chain import ChainDB
from evm.db.state import (
MainAccountStateDB,
from evm.db.account import (
AccountDB,
)
from evm.exceptions import (
ValidationError,
Expand Down Expand Up @@ -261,7 +261,7 @@ def fixture_vm_class(fixture_data):


def test_state_fixtures(fixture, fixture_vm_class):
account_state_class = MainAccountStateDB
account_state_class = AccountDB
trie_class = HexaryTrie
header = BlockHeader(
coinbase=fixture['env']['currentCoinbase'],
Expand Down
6 changes: 3 additions & 3 deletions tests/p2p/test_state_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import random

from evm.db.backends.memory import MemoryDB
from evm.db.state import MainAccountStateDB
from evm.db.account import AccountDB

from p2p.state import StateSync


def make_random_state(n):
state_db = MainAccountStateDB(MemoryDB())
state_db = AccountDB(MemoryDB())
contents = {}
for _ in range(n):
addr = os.urandom(20)
Expand Down Expand Up @@ -36,7 +36,7 @@ def test_state_sync():
results.append([request.node_key, state_db.db[request.node_key]])
scheduler.process(results)
requests = scheduler.next_batch(10)
dest_state = MainAccountStateDB(dest_db, state_db.root_hash)
dest_state = AccountDB(dest_db, state_db.root_hash)
for addr, account_data in contents.items():
balance, nonce, storage, code = account_data
assert dest_state.get_balance(addr) == balance
Expand Down

0 comments on commit 18258e6

Please sign in to comment.