Skip to content

Commit

Permalink
Refactor includability check for Tangerine Whistle.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgreg committed Apr 27, 2024
1 parent 47f7e8a commit b80eb0c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ethereum/tangerine_whistle/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def validate_proof_of_work(header: Header) -> None:


def check_transaction(
env: vm.Environment,
tx: Transaction,
gas_available: Uint,
) -> Address:
Expand All @@ -310,6 +311,8 @@ def check_transaction(
Parameters
----------
env :
Environment for the Ethereum Virtual Machine.
tx :
The transaction.
gas_available :
Expand All @@ -325,6 +328,13 @@ def check_transaction(
InvalidBlock :
If the transaction is not includable.
"""
sender = env.origin
sender_account = get_account(env.state, sender)
gas_fee = tx.gas * tx.gas_price
ensure(sender_account.nonce == tx.nonce, InvalidBlock)
ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock)
ensure(sender_account.code == bytearray(), InvalidBlock)

ensure(tx.gas <= gas_available, InvalidBlock)
sender_address = recover_sender(tx)

Expand Down Expand Up @@ -656,9 +666,6 @@ def process_transaction(
sender = env.origin
sender_account = get_account(env.state, sender)
gas_fee = tx.gas * tx.gas_price
ensure(sender_account.nonce == tx.nonce, InvalidBlock)
ensure(sender_account.balance >= gas_fee + tx.value, InvalidBlock)
ensure(sender_account.code == bytearray(), InvalidBlock)

gas = tx.gas - calculate_intrinsic_cost(tx)
increment_nonce(env.state, sender)
Expand Down

0 comments on commit b80eb0c

Please sign in to comment.