Skip to content

Commit 2c584ed

Browse files
SamWilsnnerolation
authored andcommitted
update storage trie type (ethereum#1070 ethereum#1071)
1 parent b151dfe commit 2c584ed

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/ethereum/prague/state.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from dataclasses import dataclass, field
2020
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple
2121

22-
from ethereum_types.bytes import Bytes
22+
from ethereum_types.bytes import Bytes, Bytes32
2323
from ethereum_types.frozen import modify
2424
from ethereum_types.numeric import U256, Uint
2525

@@ -37,12 +37,13 @@ class State:
3737
_main_trie: Trie[Address, Optional[Account]] = field(
3838
default_factory=lambda: Trie(secured=True, default=None)
3939
)
40-
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
40+
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
4141
default_factory=dict
4242
)
4343
_snapshots: List[
4444
Tuple[
45-
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
45+
Trie[Address, Optional[Account]],
46+
Dict[Address, Trie[Bytes32, U256]],
4647
]
4748
] = field(default_factory=list)
4849
created_accounts: Set[Address] = field(default_factory=set)
@@ -55,8 +56,8 @@ class TransientStorage:
5556
within a transaction.
5657
"""
5758

58-
_tries: Dict[Address, Trie[Bytes, U256]] = field(default_factory=dict)
59-
_snapshots: List[Dict[Address, Trie[Bytes, U256]]] = field(
59+
_tries: Dict[Address, Trie[Bytes32, U256]] = field(default_factory=dict)
60+
_snapshots: List[Dict[Address, Trie[Bytes32, U256]]] = field(
6061
default_factory=list
6162
)
6263

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

263264

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

292293

293294
def set_storage(
294-
state: State, address: Address, key: Bytes, value: U256
295+
state: State, address: Address, key: Bytes32, value: U256
295296
) -> None:
296297
"""
297298
Set a value at a storage key on an account. Setting to `U256(0)` deletes
@@ -626,7 +627,7 @@ def write_code(sender: Account) -> None:
626627
modify_state(state, address, write_code)
627628

628629

629-
def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
630+
def get_storage_original(state: State, address: Address, key: Bytes32) -> U256:
630631
"""
631632
Get the original value in a storage slot i.e. the value before the current
632633
transaction began. This function reads the value from the snapshots taken
@@ -660,7 +661,7 @@ def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
660661

661662

662663
def get_transient_storage(
663-
transient_storage: TransientStorage, address: Address, key: Bytes
664+
transient_storage: TransientStorage, address: Address, key: Bytes32
664665
) -> U256:
665666
"""
666667
Get a value at a storage key on an account from transient storage.
@@ -691,7 +692,7 @@ def get_transient_storage(
691692
def set_transient_storage(
692693
transient_storage: TransientStorage,
693694
address: Address,
694-
key: Bytes,
695+
key: Bytes32,
695696
value: U256,
696697
) -> None:
697698
"""

src/ethereum_optimized/state_db.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"package"
2727
)
2828

29-
from ethereum_types.bytes import Bytes, Bytes20
29+
from ethereum_types.bytes import Bytes, Bytes20, Bytes32
3030
from ethereum_types.numeric import U256, Uint
3131

3232
from ethereum.crypto.hash import Hash32
@@ -76,7 +76,7 @@ class State:
7676

7777
db: Any
7878
dirty_accounts: Dict[Address, Optional[Account_]]
79-
dirty_storage: Dict[Address, Dict[Bytes, U256]]
79+
dirty_storage: Dict[Address, Dict[Bytes32, U256]]
8080
destroyed_accounts: Set[Address]
8181
tx_restore_points: List[int]
8282
journal: List[Any]
@@ -328,7 +328,7 @@ def rollback_transaction(state: State) -> None:
328328
_rollback_transaction(state)
329329

330330
@add_item(patches)
331-
def get_storage(state: State, address: Address, key: Bytes) -> U256:
331+
def get_storage(state: State, address: Address, key: Bytes32) -> U256:
332332
"""
333333
See `state`.
334334
"""
@@ -345,7 +345,7 @@ def get_storage(state: State, address: Address, key: Bytes) -> U256:
345345

346346
@add_item(patches)
347347
def get_storage_original(
348-
state: State, address: Address, key: Bytes
348+
state: State, address: Address, key: Bytes32
349349
) -> U256:
350350
"""
351351
See `state`.
@@ -357,7 +357,7 @@ def get_storage_original(
357357

358358
@add_item(patches)
359359
def set_storage(
360-
state: State, address: Address, key: Bytes, value: U256
360+
state: State, address: Address, key: Bytes32, value: U256
361361
) -> None:
362362
"""
363363
See `state`.

0 commit comments

Comments
 (0)