Skip to content

Conversation

@meetrick
Copy link

@meetrick meetrick commented Dec 22, 2025

Summary

Fix log collection in mev_simBundle to preserve the hierarchical structure of nested bundles.

Problem

When MEV searchers simulate nested bundles using mev_simBundle, the response logs were flattened into a single array. This made it impossible to determine which transactions belonged to which nested bundle.

Example: Arbitrage strategy with backrun

Arbitrage Bundle
├── tx1: Buy on DEX A
├── Backrun Bundle
│   ├── tx2: Target transaction
│   └── tx3: Sell on DEX B
└── tx4: Collect profit

Before (Flattened - Structure Lost)

{
  "logs": [
    { "txLogs": ["tx1 logs"], "bundleLogs": null },
    { "txLogs": ["tx2 logs"], "bundleLogs": null },
    { "txLogs": ["tx3 logs"], "bundleLogs": null },
    { "txLogs": ["tx4 logs"], "bundleLogs": null }
  ]
}

→ Cannot identify tx2, tx3 belong to Backrun Bundle

After (Hierarchical - Structure Preserved)

{
  "logs": [
    { "txLogs": ["tx1 logs"], "bundleLogs": null },
    { "txLogs": null, "bundleLogs": [
        { "txLogs": ["tx2 logs"], "bundleLogs": null },
        { "txLogs": ["tx3 logs"], "bundleLogs": null }
    ]},
    { "txLogs": ["tx4 logs"], "bundleLogs": null }
  ]
}

→ Backrun Bundle clearly identified via bundleLogs

Note: txLogs and bundleLogs are mutually exclusive by design - a SimBundleLogs entry represents either a transaction (with txLogs) or a nested bundle (with bundleLogs), never both.

User Benefits

  • Accurate debugging: Identify exactly which nested bundle caused failures
  • Strategy analysis: Analyze gas usage and events per sub-bundle
  • Proper API behavior: SimBundleLogs.bundle_logs field now works as intended

Changes

  • Add build_bundle_logs() using stack-based iteration to reconstruct log hierarchy (avoids recursive calls)
  • Add bundle_path field to FlattenedBundleItem to track each transaction's position in the bundle hierarchy
  • Store logs in HashMap during execution for structure reconstruction
  • Add 4 unit tests for nested bundle log collection

- Add build_bundle_logs() to recursively build SimBundleLogs tree
- Add raw_tx_hash field to FlattenedBundleItem for consistent hash matching
- Use HashMap to map transaction hashes to logs
- Add unit tests for nested bundle log collection

Signed-off-by: Hwangjae Lee <[email protected]>
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Dec 22, 2025
@meetrick meetrick marked this pull request as ready for review December 22, 2025 07:57
@mattsse
Copy link
Collaborator

mattsse commented Dec 22, 2025

{ "txLogs": null, "bundleLogs": [
{ "txLogs": ["tx2 logs"], "bundleLogs": null },
{ "txLogs": ["tx3 logs"], "bundleLogs": null }
]},

does that mean that txLogs and bundeLogs are mutually exclusive?

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

thanks, all of this makes sense

but I believe we can also populate the logs if use smth like a stack of logs instead because I'd like to avoid having recursive calls here

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Dec 22, 2025
@mattsse mattsse added C-bug An unexpected or incorrect behavior A-rpc Related to the RPC implementation labels Dec 22, 2025
@meetrick
Copy link
Author

maybe a better approach here would be to include the bundle depth in the FlattenedBundleItem as an identifier then we can populate the body_logs properly

Yes, txLogs and bundleLogs are mutually exclusive by design.
And I'll refactor to remove the recursive call.

- Replace recursive build_bundle_logs() with stack-based iteration
- Add bundle_path to FlattenedBundleItem for tracking item position
- Revert formatting changes per review feedback
- Update tests to use iterative approach

Signed-off-by: Hwangjae Lee <[email protected]>
Signed-off-by: Hwangjae Lee <[email protected]>
@meetrick
Copy link
Author

meetrick commented Dec 23, 2025

@mattsse I have updated the code based on your suggestion and ran the tests using the same approach as before.
I would appreciate it if you could take another look.

@meetrick meetrick requested a review from mattsse December 24, 2025 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rpc Related to the RPC implementation C-bug An unexpected or incorrect behavior

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants