Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: contract_type cache corruption #2540

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix for contract_type cache corruption
  • Loading branch information
BowTiedDevil committed Mar 7, 2025
commit 29c3c49ad273f6b8b48083ab7f46b624fa758eba
18 changes: 13 additions & 5 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,9 @@ def get_abi(_topic: HexStr) -> Optional[LogInputABICollection]:
value[struct_key] = (
self.decode_address(struct_val)
if struct_type == "address"
else HexBytes(struct_val) if "bytes" in struct_type else struct_val
else HexBytes(struct_val)
if "bytes" in struct_type
else struct_val
)
converted_arguments[key] = value

Expand Down Expand Up @@ -1188,6 +1190,10 @@ def _enrich_calltree(self, call: dict, **kwargs) -> dict:
return call

def _enrich_contract_id(self, address: AddressType, **kwargs) -> str:
# Defensively pop `contract_type` key from kwargs in case the contract type set by a
# previous call is not valid for this address.
kwargs.pop("contract_type", None)

if address and address == kwargs.get("sender"):
return "tx.origin"

Expand All @@ -1200,11 +1206,13 @@ def _enrich_contract_id(self, address: AddressType, **kwargs) -> str:

kwargs["contract_type"] = contract_type
if kwargs.get("use_symbol_for_tokens") and "symbol" in contract_type.view_methods:
# Use token symbol as name
contract = self.chain_manager.contracts.instance_at(
address, contract_type=contract_type
)
# Store contract_type in cache only if missing
if (contract := self.chain_manager.contracts.instance_at(address)) is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think instance_at() returns None, you probably want .get_contract_type() here.

Suggested change
if (contract := self.chain_manager.contracts.instance_at(address)) is None:
if (contract_type := self.chain_manager.contracts.get_contract_type(address)) is None:

contract = self.chain_manager.contracts.instance_at(
address, contract_type=contract_type
)

# Use token symbol as name
try:
symbol = contract.symbol(skip_trace=True)
except ApeException:
Expand Down