Skip to content

Commit c257bd3

Browse files
committed
feat(fw): add initial target blob count to header.
1 parent 9a10929 commit c257bd3

File tree

8 files changed

+63
-3
lines changed

8 files changed

+63
-3
lines changed

src/ethereum_clis/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class Result(CamelModel):
8989
blob_gas_used: HexNumber | None = None
9090
requests_hash: Hash | None = None
9191
requests: List[Bytes] | None = None
92+
target_blob_count: HexNumber | None = None
9293

9394

9495
class TransitionToolInput(CamelModel):

src/ethereum_test_fixtures/blockchain.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class FixtureHeader(CamelModel):
111111
None
112112
)
113113
requests_hash: Annotated[Hash, HeaderForkRequirement("requests")] | None = Field(None)
114+
target_blob_count: Annotated[
115+
ZeroPaddedHexNumber, HeaderForkRequirement("blob_count")
116+
] | None = Field(None)
114117

115118
fork: Fork | None = Field(None, exclude=True)
116119

@@ -199,6 +202,8 @@ class FixtureExecutionPayload(CamelModel):
199202
blob_gas_used: HexNumber | None = Field(None)
200203
excess_blob_gas: HexNumber | None = Field(None)
201204

205+
target_blob_count: HexNumber | None = Field(None)
206+
202207
block_hash: Hash
203208

204209
transactions: List[Bytes]

src/ethereum_test_fixtures/tests/test_blockchain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@
668668
excess_blob_gas=18,
669669
parent_beacon_block_root=19,
670670
requests_hash=20,
671+
target_blob_count=10,
671672
),
672673
transactions=[
673674
Transaction(
@@ -1191,6 +1192,7 @@ def test_json_deserialization(
11911192
withdrawals_root=Hash(16),
11921193
blob_gas_used=17,
11931194
excess_blob_gas=18,
1195+
target_blob_count=10,
11941196
),
11951197
transactions=[
11961198
Transaction(
@@ -1249,6 +1251,7 @@ def test_json_deserialization(
12491251
"baseFeePerGas": hex(15),
12501252
"blobGasUsed": hex(17),
12511253
"excessBlobGas": hex(18),
1254+
"targetBlobCount": hex(10),
12521255
"blockHash": "0xd90115b7fde329f64335763a446af1"
12531256
"50ab67e639281dccdb07a007d18bb80211",
12541257
"transactions": [

src/ethereum_test_forks/base_fork.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ def header_requests_required(cls, block_number: int, timestamp: int) -> bool:
160160
"""
161161
pass
162162

163+
@classmethod
164+
@abstractmethod
165+
def header_target_blob_count_required(cls, block_number: int, timestamp: int) -> bool:
166+
"""
167+
Returns true if the header must contain target blob count
168+
"""
169+
pass
170+
163171
@classmethod
164172
@abstractmethod
165173
def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
@@ -168,6 +176,14 @@ def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
168176
"""
169177
pass
170178

179+
@classmethod
180+
@abstractmethod
181+
def target_blob_count(cls, block_number: int, timestamp: int) -> int:
182+
"""
183+
Returns the target blobs per block for a given fork.
184+
"""
185+
pass
186+
171187
@classmethod
172188
@abstractmethod
173189
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:

src/ethereum_test_forks/forks/forks.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,16 @@ def header_beacon_root_required(cls, block_number: int = 0, timestamp: int = 0)
730730
@classmethod
731731
def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
732732
"""
733-
Blobs are enabled started from Cancun.
733+
Blobs are enabled starting from Cancun.
734734
"""
735735
return 2**17
736+
737+
@classmethod
738+
def target_blob_count(cls, block_number: int, timestamp: int) -> int:
739+
"""
740+
Blobs are enabled starting from Cancun, with a static target of 3 blobs.
741+
"""
742+
return 3
736743

737744
@classmethod
738745
def tx_types(cls, block_number: int = 0, timestamp: int = 0) -> List[int]:
@@ -938,6 +945,14 @@ def header_requests_required(cls, block_number: int, timestamp: int) -> bool:
938945
"""
939946
return True
940947

948+
@classmethod
949+
def header_target_blob_count_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
950+
"""
951+
Prague requires that the execution layer header contains the beacon
952+
chain target blob count.
953+
"""
954+
return True
955+
941956
@classmethod
942957
def engine_new_payload_requests(cls, block_number: int = 0, timestamp: int = 0) -> bool:
943958
"""

src/ethereum_test_specs/blockchain.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class Header(CamelModel):
119119
excess_blob_gas: Removable | HexNumber | None = None
120120
parent_beacon_block_root: Removable | Hash | None = None
121121
requests_hash: Removable | Hash | None = None
122+
target_blob_count: Removable | HexNumber | None = None
122123

123124
REMOVE_FIELD: ClassVar[Removable] = Removable()
124125
"""
@@ -353,12 +354,17 @@ def make_genesis(
353354
blob_gas_used=env.blob_gas_used,
354355
excess_blob_gas=env.excess_blob_gas,
355356
withdrawals_root=(
356-
Withdrawal.list_root(env.withdrawals) if env.withdrawals is not None else None
357+
Withdrawal.list_root(env.withdrawals)
358+
if env.withdrawals is not None
359+
else None
357360
),
358361
parent_beacon_block_root=env.parent_beacon_block_root,
359362
requests_hash=Requests(max_request_type=fork.max_request_type(0, 0))
360363
if fork.header_requests_required(0, 0)
361364
else None,
365+
target_blob_count=fork.target_blob_count(0, 0)
366+
if fork.header_target_blob_count_required(0, 0)
367+
else None,
362368
fork=fork,
363369
)
364370

src/ethereum_test_types/types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ class EnvironmentGeneric(CamelModel, Generic[NumberBoundTypeVar]):
390390
base_fee_per_gas: NumberBoundTypeVar | None = Field(None, alias="currentBaseFee")
391391
excess_blob_gas: NumberBoundTypeVar | None = Field(None, alias="currentExcessBlobGas")
392392

393+
target_blob_count: NumberBoundTypeVar | None = Field(None, alias="currentTargetBlobGasUsed")
394+
393395
parent_difficulty: NumberBoundTypeVar | None = Field(None)
394396
parent_timestamp: NumberBoundTypeVar | None = Field(None)
395397
parent_base_fee_per_gas: NumberBoundTypeVar | None = Field(None, alias="parentBaseFee")
@@ -474,6 +476,9 @@ def set_fork_requirements(self, fork: Fork) -> "Environment":
474476
):
475477
updated_values["parent_beacon_block_root"] = 0
476478

479+
if fork.header_target_blob_count_required(number, timestamp) and self.target_blob_count is None:
480+
updated_values["target_blob_count"] = fork.target_blob_count(number, timestamp)
481+
477482
return self.copy(**updated_values)
478483

479484

src/pytest_plugins/execute/rpc/hive.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,16 @@ def base_pre_genesis(
260260
timestamp=timestamp,
261261
),
262262
)
263-
if base_fork.header_requests_required(block_number=block_number, timestamp=timestamp)
263+
if base_fork.header_requests_required(
264+
block_number=block_number, timestamp=timestamp
265+
)
266+
else None,
267+
target_blob_count=base_fork.target_blob_count(
268+
block_number=block_number, timestamp=timestamp
269+
)
270+
if base_fork.header_target_blob_count_required(
271+
block_number=block_number, timestamp=timestamp
272+
)
264273
else None,
265274
)
266275

0 commit comments

Comments
 (0)