Skip to content

Commit

Permalink
perf: Merge branch 'perf/trace-return-value' into perf/tx-cache-ret-val
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 18, 2024
2 parents d8aad64 + b845d2d commit 84ca51e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ape_ethereum/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def return_value(self) -> Any:

# Barely enrich a calltree for performance reasons
# (likely not a need to enrich the whole thing).
calltree = self.get_raw_calltree()
calltree = self.get_calltree()
return self._get_return_value_from_calltree(calltree)

@cached_property
Expand All @@ -248,9 +248,13 @@ def _return_value_from_enriched_calltree(self) -> Any:

return self._get_return_value_from_calltree(calltree)

def _get_return_value_from_calltree(self, calltree: dict) -> tuple[Optional[Any], ...]:
def _get_return_value_from_calltree(
self, calltree: Union[dict, CallTreeNode]
) -> tuple[Optional[Any], ...]:
num_outputs = 1
if raw_return_data := calltree.get("returndata"):
if raw_return_data := (
calltree.get("returndata") if isinstance(calltree, dict) else calltree.returndata
):
if abi := self._get_abi(calltree):
# Ensure we return a tuple with the correct length, even if fails.
num_outputs = len(abi.outputs)
Expand Down Expand Up @@ -440,10 +444,10 @@ def _debug_trace_transaction_struct_logs_to_call(self) -> CallTreeNode:
def _get_tree(self, verbose: bool = False) -> Tree:
return parse_rich_tree(self.enriched_calltree, verbose=verbose)

def _get_abi(self, call: dict) -> Optional["MethodABI"]:
if not (addr := call.get("address")):
def _get_abi(self, call: Union[dict, CallTreeNode]) -> Optional["MethodABI"]:
if not (addr := call.get("address") if isinstance(call, dict) else call.address):
return self.root_method_abi
if not (calldata := call.get("calldata")):
if not (calldata := call.get("calldata") if isinstance(call, dict) else call.calldata):
return self.root_method_abi
if not (contract_type := self.chain_manager.contracts.get(addr)):
return self.root_method_abi
Expand Down

0 comments on commit 84ca51e

Please sign in to comment.