Skip to content

Commit

Permalink
dev: update storage trie type
Browse files Browse the repository at this point in the history
  • Loading branch information
cairolover committed Jan 6, 2025
1 parent 4c7eaa8 commit 338b3cb
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 97 deletions.
13 changes: 7 additions & 6 deletions src/ethereum/arrow_glacier/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass, field
from typing import Callable, Dict, List, Optional, Set, Tuple

from ethereum_types.bytes import Bytes
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
from ethereum_types.numeric import U256, Uint

Expand All @@ -36,12 +36,13 @@ class State:
_main_trie: Trie[Address, Optional[Account]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
default_factory=dict
)
_snapshots: List[
Tuple[
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
Trie[Address, Optional[Account]],
Dict[Address, Trie[Bytes32, U256]],
]
] = field(default_factory=list)
created_accounts: Set[Address] = field(default_factory=set)
Expand Down Expand Up @@ -228,7 +229,7 @@ def mark_account_created(state: State, address: Address) -> None:
state.created_accounts.add(address)


def get_storage(state: State, address: Address, key: Bytes) -> U256:
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
"""
Get a value at a storage key on an account. Returns `U256(0)` if the
storage key has not been set previously.
Expand Down Expand Up @@ -258,7 +259,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:


def set_storage(
state: State, address: Address, key: Bytes, value: U256
state: State, address: Address, key: Bytes32, value: U256
) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
Expand Down Expand Up @@ -580,7 +581,7 @@ def increase_balance(account: Account) -> None:
modify_state(state, address, increase_balance)


def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
def get_storage_original(state: State, address: Address, key: Bytes32) -> U256:
"""
Get the original value in a storage slot i.e. the value before the current
transaction began. This function reads the value from the snapshots taken
Expand Down
13 changes: 7 additions & 6 deletions src/ethereum/berlin/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass, field
from typing import Callable, Dict, List, Optional, Set, Tuple

from ethereum_types.bytes import Bytes
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
from ethereum_types.numeric import U256, Uint

Expand All @@ -36,12 +36,13 @@ class State:
_main_trie: Trie[Address, Optional[Account]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
default_factory=dict
)
_snapshots: List[
Tuple[
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
Trie[Address, Optional[Account]],
Dict[Address, Trie[Bytes32, U256]],
]
] = field(default_factory=list)
created_accounts: Set[Address] = field(default_factory=set)
Expand Down Expand Up @@ -228,7 +229,7 @@ def mark_account_created(state: State, address: Address) -> None:
state.created_accounts.add(address)


def get_storage(state: State, address: Address, key: Bytes) -> U256:
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
"""
Get a value at a storage key on an account. Returns `U256(0)` if the
storage key has not been set previously.
Expand Down Expand Up @@ -258,7 +259,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:


def set_storage(
state: State, address: Address, key: Bytes, value: U256
state: State, address: Address, key: Bytes32, value: U256
) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
Expand Down Expand Up @@ -580,7 +581,7 @@ def increase_balance(account: Account) -> None:
modify_state(state, address, increase_balance)


def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
def get_storage_original(state: State, address: Address, key: Bytes32) -> U256:
"""
Get the original value in a storage slot i.e. the value before the current
transaction began. This function reads the value from the snapshots taken
Expand Down
11 changes: 6 additions & 5 deletions src/ethereum/byzantium/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass, field
from typing import Callable, Dict, List, Optional, Tuple

from ethereum_types.bytes import Bytes
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
from ethereum_types.numeric import U256, Uint

Expand All @@ -36,12 +36,13 @@ class State:
_main_trie: Trie[Address, Optional[Account]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
default_factory=dict
)
_snapshots: List[
Tuple[
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
Trie[Address, Optional[Account]],
Dict[Address, Trie[Bytes32, U256]],
]
] = field(default_factory=list)

Expand Down Expand Up @@ -202,7 +203,7 @@ def destroy_storage(state: State, address: Address) -> None:
del state._storage_tries[address]


def get_storage(state: State, address: Address, key: Bytes) -> U256:
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
"""
Get a value at a storage key on an account. Returns `U256(0)` if the
storage key has not been set previously.
Expand Down Expand Up @@ -232,7 +233,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:


def set_storage(
state: State, address: Address, key: Bytes, value: U256
state: State, address: Address, key: Bytes32, value: U256
) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
Expand Down
21 changes: 11 additions & 10 deletions src/ethereum/cancun/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass, field
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple

from ethereum_types.bytes import Bytes
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
from ethereum_types.numeric import U256, Uint

Expand All @@ -37,12 +37,13 @@ class State:
_main_trie: Trie[Address, Optional[Account]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
default_factory=dict
)
_snapshots: List[
Tuple[
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
Trie[Address, Optional[Account]],
Dict[Address, Trie[Bytes32, U256]],
]
] = field(default_factory=list)
created_accounts: Set[Address] = field(default_factory=set)
Expand All @@ -55,8 +56,8 @@ class TransientStorage:
within a transaction.
"""

