diff --git a/tests/cancun/eip4844_blobs/spec.py b/tests/cancun/eip4844_blobs/spec.py index c253aee0a26..1a7f52b6c77 100644 --- a/tests/cancun/eip4844_blobs/spec.py +++ b/tests/cancun/eip4844_blobs/spec.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from hashlib import sha256 from typing import Optional +from ethereum_test_forks import Fork, Cancun from ethereum_test_tools import Transaction @@ -62,6 +63,16 @@ class Spec: HASH_OPCODE_BYTE = 0x49 HASH_GAS_COST = 3 + @classmethod + def target_blob_gas_per_block(cls, fork: Optional[Fork] = Cancun, cl_target_blob_count: Optional[int] = None) -> int: + """ + Returns the target blob gas per block, using a dynamic target for forks after Cancun. + For Cancun the target blob count is 3, hence the blob gas per block is 393216. + """ + if fork and fork > Cancun and cl_target_blob_count is not None: + return cl_target_blob_count * cls.GAS_PER_BLOB + return Spec.TARGET_BLOB_GAS_PER_BLOCK + @classmethod def kzg_to_versioned_hash( cls, @@ -99,10 +110,10 @@ def calc_excess_blob_gas(cls, parent: BlockHeaderBlobGasFields) -> int: Calculate the excess blob gas for a block given the excess blob gas and blob gas used from the parent block header. """ - if parent.excess_blob_gas + parent.blob_gas_used < cls.TARGET_BLOB_GAS_PER_BLOCK: + if parent.excess_blob_gas + parent.blob_gas_used < cls.target_blob_gas_per_block(): return 0 else: - return parent.excess_blob_gas + parent.blob_gas_used - cls.TARGET_BLOB_GAS_PER_BLOCK + return parent.excess_blob_gas + parent.blob_gas_used - cls.target_blob_gas_per_block() @classmethod def get_total_blob_gas(cls, tx: Transaction) -> int: @@ -124,7 +135,6 @@ def get_blob_gasprice(cls, *, excess_blob_gas: int) -> int: cls.BLOB_GASPRICE_UPDATE_FRACTION, ) - @dataclass(frozen=True) class SpecHelpers: """ @@ -146,7 +156,7 @@ def target_blobs_per_block(cls) -> int: """ Returns the target number of blobs per block. """ - return Spec.TARGET_BLOB_GAS_PER_BLOCK // Spec.GAS_PER_BLOB + return Spec.target_blob_gas_per_block() // Spec.GAS_PER_BLOB @classmethod def calc_excess_blob_gas_from_blob_count( @@ -180,4 +190,7 @@ def get_min_excess_blobs_for_blob_gas_price(cls, blob_gas_price: int) -> int: """ Gets the minimum required excess blobs to get a given blob gas cost in a block """ - return cls.get_min_excess_blob_gas_for_blob_gas_price(blob_gas_price) // Spec.GAS_PER_BLOB + return ( + cls.get_min_excess_blob_gas_for_blob_gas_price(blob_gas_price) + // Spec.GAS_PER_BLOB + )