Skip to content

Commit 6309cde

Browse files
souradeep-dasSamWilsn
authored andcommitted
fix review comments
1 parent 6c038e8 commit 6309cde

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/ethereum/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ class NonceMismatchError(InvalidTransaction):
5353
Thrown when a transaction's nonce does not match the expected nonce for the
5454
sender.
5555
"""
56+
57+
58+
class GasUsedExceedsLimitError(InvalidTransaction):
59+
"""
60+
Thrown when a transaction's gas usage exceeds the gas available in the
61+
block.
62+
"""

src/ethereum/prague/exceptions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ class InsufficientMaxFeePerGasError(InvalidTransaction):
5959
The maximum fee per gas is insufficient for the transaction.
6060
"""
6161

62+
transaction_max_fee_per_gas: Final[int]
63+
"""
64+
The maximum fee per gas specified in the transaction.
65+
"""
66+
67+
block_base_fee_per_gas: Final[int]
68+
"""
69+
The base fee per gas of the block in which the transaction is included.
70+
"""
71+
72+
def __init__(
73+
self, transaction_max_fee_per_gas: int, block_base_fee_per_gas: int
74+
):
75+
super().__init__(
76+
f"Insufficient max fee per gas "
77+
f"({transaction_max_fee_per_gas} < {block_base_fee_per_gas})"
78+
)
79+
self.transaction_max_fee_per_gas = transaction_max_fee_per_gas
80+
self.block_base_fee_per_gas = block_base_fee_per_gas
81+
6282

6383
class InvalidBlobVersionedHashError(InvalidTransaction):
6484
"""

src/ethereum/prague/fork.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ethereum.crypto.hash import Hash32, keccak256
2323
from ethereum.exceptions import (
2424
EthereumException,
25+
GasUsedExceedsLimitError,
2526
InsufficientBalanceError,
2627
InvalidBlock,
2728
InvalidSenderError,
@@ -417,7 +418,7 @@ def check_transaction(
417418
blob_gas_available = MAX_BLOB_GAS_PER_BLOCK - block_output.blob_gas_used
418419

419420
if tx.gas > gas_available:
420-
raise InvalidBlock
421+
raise GasUsedExceedsLimitError("gas used exceeds limit")
421422

422423
tx_blob_gas_used = calculate_total_blob_gas(tx)
423424
if tx_blob_gas_used > blob_gas_available:
@@ -434,7 +435,9 @@ def check_transaction(
434435
"priority fee greater than max fee"
435436
)
436437
if tx.max_fee_per_gas < block_env.base_fee_per_gas:
437-
raise InsufficientMaxFeePerGasError("insufficient max fee per gas")
438+
raise InsufficientMaxFeePerGasError(
439+
tx.max_fee_per_gas, block_env.base_fee_per_gas
440+
)
438441

439442
priority_fee_per_gas = min(
440443
tx.max_priority_fee_per_gas,
@@ -478,11 +481,11 @@ def check_transaction(
478481
if not any(tx.authorizations):
479482
raise EmptyAuthorizationListError("empty authorization list")
480483

481-
if sender_account.nonce != tx.nonce:
482-
if sender_account.nonce > Uint(tx.nonce):
483-
raise NonceMismatchError("nonce too low")
484-
else:
485-
raise NonceMismatchError("nonce too high")
484+
if sender_account.nonce > Uint(tx.nonce):
485+
raise NonceMismatchError("nonce too low")
486+
elif sender_account.nonce < Uint(tx.nonce):
487+
raise NonceMismatchError("nonce too high")
488+
486489
if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value):
487490
raise InsufficientBalanceError("insufficient sender balance")
488491
if sender_account.code and not is_valid_delegation(sender_account.code):

0 commit comments

Comments
 (0)