Skip to content

Commit

Permalink
chore: fixes for new payload v4.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Oct 31, 2024
1 parent 036972a commit 08eea93
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
52 changes: 27 additions & 25 deletions src/ethereum_test_fixtures/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def from_fixture_header(

EngineNewPayloadV1Parameters = Tuple[FixtureExecutionPayload]
EngineNewPayloadV3Parameters = Tuple[FixtureExecutionPayload, List[Hash], Hash]
EngineNewPayloadV4Parameters = Tuple[FixtureExecutionPayload, List[Hash], Hash, List[Bytes]]
EngineNewPayloadV4Parameters = Tuple[FixtureExecutionPayload, List[Hash], Hash, List[Bytes], HexNumber]

# Important: We check EngineNewPayloadV3Parameters first as it has more fields, and pydantic
# has a weird behavior when the smaller tuple is checked first.
Expand Down Expand Up @@ -291,32 +291,34 @@ def from_fixture_header(
transactions=transactions,
withdrawals=withdrawals,
)
params: EngineNewPayloadParameters
if (
fork.engine_new_payload_requests(header.number, header.timestamp)
and requests is not None
):
parent_beacon_block_root = header.parent_beacon_block_root
assert parent_beacon_block_root is not None
params = (
execution_payload,
Transaction.list_blob_versioned_hashes(transactions),
parent_beacon_block_root,
requests,
)
elif fork.engine_new_payload_blob_hashes(header.number, header.timestamp):
parent_beacon_block_root = header.parent_beacon_block_root
assert parent_beacon_block_root is not None
params = (
execution_payload,
Transaction.list_blob_versioned_hashes(transactions),
parent_beacon_block_root,
)
else:
params = (execution_payload,)

params: List[Any] = [execution_payload]
if fork.engine_new_payload_blob_hashes(header.number, header.timestamp):
blob_hashes = Transaction.list_blob_versioned_hashes(transactions)
if blob_hashes is None:
raise ValueError(f"Blob hashes are required for ${fork}.")
params.append(blob_hashes)

if fork.engine_new_payload_beacon_root(header.number, header.timestamp):
parent_beacon_block_root = header.parent_beacon_block_root
if parent_beacon_block_root is None:
raise ValueError(f"Parent beacon block root is required for ${fork}.")
params.append(parent_beacon_block_root)

if fork.engine_new_payload_requests(header.number, header.timestamp):
if requests is None:
raise ValueError(f"Requests are required for ${fork}.")
params.append(requests)

if fork.engine_new_payload_target_blob_count(header.number, header.timestamp):
target_blob_count = header.target_blob_count
if target_blob_count is None:
raise ValueError(f"Target blob count is required for ${fork}.")
params.append(target_blob_count)

payload_params: EngineNewPayloadParameters = tuple(params)
new_payload = cls(
params=params,
params=payload_params,
new_payload_version=new_payload_version,
forkchoice_updated_version=forkchoice_updated_version,
**kwargs,
Expand Down
10 changes: 9 additions & 1 deletion src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,15 @@ def engine_new_payload_beacon_root(cls, block_number: int = 0, timestamp: int =
@abstractmethod
def engine_new_payload_requests(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the engine api version requires new payload calls to include requests.
returns true if the engine api version requires new payload calls to include requests.
"""
pass

@classmethod
@abstractmethod
def engine_new_payload_target_blob_count(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
returns true if the engine api version requires new payload calls to include target blob count.
"""
pass

Expand Down
4 changes: 2 additions & 2 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,9 @@ def engine_new_payload_requests(cls, block_number: int = 0, timestamp: int = 0)
return True

@classmethod
def engine_new_payload_blob_hashes(cls, block_number: int = 0, timestamp: int = 0) -> bool:
def engine_new_payload_target_blob_count(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Starting at Prague, new payload directives must contain requests as parameter.
Starting at Prague, new payloads include the target blob count as a parameter.
"""
return True

Expand Down

0 comments on commit 08eea93

Please sign in to comment.