Skip to content

Latest commit

 

History

History
190 lines (149 loc) · 5.81 KB

File metadata and controls

190 lines (149 loc) · 5.81 KB

Tracing Phase Logging Fix

Problem

The application was getting stuck at "Tracing Origins" phase with no feedback about what was happening. Users couldn't see:

  • Which wallet was being traced
  • What API calls were being made
  • How deep the trace was going
  • Where the process was stuck

Solution

Added comprehensive logging throughout the entire token tracing process.

New Logging Added

1. TokenTracker Constructor

  • Added logCallback parameter
  • Created log() method to output messages

2. analyzeAndTrace Method

Analyzing DEX transactions from block X to Y...
Found N total transactions (X sells, Y buys)

=== Tracing sell #1/3: 0x1234...5678 ===
[Detailed trace logs...]
=== Completed trace #1/3 ===

3. traceToOrigin Method (Recursive)

Each depth level shows:

[Depth 0] Tracing wallet 0x1234...5678 at block 36230305
[Depth 0] Searching for first incoming transfer to 0x1234...5678...
  Searching blocks 36229305-36230305 for 0x1234...5678...
  Found 2 incoming transfer(s) for 0x1234...5678
[Depth 0] Found transfer from 0xabcd...ef01 at block 36229800
[Depth 0] → Recursively tracing 0xabcd...ef01...

[Depth 1] Tracing wallet 0xabcd...ef01 at block 36229800
[Depth 1] Searching for first incoming transfer to 0xabcd...ef01...
  Searching blocks 36228800-36229800 for 0xabcd...ef01...
  No transfers found in this range, searching earlier blocks...
  Searching blocks 36227800-36228799 for 0xabcd...ef01...
  Found 1 incoming transfer(s) for 0xabcd...ef01
[Depth 1] Found transfer from 0xdex0...pool at block 36228100
[Depth 1] ✓ Source is origin: dex (0xdex0...pool)

4. Origin Detection

[Depth N] ✓ Origin found: dex (0x1234...5678)
[Depth N] ✓ Source is origin: contract (0xabcd...ef01)
[Depth N] ⚠ Already processed 0x1234...5678, stopping trace
[Depth N] ⚠ Max depth reached for 0x1234...5678
[Depth N] ⚠ No incoming transfers found for 0x1234...5678

5. Search Progress

  Searching blocks 36229305-36230305 for 0x1234...5678...
  Found 2 incoming transfer(s) for 0x1234...5678
  
  No transfers found in this range, searching earlier blocks...
  Searching blocks 36228305-36229304 for 0x1234...5678...
  
  Search exhausted for 0x1234...5678 (searched 50 chunks)

6. Error Handling

[Depth N] ❌ Error tracing 0x1234...5678: [error message]

What Users Now See

Before (Stuck)

12:33:28 PM - Tracing Origins
Found 3 sell transaction(s) to trace
[Nothing more... appears frozen]

After (Detailed Progress)

12:33:28 PM - Tracing Origins
Found 3 sell transaction(s) to trace

12:33:29 PM - Token Tracer
Analyzing DEX transactions from block 36230305 to 36230305...

12:33:29 PM - Token Tracer
Found 3 total transactions (3 sells, 0 buys)

12:33:29 PM - Token Tracer
=== Tracing sell #1/3: 0x1234...5678 ===

12:33:29 PM - Token Tracer
[Depth 0] Tracing wallet 0x1234...5678 at block 36230305

12:33:29 PM - Token Tracer
[Depth 0] Searching for first incoming transfer to 0x1234...5678...

12:33:30 PM - Token Tracer
  Searching blocks 36229305-36230305 for 0x1234...5678...

12:33:31 PM - Blockchain API
API Call: eth_getLogs for blocks 36229305-36229314 (10 blocks)

12:33:32 PM - Blockchain API
Received 5 transfer events (filtering zero-value)

... [continues with detailed progress]

Benefits

  1. Transparency: Users see exactly what's happening
  2. Debugging: Easy to identify where process is slow or stuck
  3. Trust: Shows the app is working, not frozen
  4. Performance Insight: Can see which operations take time
  5. Error Identification: Quickly spot where failures occur

Technical Implementation

Files Modified:

  1. src/utils/tracker.ts

    • Added logCallback parameter to constructor
    • Added log() method
    • Added depth parameter to traceToOrigin()
    • Added logging at every major step
    • Added logging in findFirstIncomingTransfer()
    • Added logging in analyzeAndTrace()
  2. src/components/AnalysisForm.tsx

    • Pass log callback to TokenTracker constructor

Log Message Format

  • [Depth N]: Shows recursion depth (0 = original seller)
  • : Success/completion
  • : Warning/limitation reached
  • : Error occurred
  • : Recursive call
  • Indented: Sub-operations (like block searches)

Performance Impact

Minimal - logging only adds string operations and state updates. The actual blockchain queries remain the same.

Testing

Test scenarios:

  1. ✅ Trace that reaches DEX pool origin
  2. ✅ Trace that reaches token contract origin
  3. ✅ Trace with multiple hops (depth > 1)
  4. ✅ Trace that hits max depth
  5. ✅ Trace with no incoming transfers found
  6. ✅ Multiple sells being traced sequentially

Example Full Trace Log

=== Tracing sell #1/3: 0x1234...5678 ===
[Depth 0] Tracing wallet 0x1234...5678 at block 36230305
[Depth 0] Searching for first incoming transfer to 0x1234...5678...
  Searching blocks 36229305-36230305 for 0x1234...5678...
  Found 1 incoming transfer(s) for 0x1234...5678
[Depth 0] Found transfer from 0xabcd...ef01 at block 36229800
[Depth 0] → Recursively tracing 0xabcd...ef01...
[Depth 1] Tracing wallet 0xabcd...ef01 at block 36229800
[Depth 1] Searching for first incoming transfer to 0xabcd...ef01...
  Searching blocks 36228800-36229800 for 0xabcd...ef01...
  Found 1 incoming transfer(s) for 0xabcd...ef01
[Depth 1] Found transfer from 0xpool...addr at block 36228900
[Depth 1] ✓ Source is origin: dex (0xpool...addr)
=== Completed trace #1/3 ===

This shows:

  1. Starting trace for seller
  2. Searching for where they got tokens
  3. Found they received from another wallet
  4. Recursively trace that wallet
  5. Found that wallet received from DEX pool
  6. Origin identified as DEX
  7. Trace complete

Conclusion

Users now have complete visibility into the tracing process, making it clear the app is working and showing exactly what it's doing at each step.