Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement t8n changes for 7742
Browse files Browse the repository at this point in the history
petertdavies committed Dec 3, 2024
1 parent 9dfa708 commit 936e30b
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/ethereum_spec_tools/evm_tools/loaders/fork_loader.py
Original file line number Diff line number Diff line change
@@ -82,6 +82,11 @@ def HISTORY_SERVE_WINDOW(self) -> Any:
"""HISTORY_SERVE_WINDOW of the given fork."""
return self._module("fork").HISTORY_SERVE_WINDOW

@property
def GAS_PER_BLOB(self) -> Any:
"""GAS_PER_BLOB of the given fork."""
return self._module("vm.gas").GAS_PER_BLOB

@property
def process_general_purpose_requests(self) -> Any:
"""process_general_purpose_requests function of the given fork."""
4 changes: 3 additions & 1 deletion src/ethereum_spec_tools/evm_tools/t8n/__init__.py
Original file line number Diff line number Diff line change
@@ -357,7 +357,9 @@ def apply_body(self) -> None:
env, tx
)

if self.fork.is_after_fork("ethereum.cancun"):
if self.fork.is_after_fork(
"ethereum.cancun"
) and not self.fork.is_after_fork("ethereum.prague"):
blob_gas_used += self.fork.calculate_total_blob_gas(tx)
if blob_gas_used > self.fork.MAX_BLOB_GAS_PER_BLOCK:
raise InvalidBlock
17 changes: 16 additions & 1 deletion src/ethereum_spec_tools/evm_tools/t8n/env.py
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ class Env:
parent_blob_gas_used: Optional[U64]
excess_blob_gas: Optional[U64]
requests: Any
target_blobs_per_block: Optional[U64]

def __init__(self, t8n: "T8N", stdin: Optional[Dict] = None):
if t8n.options.input_env == "stdin":
@@ -90,6 +91,7 @@ def read_excess_blob_gas(self, data: Any, t8n: "T8N") -> None:
self.parent_blob_gas_used = U64(0)
self.parent_excess_blob_gas = U64(0)
self.excess_blob_gas = None
self.target_blobs_per_block = None

if not t8n.fork.is_after_fork("ethereum.cancun"):
return
@@ -114,12 +116,25 @@ def read_excess_blob_gas(self, data: Any, t8n: "T8N") -> None:
self.parent_excess_blob_gas + self.parent_blob_gas_used
)

target_blob_gas_per_block = t8n.fork.TARGET_BLOB_GAS_PER_BLOCK
if "currentTargetBlobsPerBlock" in data:
self.target_blobs_per_block = parse_hex_or_int(
data["currentTargetBlobsPerBlock"], U64
)
target_blob_gas_per_block = (
self.target_blobs_per_block * t8n.fork.GAS_PER_BLOB
)
else:
target_blob_gas_per_block = t8n.fork.TARGET_BLOB_GAS_PER_BLOCK

self.excess_blob_gas = U64(0)
if excess_blob_gas >= target_blob_gas_per_block:
self.excess_blob_gas = excess_blob_gas - target_blob_gas_per_block

if "currentTargetBlobsPerBlock" in data:
self.target_blobs_per_block = parse_hex_or_int(
data["currentTargetBlobsPerBlock"], U64
)

def read_base_fee_per_gas(self, data: Any, t8n: "T8N") -> None:
"""
Read the base_fee_per_gas from the data. If the base fee is
4 changes: 4 additions & 0 deletions src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py
Original file line number Diff line number Diff line change
@@ -308,6 +308,7 @@ class Result:
blob_gas_used: Optional[Uint] = None
requests_hash: Optional[Hash32] = None
requests: Optional[List[Bytes]] = None
target_blobs_per_block: Optional[U64] = None

def to_json(self) -> Any:
"""Encode the result to JSON"""
@@ -360,4 +361,7 @@ def to_json(self) -> Any:
encode_to_hex(req[1:]) for req in self.requests
]

if self.target_blobs_per_block is not None:
data["currentBlobsPerBlock"] = hex(self.target_blobs_per_block)

return data

0 comments on commit 936e30b

Please sign in to comment.