Skip to content

Commit

Permalink
fix lint, bad type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 16, 2023
1 parent d468fff commit 1c30130
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
16 changes: 10 additions & 6 deletions boa/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
from boa.util.abi import abi_decode
from boa.util.eip1167 import extract_eip1167_address, is_eip1167_contract
from boa.util.lrudict import lrudict
from boa.vm.fast_accountdb import (
FastAccountDB,
patch_pyevm_state_object,
unpatch_pyevm_state_object,
)
from boa.vm.fork import AccountDBFork
from boa.vm.fast_accountdb import FastAccountDB, patch_pyevm_state_object, unpatch_pyevm_state_object
from boa.vm.gas_meters import GasMeter, NoGasMeter, ProfilingGasMeter
from boa.vm.utils import to_bytes, to_int

Expand Down Expand Up @@ -337,22 +341,22 @@ def apply_create_message(cls, state, msg, tx_ctx):
def apply_computation(cls, state, msg, tx_ctx):
addr = msg.code_address
contract = cls.env._lookup_contract_fast(addr) if addr else None
#print("ENTER", Address(msg.code_address or bytes([0]*20)), contract)
# print("ENTER", Address(msg.code_address or bytes([0]*20)), contract)
if contract is None or not cls.env._fast_mode_enabled:
#print("SLOW MODE")
# print("SLOW MODE")
return super().apply_computation(state, msg, tx_ctx)

with cls(state, msg, tx_ctx) as computation:
try:
if getattr(msg, "_ir_executor", None) is not None:
#print("MSG HAS IR EXECUTOR")
# print("MSG HAS IR EXECUTOR")
# this happens when bytecode is overridden, e.g.
# for injected functions. note ir_executor is (correctly)
# used for the outer computation only because on subcalls
# a clean message is constructed for the child computation
msg._ir_executor.exec(computation)
else:
#print("REGULAR FAST MODE")
# print("REGULAR FAST MODE")
contract.ir_executor.exec(computation)
except Halt:
pass
Expand Down Expand Up @@ -560,7 +564,7 @@ def get_singleton(cls):
cls._singleton = cls()
return cls._singleton

def generate_address(self, alias: Optional[str] = None) -> AddressType:
def generate_address(self, alias: Optional[str] = None) -> _AddressType:
t = Address(self._random.randbytes(20))
if alias is not None:
self.alias(t, alias)
Expand Down
1 change: 1 addition & 0 deletions boa/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import contextlib
import time
import warnings
from dataclasses import dataclass
from functools import cached_property
from math import ceil

Expand Down
5 changes: 5 additions & 0 deletions boa/vm/fast_accountdb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from eth.db.account import AccountDB


class FastAccountDB(AccountDB):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# this is a hotspot in super().
def touch_account(self, address):
self._accessed_accounts.add(address)
Expand All @@ -11,8 +13,10 @@ def touch_account(self, address):
def _touch_account_patcher(self, address):
self._accessed_accounts.add(address)


_BOA_PATCHED = object()


def patch_pyevm_state_object(state_object):
if getattr(state_object, "__boa_patched__", None) == _BOA_PATCHED:
return
Expand All @@ -21,6 +25,7 @@ def patch_pyevm_state_object(state_object):
accountdb.touch_account = _touch_account_patcher.__get__(accountdb, AccountDB)
state_object.__boa_patched__ = True


def unpatch_pyevm_state_object(state_object):
if not getattr(state_object, "__boa_patched__", None) == _BOA_PATCHED:
return
Expand Down
2 changes: 0 additions & 2 deletions boa/vyper/compiler_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from vyper.ast.utils import parse_to_ast
from vyper.codegen.function_definitions import generate_ir_for_function
from vyper.codegen.ir_node import IRnode
from vyper.compiler.settings import OptimizationLevel
from vyper.exceptions import InvalidType
from vyper.ir import compile_ir, optimizer
from vyper.semantics.analysis.utils import get_exact_type_from_node
from vyper.utils import method_id_int

from boa.vyper import _METHOD_ID_VAR
from boa.vyper.ir_executor import executor_from_ir
Expand Down
10 changes: 6 additions & 4 deletions boa/vyper/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import vyper.semantics.namespace as vy_ns
from eth.exceptions import VMError
from vyper.ast.utils import parse_to_ast
from vyper.compiler.settings import OptimizationLevel
from vyper.codegen.core import calculate_type_for_external_return, anchor_opt_level
from vyper.codegen.core import anchor_opt_level, calculate_type_for_external_return
from vyper.codegen.function_definitions import generate_ir_for_function
from vyper.codegen.function_definitions.common import ExternalFuncIR, InternalFuncIR
from vyper.codegen.global_context import GlobalContext
Expand Down Expand Up @@ -271,9 +270,12 @@ def _handle_child_trace(computation, env, return_trace):
child = computation.children[-1]

# TODO: maybe should be:
# child_obj = env.lookup_contract(child.msg.code_address) or env._code_registry.get(child.msg.code)

# child_obj = (
# env.lookup_contract(child.msg.code_address)
# or env._code_registry.get(child.msg.code)
# )
child_obj = env.lookup_contract(child.msg.code_address)

if child_obj is None:
child_trace = trace_for_unknown_contract(child, env)
else:
Expand Down
5 changes: 1 addition & 4 deletions boa/vyper/ir_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,10 @@ def compile_main(self, contract_path=""):
self.builder.extend("\n\n")
func.compile_func()


py_file = contract_path + str(self.compile_ctx.uuid) + ".py"

# uncomment for debugging the python code:
#with open(py_file, "w") as f:
# with open(py_file, "w") as f:
# print(self.builder.get_output(), file=f)

py_bytecode = compile(self.builder.get_output(), py_file, "exec")
Expand Down Expand Up @@ -1124,8 +1123,6 @@ def _ensure_source_pos(ir_node, source_pos=None, error_msg=None):


def executor_from_ir(ir_node, vyper_compiler_data) -> Any:
import vyper.version

_ensure_source_pos(ir_node)
ret = _executor_from_ir(ir_node, CompileContext(vyper_compiler_data))

Expand Down

0 comments on commit 1c30130

Please sign in to comment.