Skip to content

Commit

Permalink
address comments from PR ethereum#2151
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Mar 13, 2024
1 parent c00eea2 commit 4059be0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
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
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 4059be0

Please sign in to comment.