Skip to content

Commit

Permalink
chore: refactor verkle conversion field updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Sep 3, 2024
1 parent 1cd4200 commit 7fc7516
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
11 changes: 8 additions & 3 deletions src/ethereum_test_specs/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from .debugging import print_traces


def environment_from_parent_header(parent: "FixtureHeader") -> "Environment":
def environment_from_parent_header(parent: FixtureHeader) -> Environment:
"""
Instantiates a new environment with the provided header as parent.
"""
Expand All @@ -72,7 +72,7 @@ def environment_from_parent_header(parent: "FixtureHeader") -> "Environment":
)


def apply_new_parent(env: Environment, new_parent: FixtureHeader) -> "Environment":
def apply_new_parent(env: Environment, new_parent: FixtureHeader) -> Environment:
"""
Applies a header as parent to a copy of this environment.
"""
Expand Down Expand Up @@ -518,7 +518,12 @@ def generate_block_data(
header.requests_root = requests.trie_root

if fork.fork_at(env.number, env.timestamp) == ShanghaiEIP6800:
env.update_from_result(transition_tool_output.result)
env = Environment(
**(
env.model_dump(exclude_none=True)
| transition_tool_output.result.model_dump(exclude_none=True)
)
)
transition_tool_output.alloc = previous_alloc

return (
Expand Down
23 changes: 0 additions & 23 deletions src/ethereum_test_types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,29 +465,6 @@ def set_fork_requirements(self, fork: Fork) -> "Environment":
return self.copy(**updated_values)

# TODO: move this function, importing the Result type creates a circular import.
def update_from_result(self, result: Any) -> "Environment":
"""
Updates the environment with the result of a transition tool execution.
"""
if result.verkle_conversion_address:
self.verkle_conversion_address = result.verkle_conversion_address
if result.verkle_conversion_slot_hash:
self.verkle_conversion_slot_hash = result.verkle_conversion_slot_hash
# Boolean fields required to check if not None so we actually update them even when False
if result.verkle_conversion_started is not None:
conversion_started = result.verkle_conversion_started
assert isinstance(conversion_started, bool)
self.verkle_conversion_started = result.verkle_conversion_started
if result.verkle_conversion_ended is not None:
conversion_ended = result.verkle_conversion_ended
assert isinstance(conversion_ended, bool)
self.verkle_conversion_ended = result.verkle_conversion_ended
if result.verkle_conversion_storage_processed is not None:
conversion_storage_processed = result.verkle_conversion_storage_processed
assert isinstance(conversion_storage_processed, bool)
self.verkle_conversion_storage_processed = conversion_storage_processed

return self


class AccessList(CamelModel):
Expand Down

0 comments on commit 7fc7516

Please sign in to comment.