Skip to content

Commit d9febcb

Browse files
authored
dev: update storage trie type (#1071)
* dev: update storage trie type * update type in state_db
1 parent 26ab1bc commit d9febcb

File tree

17 files changed

+114
-98
lines changed

17 files changed

+114
-98
lines changed

src/ethereum/arrow_glacier/state.py

Lines changed: 7 additions & 6 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, 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

@@ -36,12 +36,13 @@ class State:
3636
_main_trie: Trie[Address, Optional[Account]] = field(
3737
default_factory=lambda: Trie(secured=True, default=None)
3838
)
39-
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
39+
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
4040
default_factory=dict
4141
)
4242
_snapshots: List[
4343
Tuple[
44-
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
44+
Trie[Address, Optional[Account]],
45+
Dict[Address, Trie[Bytes32, U256]],
4546
]
4647
] = field(default_factory=list)
4748
created_accounts: Set[Address] = field(default_factory=set)
@@ -228,7 +229,7 @@ def mark_account_created(state: State, address: Address) -> None:
228229
state.created_accounts.add(address)
229230

230231

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

259260

260261
def set_storage(
261-
state: State, address: Address, key: Bytes, value: U256
262+
state: State, address: Address, key: Bytes32, value: U256
262263
) -> None:
263264
"""
264265
Set a value at a storage key on an account. Setting to `U256(0)` deletes
@@ -599,7 +600,7 @@ def increase_balance(account: Account) -> None:
599600
modify_state(state, address, increase_balance)
600601

601602

602-
def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
603+
def get_storage_original(state: State, address: Address, key: Bytes32) -> U256:
603604
"""
604605
Get the original value in a storage slot i.e. the value before the current
605606
transaction began. This function reads the value from the snapshots taken

src/ethereum/berlin/state.py

Lines changed: 7 additions & 6 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, 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

@@ -36,12 +36,13 @@ class State:
3636
_main_trie: Trie[Address, Optional[Account]] = field(
3737
default_factory=lambda: Trie(secured=True, default=None)
3838
)
39-
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
39+
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
4040
default_factory=dict
4141
)
4242
_snapshots: List[
4343
Tuple[
44-
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
44+
Trie[Address, Optional[Account]],
45+
Dict[Address, Trie[Bytes32, U256]],
4546
]
4647
] = field(default_factory=list)
4748
created_accounts: Set[Address] = field(default_factory=set)
@@ -228,7 +229,7 @@ def mark_account_created(state: State, address: Address) -> None:
228229
state.created_accounts.add(address)
229230

230231

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

259260

260261
def set_storage(
261-
state: State, address: Address, key: Bytes, value: U256
262+
state: State, address: Address, key: Bytes32, value: U256
262263
) -> None:
263264
"""
264265
Set a value at a storage key on an account. Setting to `U256(0)` deletes
@@ -599,7 +600,7 @@ def increase_balance(account: Account) -> None:
599600
modify_state(state, address, increase_balance)
600601

601602

602-
def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
603+
def get_storage_original(state: State, address: Address, key: Bytes32) -> U256:
603604
"""
604605
Get the original value in a storage slot i.e. the value before the current
605606
transaction began. This function reads the value from the snapshots taken

src/ethereum/byzantium/state.py

Lines changed: 6 additions & 5 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, List, Optional, 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

@@ -36,12 +36,13 @@ class State:
3636
_main_trie: Trie[Address, Optional[Account]] = field(
3737
default_factory=lambda: Trie(secured=True, default=None)
3838
)
39-
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
39+
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
4040
default_factory=dict
4141
)
4242
_snapshots: List[
4343
Tuple[
44-
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
44+
Trie[Address, Optional[Account]],
45+
Dict[Address, Trie[Bytes32, U256]],
4546
]
4647
] = field(default_factory=list)
4748

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

204205

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

233234

234235
def set_storage(
235-
state: State, address: Address, key: Bytes, value: U256
236+
state: State, address: Address, key: Bytes32, value: U256
236237
) -> None:
237238
"""
238239
Set a value at a storage key on an account. Setting to `U256(0)` deletes

src/ethereum/cancun/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/constantinople/state.py

Lines changed: 6 additions & 5 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, List, Optional, 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

@@ -36,12 +36,13 @@ class State:
3636
_main_trie: Trie[Address, Optional[Account]] = field(
3737
default_factory=lambda: Trie(secured=True, default=None)
3838
)
39-
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
39+
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
4040
default_factory=dict
4141
)
4242
_snapshots: List[
4343
Tuple[
44-
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
44+
Trie[Address, Optional[Account]],
45+
Dict[Address, Trie[Bytes32, U256]],
4546
]
4647
] = field(default_factory=list)
4748

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

204205

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

233234

234235
def set_storage(
235-
state: State, address: Address, key: Bytes, value: U256
236+
state: State, address: Address, key: Bytes32, value: U256
236237
) -> None:
237238
"""
238239
Set a value at a storage key on an account. Setting to `U256(0)` deletes

src/ethereum/dao_fork/state.py

Lines changed: 6 additions & 5 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, List, Optional, 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

@@ -36,12 +36,13 @@ class State:
3636
_main_trie: Trie[Address, Optional[Account]] = field(
3737
default_factory=lambda: Trie(secured=True, default=None)
3838
)
39-
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
39+
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
4040
default_factory=dict
4141
)
4242
_snapshots: List[
4343
Tuple[
44-
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
44+
Trie[Address, Optional[Account]],
45+
Dict[Address, Trie[Bytes32, U256]],
4546
]
4647
] = field(default_factory=list)
4748

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

204205

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

233234

234235
def set_storage(
235-
state: State, address: Address, key: Bytes, value: U256
236+
state: State, address: Address, key: Bytes32, value: U256
236237
) -> None:
237238
"""
238239
Set a value at a storage key on an account. Setting to `U256(0)` deletes

src/ethereum/frontier/state.py

Lines changed: 6 additions & 5 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, List, Optional, 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

@@ -36,12 +36,13 @@ class State:
3636
_main_trie: Trie[Address, Optional[Account]] = field(
3737
default_factory=lambda: Trie(secured=True, default=None)
3838
)
39-
_storage_tries: Dict[Address, Trie[Bytes, U256]] = field(
39+
_storage_tries: Dict[Address, Trie[Bytes32, U256]] = field(
4040
default_factory=dict
4141
)
4242
_snapshots: List[
4343
Tuple[
44-
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
44+
Trie[Address, Optional[Account]],
45+
Dict[Address, Trie[Bytes32, U256]],
4546
]
4647
] = field(default_factory=list)
4748

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

204205

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

233234

234235
def set_storage(
235-
state: State, address: Address, key: Bytes, value: U256
236+
state: State, address: Address, key: Bytes32, value: U256
236237
) -> None:
237238
"""
238239
Set a value at a storage key on an account. Setting to `U256(0)` deletes

0 commit comments

Comments
 (0)