Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add engine API forkchoice updated information in fixtures #256

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ def engine_new_payload_beacon_root(cls, block_number: int = 0, timestamp: int =
"""
pass

@classmethod
@abstractmethod
def engine_forkchoice_updated_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
Returns `None` if the forks canonical chain cannot be set using the forkchoice method.
"""
pass

# Meta information about the fork
@classmethod
def name(cls) -> str:
Expand Down
9 changes: 9 additions & 0 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ def engine_new_payload_beacon_root(cls, block_number: int = 0, timestamp: int =
"""
return False

@classmethod
def engine_forkchoice_updated_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
At genesis, forkchoice updates cannot be sent through the engine API.
"""
return cls.engine_new_payload_version(block_number, timestamp)

@classmethod
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:
"""
Expand Down
5 changes: 5 additions & 0 deletions src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2707,6 +2707,11 @@ class Fixture:
to_json=True,
),
)
fcu_version: Optional[int] = field(
json_encoder=JSONEncoder.Field(
name="engineFcuVersion",
),
)
genesis: FixtureHeader = field(
json_encoder=JSONEncoder.Field(
name="genesisBlockHeader",
Expand Down
15 changes: 15 additions & 0 deletions src/ethereum_test_tools/filling/fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ def fill_test(
eips=eips,
)

fcu_version: int | None = None
if not test_spec.base_test_config.disable_hive:
last_valid_block = next(
spencer-tb marked this conversation as resolved.
Show resolved Hide resolved
(block.block_header for block in reversed(blocks) if block.expected_exception is None),
None,
)
fcu_version = (
fork.engine_forkchoice_updated_version(
last_valid_block.number, last_valid_block.timestamp
)
if last_valid_block
else None
)

fork_name = fork.name()
fixture = Fixture(
blocks=blocks,
Expand All @@ -45,6 +59,7 @@ def fill_test(
post_state=alloc_to_accounts(alloc),
seal_engine=engine,
name=test_spec.tag,
fcu_version=fcu_version,
)
fixture.fill_info(t8n, spec)

Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ extcodesize
fn
fname
forkchoice
fcu
formatOnSave
formatter
fromhex
Expand Down