Skip to content

Commit

Permalink
address comments from PR #2151
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Mar 13, 2024
1 parent 31f499e commit 74e82b0
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 41 deletions.
8 changes: 0 additions & 8 deletions eth/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,14 +1966,6 @@ def base_fee_per_gas(self) -> Optional[int]:
"""
...

@property
@abstractmethod
def blob_gas_used(self) -> Optional[int]:
"""
Return the blob gas used of the block
"""
...

@property
@abstractmethod
def excess_blob_gas(self) -> Optional[int]:
Expand Down
2 changes: 1 addition & 1 deletion eth/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)


def validate_is_bytes(value: bytes, size: int = None, title: str = "Value") -> None:
def validate_is_bytes(value: bytes, title: str = "Value", size: int = None) -> None:
if not isinstance(value, bytes):
raise ValidationError(f"{title} must be a byte string. Got: {type(value)}")
if size is not None and len(value) != size:
Expand Down
2 changes: 0 additions & 2 deletions eth/vm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def create_execution_context(
fee_recipient = cls.consensus_class.get_fee_recipient(header)

base_fee_per_gas = getattr(header, "base_fee_per_gas", None)
blob_gas_used = getattr(header, "blob_gas_used", None)
excess_blob_gas = getattr(header, "excess_blob_gas", None)

return ExecutionContext(
Expand All @@ -213,7 +212,6 @@ def create_execution_context(
prev_hashes=prev_hashes,
chain_id=chain_context.chain_id,
base_fee_per_gas=base_fee_per_gas,
blob_gas_used=blob_gas_used,
excess_blob_gas=excess_blob_gas,
)

Expand Down
13 changes: 0 additions & 13 deletions eth/vm/execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ExecutionContext(ExecutionContextAPI):
_prev_hashes = None
_chain_id = None
_base_fee_per_gas = None
_blob_gas_used = None
_excess_blob_gas = None

def __init__(
Expand All @@ -41,7 +40,6 @@ def __init__(
prev_hashes: Iterable[Hash32],
chain_id: int,
base_fee_per_gas: Optional[int] = None,
blob_gas_used: Optional[int] = None,
excess_blob_gas: Optional[int] = None,
) -> None:
self._coinbase = coinbase
Expand All @@ -53,7 +51,6 @@ def __init__(
self._prev_hashes = CachedIterable(prev_hashes)
self._chain_id = chain_id
self._base_fee_per_gas = base_fee_per_gas
self._blob_gas_used = blob_gas_used
self._excess_blob_gas = excess_blob_gas

@property
Expand Down Expand Up @@ -98,16 +95,6 @@ def base_fee_per_gas(self) -> int:
else:
return self._base_fee_per_gas

@property
def blob_gas_used(self) -> int:
if self._blob_gas_used is None:
raise AttributeError(
f"This header at Block #{self.block_number} "
"does not have a blob gas used"
)
else:
return self._blob_gas_used

@property
def excess_blob_gas(self) -> int:
if self._excess_blob_gas is None:
Expand Down
14 changes: 4 additions & 10 deletions eth/vm/forks/cancun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
Type,
)

from eth._utils.db import get_block_header_by_hash
from eth._utils.db import (
get_block_header_by_hash,
)
from eth.abc import (
BlockAPI,
BlockHeaderAPI,
Expand Down Expand Up @@ -58,19 +60,11 @@ class CancunVM(ShanghaiVM):
create_cancun_header_from_parent()
)

@staticmethod
def _get_total_blob_gas(transaction: TransactionFieldsAPI) -> int:
try:
return GAS_PER_BLOB * len(transaction.blob_versioned_hashes) # type: ignore
except (AttributeError, NotImplementedError):
return 0

def increment_blob_gas_used(
self, old_header: BlockHeaderAPI, transaction: TransactionFieldsAPI
) -> BlockHeaderAPI:
return old_header.copy(
blob_gas_used=old_header.blob_gas_used
+ self._get_total_blob_gas(transaction)
blob_gas_used=old_header.blob_gas_used + get_total_blob_gas(transaction)
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion eth/vm/forks/cancun/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
GAS_PER_BLOB = 2**17
HASH_OPCODE_GAS = 3

# EIP-75416
# EIP-7516
BASEFEE_OPCODE_GAS = 2
6 changes: 2 additions & 4 deletions eth/vm/forks/cancun/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ def calc_excess_blob_gas(parent_header: BlockHeaderAPI) -> int:
):
return 0
else:
excess_blob_gas = (
return (
parent_header.excess_blob_gas
+ parent_header.blob_gas_used
- TARGET_BLOB_GAS_PER_BLOCK
)
return excess_blob_gas


@curry
Expand Down Expand Up @@ -70,5 +69,4 @@ def create_cancun_header_from_parent(
if parent_header is not None:
all_fields["excess_blob_gas"] = calc_excess_blob_gas(parent_header)

new_header = CancunBlockHeader(**all_fields)
return new_header
return CancunBlockHeader(**all_fields)
4 changes: 4 additions & 0 deletions eth/vm/forks/cancun/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
)


# ``max_iterations`` was added to prevent the exponential nature from running
# indefinitely. Some ``ethereum/tests`` would hang forever on this calculation. We
# should keep an eye on this function to see if this value is accurate enough for
# the use case.
def fake_exponential(
factor: int, numerator: int, denominator: int, max_iterations: int = 10000
) -> int:
Expand Down
4 changes: 2 additions & 2 deletions eth/vm/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def gas_limit(self) -> int:
@property
def base_fee(self) -> int:
raise NotImplementedError(
"Basefee opcode is not implemented prior to London hard fork"
"BASEFEE opcode is not implemented prior to London hard fork"
)

def get_tip(self, transaction: SignedTransactionAPI) -> int:
Expand All @@ -114,7 +114,7 @@ def get_gas_price(self, transaction: SignedTransactionAPI) -> int:
@property
def blob_base_fee(self) -> int:
raise NotImplementedError(
"Basefee opcode is not implemented prior to Cancun hard fork"
"BLOBBASEFEE opcode is not implemented prior to Cancun hard fork"
)

#
Expand Down

0 comments on commit 74e82b0

Please sign in to comment.