Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

feat(bundles): Support backrun bundles execution #32

Merged
cody-wang-cb merged 20 commits into
mainfrom
cody/builder_backrun
Dec 23, 2025
Merged

feat(bundles): Support backrun bundles execution #32
cody-wang-cb merged 20 commits into
mainfrom
cody/builder_backrun

Conversation

@cody-wang-cb

@cody-wang-cb cody-wang-cb commented Dec 17, 2025

Copy link
Copy Markdown

Summary

  • Adds a new base_sendBackrunBundle RPC endpoint and in-memory store to enable backrun transactions to execute immediately after their target transactions during block building.
  • In the block building loop
    • checks the backrun bundles after executing the target transactions
    • sorts bundles in terms of priority fee
    • validates the bundle priority fee >= target priority fee
    • executes bundles in the order of priority fee
  • It also should handle replacement as it replaces bundles from the same sender targeting the same tx
  • Added integration tests for the backrun bundles logic
  • Moved resource_metering and backrun bundle into one single store

✅ I have completed the following steps:

  • Run make lint
  • Run make test
  • Added tests (if applicable)

@dvush dvush left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like that this implementation is simple to understand and it solves the problem of mempool replacements in an elegant way.

There are couple of things that I wanted to point out as possible issues.

Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
@cody-wang-cb
cody-wang-cb requested a review from dvush December 19, 2025 17:10
Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
Comment thread crates/op-rbuilder/src/builders/context.rs
Comment thread crates/op-rbuilder/src/bundles.rs Outdated
Comment thread crates/op-rbuilder/src/bundles.rs Outdated
Comment on lines +611 to +623
// Pre-compute total fees and sort bundles (descending)
let mut bundles_with_fees: Vec<_> = backrun_bundles
.into_iter()
.map(|bundle| {
let total_fee: u128 = bundle
.backrun_txs
.iter()
.map(|tx| tx.effective_tip_per_gas(base_fee).unwrap_or(0))
.sum();
(bundle, total_fee)
})
.collect();
bundles_with_fees.sort_by(|a, b| b.1.cmp(&a.1));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lets move this logic into the backrun store and outside of the main build loop. It'll:

  • Make merging upstream changes easier in the future (less of a diff to this file)
  • Less change of delaying building

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

One reason i decided to do it here is that i i think backrun insertion should be as fast as possible to remove any possible delays for finding backrun bundles

But i guess maybe this kind of sorting is super fast such that the latency is negligible

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One reason i decided to do it here is that i i think backrun insertion should be as fast as possible to remove any possible delays for finding backrun bundles

If this code adds noticeable overhead, I would rather us slow down the backrun RPC over the build loop (as this would impact the rest of the chain).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

oh, one thing is that
tx.effective_tip_per_gas(base_fee) must be computed at execution time.

During insertion we only have max_priority_fee_per_gas which is not the actual tip during execution.

What im thinking is that

  • we could sort by max_priority_fee_per_gas during insertion
  • but at execution time, will still need to compute tx.effective_tip_per_gas(base_fee) again for validation (bundles priority fee >= target tx priority fee)

what do you think?

Comment thread crates/op-rbuilder/src/builders/context.rs
Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
Comment thread crates/op-rbuilder/src/bundles.rs Outdated
Comment thread crates/op-rbuilder/src/builders/context.rs
Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
Comment thread crates/op-rbuilder/src/builders/context.rs Outdated
}

pending_results.push((backrun_tx, result, state));
pending_results.push((backrun_tx.clone(), consensus_tx, result, state));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we maybe able to remove a bunch of the clones in this codepath, but happy to do that as a followup.

@cody-wang-cb
cody-wang-cb merged commit ac1f545 into main Dec 23, 2025
8 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants