Skip to content

Commit 7ee1915

Browse files
committed
forks: Add blob_gas_per_blob
1 parent 0844e08 commit 7ee1915

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/ethereum_test_forks/base_fork.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ def header_beacon_root_required(cls, block_number: int, timestamp: int) -> bool:
143143
"""
144144
pass
145145

146+
@classmethod
147+
@abstractmethod
148+
def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
149+
"""
150+
Returns the amount of blob gas used per each blob for a given fork.
151+
"""
152+
pass
153+
146154
@classmethod
147155
@abstractmethod
148156
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:

src/ethereum_test_forks/forks/forks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ def header_blob_gas_used_required(cls, block_number: int = 0, timestamp: int = 0
7272
"""
7373
return False
7474

75+
@classmethod
76+
def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
77+
"""
78+
Returns the amount of blob gas used per each blob for a given fork.
79+
"""
80+
return 0
81+
7582
@classmethod
7683
def engine_new_payload_version(
7784
cls, block_number: int = 0, timestamp: int = 0
@@ -370,6 +377,13 @@ def header_beacon_root_required(cls, block_number: int = 0, timestamp: int = 0)
370377
"""
371378
return True
372379

380+
@classmethod
381+
def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
382+
"""
383+
Blobs are enabled started from Cancun.
384+
"""
385+
return 2**17
386+
373387
@classmethod
374388
def tx_types(cls, block_number: int = 0, timestamp: int = 0) -> List[int]:
375389
"""

src/ethereum_test_tools/spec/blockchain/blockchain_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ def apply_new_parent(env: Environment, new_parent: FixtureHeader) -> "Environmen
7979
return env
8080

8181

82+
def count_blobs(txs: List[Transaction]) -> int:
83+
"""
84+
Returns the number of blobs in a list of transactions.
85+
"""
86+
return sum(
87+
[len(tx.blob_versioned_hashes) for tx in txs if tx.blob_versioned_hashes is not None]
88+
)
89+
90+
8291
@dataclass(kw_only=True)
8392
class BlockchainTest(BaseTest):
8493
"""
@@ -229,6 +238,15 @@ def generate_block_data(
229238
environment=env,
230239
)
231240

241+
# One special case of the invalid transactions is the blob gas used, since this value
242+
# is not included in the transition tool result, but it is included in the block header,
243+
# and some clients check it before executing the block by simply counting the type-3 txs,
244+
# we need to set the correct value by default.
245+
if (
246+
blob_gas_per_blob := fork.blob_gas_per_blob(Number(env.number), Number(env.timestamp))
247+
) > 0:
248+
header.blob_gas_used = blob_gas_per_blob * count_blobs(txs)
249+
232250
if block.header_verify is not None:
233251
# Verify the header after transition tool processing.
234252
header.verify(block.header_verify)

0 commit comments

Comments
 (0)