_tries: Dict[Address, Trie[Bytes, U256]] = field(default_factory=dict)
_snapshots: List[Dict[Address, Trie[Bytes, U256]]] = field(
_tries: Dict[Address, Trie[Bytes32, U256]] = field(default_factory=dict)
_snapshots: List[Dict[Address, Trie[Bytes32, U256]]] = field(
default_factory=list
)

Expand Down Expand Up @@ -261,7 +262,7 @@ def mark_account_created(state: State, address: Address) -> None:
state.created_accounts.add(address)


def get_storage(state: State, address: Address, key: Bytes) -> U256:
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
"""
Get a value at a storage key on an account. Returns `U256(0)` if the
storage key has not been set previously.
Expand Down Expand Up @@ -291,7 +292,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:


def set_storage(
state: State, address: Address, key: Bytes, value: U256
state: State, address: Address, key: Bytes32, value: U256
) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
Expand Down Expand Up @@ -607,7 +608,7 @@ def write_code(sender: Account) -> None:
modify_state(state, address, write_code)


def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
def get_storage_original(state: State, address: Address, key: Bytes32) -> U256:
"""
Get the original value in a storage slot i.e. the value before the current
transaction began. This function reads the value from the snapshots taken
Expand Down Expand Up @@ -641,7 +642,7 @@ def get_storage_original(state: State, address: Address, key: Bytes) -> U256:


def get_transient_storage(
transient_storage: TransientStorage, address: Address, key: Bytes
transient_storage: TransientStorage, address: Address, key: Bytes32
) -> U256:
"""
Get a value at a storage key on an account from transient storage.
Expand Down Expand Up @@ -672,7 +673,7 @@ def get_transient_storage(
def set_transient_storage(
transient_storage: TransientStorage,
address: Address,
key: Bytes,
key: Bytes32,
value: U256,
) -> None:
"""
Expand Down
11 changes: 6 additions & 5 deletions src/ethereum/constantinople/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass, field
from typing import Callable, Dict, List, Optional, Tuple

from ethereum_types.bytes import Bytes
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
from ethereum_types.numeric import U256, Uint

Expand All @@ -36,12 +36,13 @@ class State:
_main_trie: Trie[Address, Optional[Account]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
default_factory=dict
)
_snapshots: List[
Tuple[
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
Trie[Address, Optional[Account]],
Dict[Address, Trie[Bytes32, U256]],
]
] = field(default_factory=list)

Expand Down Expand Up @@ -202,7 +203,7 @@ def destroy_storage(state: State, address: Address) -> None:
del state._storage_tries[address]


def get_storage(state: State, address: Address, key: Bytes) -> U256:
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
"""
Get a value at a storage key on an account. Returns `U256(0)` if the
storage key has not been set previously.
Expand Down Expand Up @@ -232,7 +233,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:


def set_storage(
state: State, address: Address, key: Bytes, value: U256
state: State, address: Address, key: Bytes32, value: U256
) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
Expand Down
11 changes: 6 additions & 5 deletions src/ethereum/dao_fork/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass, field
from typing import Callable, Dict, List, Optional, Tuple

from ethereum_types.bytes import Bytes
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
from ethereum_types.numeric import U256, Uint

Expand All @@ -36,12 +36,13 @@ class State:
_main_trie: Trie[Address, Optional[Account]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
default_factory=dict
)
_snapshots: List[
Tuple[
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
Trie[Address, Optional[Account]],
Dict[Address, Trie[Bytes32, U256]],
]
] = field(default_factory=list)

Expand Down Expand Up @@ -202,7 +203,7 @@ def destroy_storage(state: State, address: Address) -> None:
del state._storage_tries[address]


def get_storage(state: State, address: Address, key: Bytes) -> U256:
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
"""
Get a value at a storage key on an account. Returns `U256(0)` if the
storage key has not been set previously.
Expand Down Expand Up @@ -232,7 +233,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:


def set_storage(
state: State, address: Address, key: Bytes, value: U256
state: State, address: Address, key: Bytes32, value: U256
) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
Expand Down
11 changes: 6 additions & 5 deletions src/ethereum/frontier/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dataclasses import dataclass, field
from typing import Callable, Dict, List, Optional, Tuple

from ethereum_types.bytes import Bytes
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
from ethereum_types.numeric import U256, Uint

Expand All @@ -36,12 +36,13 @@ class State:
_main_trie: Trie[Address, Optional[Account]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
default_factory=dict
)
_snapshots: List[
Tuple[
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
Trie[Address, Optional[Account]],
Dict[Address, Trie[Bytes32, U256]],
]
] = field(default_factory=list)

Expand Down Expand Up @@ -202,7 +203,7 @@ def destroy_storage(state: State, address: Address) -> None:
del state._storage_tries[address]


def get_storage(state: State, address: Address, key: Bytes) -> U256:
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
"""
Get a value at a storage key on an account. Returns `U256(0)` if the
storage key has not been set previously.
Expand Down Expand Up @@ -232,7 +233,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:


def set_storage(
state: State, address: Address, key: Bytes, value: U256
state: State, address: Address, key: Bytes32, value: U256
) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
Expand Down
Loading

0 comments on commit 338b3cb

Please sign in to comment.