From a5548eee9205fc9b37d2d6553ec857de59aaccc4 Mon Sep 17 00:00:00 2001 From: spencer-tb Date: Tue, 29 Oct 2024 12:59:52 +0700 Subject: [PATCH] feat(fw): add initial target blob count to header. --- src/ethereum_clis/types.py | 1 + src/ethereum_test_fixtures/blockchain.py | 5 +++++ src/ethereum_test_fixtures/tests/test_blockchain.py | 3 +++ src/ethereum_test_forks/base_fork.py | 8 ++++++++ src/ethereum_test_forks/forks/forks.py | 8 ++++++++ src/ethereum_test_specs/blockchain.py | 1 + src/ethereum_test_types/types.py | 2 ++ src/pytest_plugins/execute/rpc/hive.py | 4 ++++ 8 files changed, 32 insertions(+) diff --git a/src/ethereum_clis/types.py b/src/ethereum_clis/types.py index 51263b1f39..019d7f4ba7 100644 --- a/src/ethereum_clis/types.py +++ b/src/ethereum_clis/types.py @@ -89,6 +89,7 @@ class Result(CamelModel): blob_gas_used: HexNumber | None = None requests_hash: Hash | None = None requests: List[Bytes] | None = None + target_blob_count: HexNumber | None = None class TransitionToolInput(CamelModel): diff --git a/src/ethereum_test_fixtures/blockchain.py b/src/ethereum_test_fixtures/blockchain.py index 27de996526..9cf3b84327 100644 --- a/src/ethereum_test_fixtures/blockchain.py +++ b/src/ethereum_test_fixtures/blockchain.py @@ -111,6 +111,9 @@ class FixtureHeader(CamelModel): None ) requests_hash: Annotated[Hash, HeaderForkRequirement("requests")] | None = Field(None) + target_blob_count: Annotated[ + ZeroPaddedHexNumber, HeaderForkRequirement("blob_count") + ] | None = Field(None) fork: Fork | None = Field(None, exclude=True) @@ -199,6 +202,8 @@ class FixtureExecutionPayload(CamelModel): blob_gas_used: HexNumber | None = Field(None) excess_blob_gas: HexNumber | None = Field(None) + target_blob_count: HexNumber | None = Field(None) + block_hash: Hash transactions: List[Bytes] diff --git a/src/ethereum_test_fixtures/tests/test_blockchain.py b/src/ethereum_test_fixtures/tests/test_blockchain.py index 5276c1835b..f9c5898e12 100644 --- a/src/ethereum_test_fixtures/tests/test_blockchain.py +++ b/src/ethereum_test_fixtures/tests/test_blockchain.py @@ -668,6 +668,7 @@ excess_blob_gas=18, parent_beacon_block_root=19, requests_hash=20, + target_blob_count=10, ), transactions=[ Transaction( @@ -1191,6 +1192,7 @@ def test_json_deserialization( withdrawals_root=Hash(16), blob_gas_used=17, excess_blob_gas=18, + target_blob_count=10, ), transactions=[ Transaction( @@ -1249,6 +1251,7 @@ def test_json_deserialization( "baseFeePerGas": hex(15), "blobGasUsed": hex(17), "excessBlobGas": hex(18), + "targetBlobCount": hex(10), "blockHash": "0xd90115b7fde329f64335763a446af1" "50ab67e639281dccdb07a007d18bb80211", "transactions": [ diff --git a/src/ethereum_test_forks/base_fork.py b/src/ethereum_test_forks/base_fork.py index 1f468fba9c..2768b8689b 100644 --- a/src/ethereum_test_forks/base_fork.py +++ b/src/ethereum_test_forks/base_fork.py @@ -160,6 +160,14 @@ def header_requests_required(cls, block_number: int, timestamp: int) -> bool: """ pass + @classmethod + @abstractmethod + def header_blob_count_required(cls, block_number: int, timestamp: int) -> bool: + """ + Returns true if the header must contain target blob count + """ + pass + @classmethod @abstractmethod def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int: diff --git a/src/ethereum_test_forks/forks/forks.py b/src/ethereum_test_forks/forks/forks.py index 6c20c84f67..6af1085764 100644 --- a/src/ethereum_test_forks/forks/forks.py +++ b/src/ethereum_test_forks/forks/forks.py @@ -938,6 +938,14 @@ def header_requests_required(cls, block_number: int, timestamp: int) -> bool: """ return True + @classmethod + def header_blob_count_required(cls, block_number: int = 0, timestamp: int = 0) -> bool: + """ + Prague requires that the execution layer header contains the beacon + chain target blob count. + """ + return True + @classmethod def engine_new_payload_requests(cls, block_number: int = 0, timestamp: int = 0) -> bool: """ diff --git a/src/ethereum_test_specs/blockchain.py b/src/ethereum_test_specs/blockchain.py index 64a0ccde74..fed93aed08 100644 --- a/src/ethereum_test_specs/blockchain.py +++ b/src/ethereum_test_specs/blockchain.py @@ -119,6 +119,7 @@ class Header(CamelModel): excess_blob_gas: Removable | HexNumber | None = None parent_beacon_block_root: Removable | Hash | None = None requests_hash: Removable | Hash | None = None + target_blob_count: Removable | HexNumber | None = None REMOVE_FIELD: ClassVar[Removable] = Removable() """ diff --git a/src/ethereum_test_types/types.py b/src/ethereum_test_types/types.py index e7f757523a..69c0afac70 100644 --- a/src/ethereum_test_types/types.py +++ b/src/ethereum_test_types/types.py @@ -390,6 +390,8 @@ class EnvironmentGeneric(CamelModel, Generic[NumberBoundTypeVar]): base_fee_per_gas: NumberBoundTypeVar | None = Field(None, alias="currentBaseFee") excess_blob_gas: NumberBoundTypeVar | None = Field(None, alias="currentExcessBlobGas") + target_blob_count: NumberBoundTypeVar | None = Field(None, alias="currentTargetBlobGasUsed") + parent_difficulty: NumberBoundTypeVar | None = Field(None) parent_timestamp: NumberBoundTypeVar | None = Field(None) parent_base_fee_per_gas: NumberBoundTypeVar | None = Field(None, alias="parentBaseFee") diff --git a/src/pytest_plugins/execute/rpc/hive.py b/src/pytest_plugins/execute/rpc/hive.py index 38995fc2ac..beacf844c7 100644 --- a/src/pytest_plugins/execute/rpc/hive.py +++ b/src/pytest_plugins/execute/rpc/hive.py @@ -262,6 +262,10 @@ def base_pre_genesis( ) if base_fork.header_requests_required(block_number=block_number, timestamp=timestamp) else None, + target_blob_count=env.target_blob_count if base_fork.header_blob_count_required( + block_number=block_number, + timestamp=timestamp + ) else None, ) return (pre_alloc, genesis)