Skip to content

Commit

Permalink
Fix trace pending txns
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechos committed Jan 15, 2025
1 parent efe2165 commit 88f0cb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ func (h *Handler) traceTransaction(ctx context.Context, hash *felt.Felt) (*vm.Tr
httpHeader.Set(ExecutionStepsHeader, "0")

if err != nil {
if pendingB := h.syncReader.PendingBlock(); pendingB != nil {
txIndex := slices.IndexFunc(pendingB.Transactions, func(tx core.Transaction) bool {
return tx.Hash().Equal(hash)
})
if txIndex != -1 {
traceResults, header, traceBlockErr := h.traceBlockTransactions(ctx, pendingB)
if traceBlockErr != nil {
return nil, header, traceBlockErr
}
return traceResults[txIndex].TraceRoot, header, nil
}
}
return nil, httpHeader, ErrTxnHashNotFound
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestTraceTransaction(t *testing.T) {

t.Run("not found", func(t *testing.T) {
hash := utils.HexToFelt(t, "0xBBBB")
// Receipt() returns error related to db
mockReader.EXPECT().Receipt(hash).Return(nil, nil, uint64(0), db.ErrKeyNotFound)
mockSyncReader.EXPECT().PendingBlock().Return(nil)

trace, httpHeader, err := handler.TraceTransaction(context.Background(), *hash)
assert.Nil(t, trace)
Expand Down

0 comments on commit 88f0cb3

Please sign in to comment.