Skip to content

Commit

Permalink
dev: stricter types for MessageCallOuput (#1098)
Browse files Browse the repository at this point in the history
* dev: stricter type for MessageCallOuput

* fix: build doc
  • Loading branch information
obatirou authored Jan 31, 2025
1 parent e49ab69 commit 9923823
Show file tree
Hide file tree
Showing 46 changed files with 194 additions and 97 deletions.
10 changes: 7 additions & 3 deletions src/ethereum/arrow_glacier/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

from ethereum.crypto.hash import Hash32, keccak256
from ethereum.ethash import dataset_size, generate_cache, hashimoto_light
from ethereum.exceptions import InvalidBlock, InvalidSenderError
from ethereum.exceptions import (
EthereumException,
InvalidBlock,
InvalidSenderError,
)

from . import vm
from .blocks import Block, Header, Log, Receipt
Expand Down Expand Up @@ -441,7 +445,7 @@ def check_transaction(

def make_receipt(
tx: Transaction,
error: Optional[Exception],
error: Optional[EthereumException],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
) -> Union[Bytes, Receipt]:
Expand Down Expand Up @@ -748,7 +752,7 @@ def pay_rewards(

def process_transaction(
env: vm.Environment, tx: Transaction
) -> Tuple[Uint, Tuple[Log, ...], Optional[Exception]]:
) -> Tuple[Uint, Tuple[Log, ...], Optional[EthereumException]]:
"""
Execute a transaction against the provided environment.
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum/arrow_glacier/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ethereum_types.numeric import U64, U256, Uint

from ethereum.crypto.hash import Hash32
from ethereum.exceptions import EthereumException

from ..blocks import Log
from ..fork_types import Address
Expand Down Expand Up @@ -91,7 +92,7 @@ class Evm:
accounts_to_delete: Set[Address]
touched_accounts: Set[Address]
return_data: Bytes
error: Optional[Exception]
error: Optional[EthereumException]
accessed_addresses: Set[Address]
accessed_storage_keys: Set[Tuple[Address, Bytes32]]

Expand Down
8 changes: 5 additions & 3 deletions src/ethereum/arrow_glacier/vm/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
A straightforward interpreter that executes EVM code.
"""

from dataclasses import dataclass
from typing import Iterable, Optional, Set, Tuple
from typing import Optional, Set, Tuple

from ethereum_types.bytes import Bytes0
from ethereum_types.numeric import U256, Uint, ulen

from ethereum.exceptions import EthereumException
from ethereum.trace import (
EvmStop,
OpEnd,
Expand Down Expand Up @@ -83,8 +85,8 @@ class MessageCallOutput:
refund_counter: U256
logs: Tuple[Log, ...]
accounts_to_delete: Set[Address]
touched_accounts: Iterable[Address]
error: Optional[Exception]
touched_accounts: Set[Address]
error: Optional[EthereumException]


def process_message_call(
Expand Down
10 changes: 7 additions & 3 deletions src/ethereum/berlin/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

from ethereum.crypto.hash import Hash32, keccak256
from ethereum.ethash import dataset_size, generate_cache, hashimoto_light
from ethereum.exceptions import InvalidBlock, InvalidSenderError
from ethereum.exceptions import (
EthereumException,
InvalidBlock,
InvalidSenderError,
)

from . import vm
from .blocks import Block, Header, Log, Receipt
Expand Down Expand Up @@ -343,7 +347,7 @@ def check_transaction(

def make_receipt(
tx: Transaction,
error: Optional[Exception],
error: Optional[EthereumException],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
) -> Union[Bytes, Receipt]:
Expand Down Expand Up @@ -642,7 +646,7 @@ def pay_rewards(

def process_transaction(
env: vm.Environment, tx: Transaction
) -> Tuple[Uint, Tuple[Log, ...], Optional[Exception]]:
) -> Tuple[Uint, Tuple[Log, ...], Optional[EthereumException]]:
"""
Execute a transaction against the provided environment.
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum/berlin/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ethereum_types.numeric import U64, U256, Uint

from ethereum.crypto.hash import Hash32
from ethereum.exceptions import EthereumException

from ..blocks import Log
from ..fork_types import Address
Expand Down Expand Up @@ -90,7 +91,7 @@ class Evm:
accounts_to_delete: Set[Address]
touched_accounts: Set[Address]
return_data: Bytes
error: Optional[Exception]
error: Optional[EthereumException]
accessed_addresses: Set[Address]
accessed_storage_keys: Set[Tuple[Address, Bytes32]]

Expand Down
8 changes: 5 additions & 3 deletions src/ethereum/berlin/vm/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
A straightforward interpreter that executes EVM code.
"""

from dataclasses import dataclass
from typing import Iterable, Optional, Set, Tuple
from typing import Optional, Set, Tuple

from ethereum_types.bytes import Bytes0
from ethereum_types.numeric import U256, Uint, ulen

from ethereum.exceptions import EthereumException
from ethereum.trace import (
EvmStop,
OpEnd,
Expand Down Expand Up @@ -82,8 +84,8 @@ class MessageCallOutput:
refund_counter: U256
logs: Tuple[Log, ...]
accounts_to_delete: Set[Address]
touched_accounts: Iterable[Address]
error: Optional[Exception]
touched_accounts: Set[Address]
error: Optional[EthereumException]


def process_message_call(
Expand Down
10 changes: 7 additions & 3 deletions src/ethereum/byzantium/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

from ethereum.crypto.hash import Hash32, keccak256
from ethereum.ethash import dataset_size, generate_cache, hashimoto_light
from ethereum.exceptions import InvalidBlock, InvalidSenderError
from ethereum.exceptions import (
EthereumException,
InvalidBlock,
InvalidSenderError,
)

from . import vm
from .blocks import Block, Header, Log, Receipt
Expand Down Expand Up @@ -339,7 +343,7 @@ def check_transaction(

def make_receipt(
tx: Transaction,
error: Optional[Exception],
error: Optional[EthereumException],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
) -> Receipt:
Expand Down Expand Up @@ -632,7 +636,7 @@ def pay_rewards(

def process_transaction(
env: vm.Environment, tx: Transaction
) -> Tuple[Uint, Tuple[Log, ...], Optional[Exception]]:
) -> Tuple[Uint, Tuple[Log, ...], Optional[EthereumException]]:
"""
Execute a transaction against the provided environment.
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum/byzantium/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ethereum_types.numeric import U256, Uint

from ethereum.crypto.hash import Hash32
from ethereum.exceptions import EthereumException

from ..blocks import Log
from ..fork_types import Address
Expand Down Expand Up @@ -87,7 +88,7 @@ class Evm:
accounts_to_delete: Set[Address]
touched_accounts: Set[Address]
return_data: Bytes
error: Optional[Exception]
error: Optional[EthereumException]


def incorporate_child_on_success(evm: Evm, child_evm: Evm) -> None:
Expand Down
8 changes: 5 additions & 3 deletions src/ethereum/byzantium/vm/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
A straightforward interpreter that executes EVM code.
"""

from dataclasses import dataclass
from typing import Iterable, Optional, Set, Tuple
from typing import Optional, Set, Tuple

from ethereum_types.bytes import Bytes0
from ethereum_types.numeric import U256, Uint, ulen

from ethereum.exceptions import EthereumException
from ethereum.trace import (
EvmStop,
OpEnd,
Expand Down Expand Up @@ -81,8 +83,8 @@ class MessageCallOutput:
refund_counter: U256
logs: Tuple[Log, ...]
accounts_to_delete: Set[Address]
touched_accounts: Iterable[Address]
error: Optional[Exception]
touched_accounts: Set[Address]
error: Optional[EthereumException]


def process_message_call(
Expand Down
10 changes: 7 additions & 3 deletions src/ethereum/cancun/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from ethereum_types.numeric import U64, U256, Uint

from ethereum.crypto.hash import Hash32, keccak256
from ethereum.exceptions import InvalidBlock, InvalidSenderError
from ethereum.exceptions import (
EthereumException,
InvalidBlock,
InvalidSenderError,
)

from . import vm
from .blocks import Block, Header, Log, Receipt, Withdrawal
Expand Down Expand Up @@ -421,7 +425,7 @@ def check_transaction(

def make_receipt(
tx: Transaction,
error: Optional[Exception],
error: Optional[EthereumException],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
) -> Union[Bytes, Receipt]:
Expand Down Expand Up @@ -696,7 +700,7 @@ def apply_body(

def process_transaction(
env: vm.Environment, tx: Transaction
) -> Tuple[Uint, Tuple[Log, ...], Optional[Exception]]:
) -> Tuple[Uint, Tuple[Log, ...], Optional[EthereumException]]:
"""
Execute a transaction against the provided environment.
Expand Down
7 changes: 4 additions & 3 deletions src/ethereum/cancun/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
There is a distinction between an account that does not exist and
`EMPTY_ACCOUNT`.
"""

from dataclasses import dataclass, field
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple
from typing import Callable, Dict, List, Optional, Set, Tuple

from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.frozen import modify
Expand Down Expand Up @@ -719,15 +720,15 @@ def set_transient_storage(


def destroy_touched_empty_accounts(
state: State, touched_accounts: Iterable[Address]
state: State, touched_accounts: Set[Address]
) -> None:
"""
Destroy all touched accounts that are empty.
Parameters
----------
state: `State`
The current state.
touched_accounts: `Iterable[Address]`
touched_accounts: `Set[Address]`
All the accounts that have been touched in the current transaction.
"""
for address in touched_accounts:
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum/cancun/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ethereum_types.numeric import U64, U256, Uint

from ethereum.crypto.hash import Hash32
from ethereum.exceptions import EthereumException

from ..blocks import Log
from ..fork_types import Address, VersionedHash
Expand Down Expand Up @@ -94,7 +95,7 @@ class Evm:
accounts_to_delete: Set[Address]
touched_accounts: Set[Address]
return_data: Bytes
error: Optional[Exception]
error: Optional[EthereumException]
accessed_addresses: Set[Address]
accessed_storage_keys: Set[Tuple[Address, Bytes32]]

Expand Down
10 changes: 6 additions & 4 deletions src/ethereum/cancun/vm/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
A straightforward interpreter that executes EVM code.
"""

from dataclasses import dataclass
from typing import Iterable, Optional, Set, Tuple, Union
from typing import Optional, Set, Tuple

from ethereum_types.bytes import Bytes0
from ethereum_types.numeric import U256, Uint, ulen

from ethereum.exceptions import EthereumException
from ethereum.trace import (
EvmStop,
OpEnd,
Expand Down Expand Up @@ -81,10 +83,10 @@ class MessageCallOutput:

gas_left: Uint
refund_counter: U256
logs: Union[Tuple[()], Tuple[Log, ...]]
logs: Tuple[Log, ...]
accounts_to_delete: Set[Address]
touched_accounts: Iterable[Address]
error: Optional[Exception]
touched_accounts: Set[Address]
error: Optional[EthereumException]


def process_message_call(
Expand Down
10 changes: 7 additions & 3 deletions src/ethereum/constantinople/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

from ethereum.crypto.hash import Hash32, keccak256
from ethereum.ethash import dataset_size, generate_cache, hashimoto_light
from ethereum.exceptions import InvalidBlock, InvalidSenderError
from ethereum.exceptions import (
EthereumException,
InvalidBlock,
InvalidSenderError,
)

from . import vm
from .blocks import Block, Header, Log, Receipt
Expand Down Expand Up @@ -339,7 +343,7 @@ def check_transaction(

def make_receipt(
tx: Transaction,
error: Optional[Exception],
error: Optional[EthereumException],
cumulative_gas_used: Uint,
logs: Tuple[Log, ...],
) -> Receipt:
Expand Down Expand Up @@ -632,7 +636,7 @@ def pay_rewards(

def process_transaction(
env: vm.Environment, tx: Transaction
) -> Tuple[Uint, Tuple[Log, ...], Optional[Exception]]:
) -> Tuple[Uint, Tuple[Log, ...], Optional[EthereumException]]:
"""
Execute a transaction against the provided environment.
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum/constantinople/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ethereum_types.numeric import U256, Uint

from ethereum.crypto.hash import Hash32
from ethereum.exceptions import EthereumException

from ..blocks import Log
from ..fork_types import Address
Expand Down Expand Up @@ -87,7 +88,7 @@ class Evm:
accounts_to_delete: Set[Address]
touched_accounts: Set[Address]
return_data: Bytes
error: Optional[Exception]
error: Optional[EthereumException]


def incorporate_child_on_success(evm: Evm, child_evm: Evm) -> None:
Expand Down
Loading

0 comments on commit 9923823

Please sign in to comment.