Skip to content

Commit

Permalink
fix(rpc): trace get is index not trace address (paradigmxyz#3852)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 19, 2023
1 parent 0fabd83 commit 0fcb338
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions crates/rpc/rpc-api/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ pub trait TraceApi {
async fn trace_filter(&self, filter: TraceFilter) -> RpcResult<Vec<LocalizedTransactionTrace>>;

/// Returns transaction trace at given index.
///
/// `indices` represent the index positions of the traces.
///
/// Note: This expects a list of indices but only one is supported since this function returns a
/// single [LocalizedTransactionTrace].
#[method(name = "get")]
async fn trace_get(
&self,
Expand Down
27 changes: 23 additions & 4 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,36 @@ where
.await
}

/// Returns transaction trace with the given address.
/// Returns transaction trace objects at the given index
///
/// Note: For compatibility reasons this only supports 1 single index, since this method is
/// supposed to return a single trace. See also: <https://github.com/ledgerwatch/erigon/blob/862faf054b8a0fa15962a9c73839b619886101eb/turbo/jsonrpc/trace_filtering.go#L114-L133>
///
/// This returns `None` if `indices` is empty
pub async fn trace_get(
&self,
hash: H256,
trace_address: Vec<usize>,
indices: Vec<usize>,
) -> EthResult<Option<LocalizedTransactionTrace>> {
if indices.len() != 1 {
// The OG impl failed if it gets more than a single index
return Ok(None)
}
self.trace_get_index(hash, indices[0]).await
}

/// Returns transaction trace object at the given index.
///
/// Returns `None` if the trace object at that index does not exist
pub async fn trace_get_index(
&self,
hash: H256,
index: usize,
) -> EthResult<Option<LocalizedTransactionTrace>> {
match self.trace_transaction(hash).await? {
None => Ok(None),
Some(traces) => {
let trace =
traces.into_iter().find(|trace| trace.trace.trace_address == trace_address);
let trace = traces.into_iter().nth(index);
Ok(trace)
}
}
Expand Down

0 comments on commit 0fcb338

Please sign in to comment.