Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Send bundles (txs) to Flashbots #165

Closed
wants to merge 0 commits into from
Closed

Conversation

da-bao-jian
Copy link
Contributor

@da-bao-jian da-bao-jian commented Jul 18, 2023

Description

Sending bundles to Flashbot's Relay has the benefit of avoiding front-run and sandwich attacks. Currently, the bundler only supports sending transaction bundles through the public mempool, which is vulnerable to the said attacks above. As the volume of UserOperations picks up, each bundle submitted will likely generate more MEV, hence attracting more MEV bots.

Allowing the bundlers to submit bundles through Flashbots has the following benefits:

  • Avoiding the malicious MEV attacks from the public mempool
  • Paving the way to support more MEV-related features, such as MEV-protect and MEV-Share

Things changed

crates/bundler/.env.example

crates/bundler/Cargo.toml

  • Added ethers-flashbot, url, tokio crates to support functionalities in the send_next_bundle_flashbots function

crates/bundler/src/bundler.rs

  • Added the RELAY_ENDPOINTS for most of the commonly used block builder endpoint
  • Added the send_next_bundle_flashbots function

Pending Issues

There is no good way to test sending bundle using Flashbots unless a remote endpoint is used, such as Flashbots' Bundle Relay API on Goerli or Sepolia

Copy link
Collaborator

@zsluedem zsluedem left a comment

Choose a reason for hiding this comment

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

Left some comments

crates/bundler/src/bundler.rs Outdated Show resolved Hide resolved
crates/bundler/src/bundler.rs Outdated Show resolved Hide resolved
crates/bundler/src/bundler.rs Outdated Show resolved Hide resolved
crates/bundler/src/bundler.rs Outdated Show resolved Hide resolved
@@ -17,3 +17,6 @@ aa-bundler-primitives = { path = "../primitives" }
anyhow = "1"
ethers = { workspace = true }
tracing = { workspace = true }
ethers-flashbots = "0.13.1"
Copy link
Member

Choose a reason for hiding this comment

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

sort deps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what are the formatting and sorting rules for Cargo.toml

Even if I sorted the deps alphabetically, it when run make lint it still says not sorted

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, it should be alphabetically and nothing else. Is there any error text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

error: Cargo.toml for bundler is not formatted
Checking bundler...
error: Dependencies for bundler are not sorted
Checking contracts...
Checking grpc...
Checking primitives...
Checking rpc...
Checking uopool...
Checking examples...
error: Cargo.toml for examples is not formatted

If you check the example/Cargo.tomal, and bin/bundler/Cargo.toml in the latest commit, they should be alphabetically sorted.

Copy link
Member

Choose a reason for hiding this comment

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

It's not sorted because tokio should be before tracing

crates/bundler/src/bundler.rs Outdated Show resolved Hide resolved
crates/bundler/src/bundler.rs Outdated Show resolved Hide resolved
@Vid201 Vid201 linked an issue Jul 24, 2023 that may be closed by this pull request
@da-bao-jian da-bao-jian marked this pull request as ready for review July 25, 2023 04:44


[dependencies]
jsonrpsee = {version = "0.18.2", features = ["server", "http-client"]}
Copy link
Member

Choose a reason for hiding this comment

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

Is not formatted error is because features are not sorted and there is no whitespace between {version -> { version and "http-client"]} -> "http-client"] }

Copy link
Contributor Author

@da-bao-jian da-bao-jian Jul 25, 2023

Choose a reason for hiding this comment

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

Thanks for pointing it out!

I've added cargo sort --workspace command to the Makefile in the latest commit. Otherwise, it's a pain in the ass to sort & format deps manually.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that makes sense, cool

@@ -17,3 +17,6 @@ aa-bundler-primitives = { path = "../primitives" }
anyhow = "1"
ethers = { workspace = true }
tracing = { workspace = true }
ethers-flashbots = "0.13.1"
Copy link
Member

Choose a reason for hiding this comment

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

It's not sorted because tokio should be before tracing

@da-bao-jian
Copy link
Contributor Author

For the latest update, other than addressing the previous issues, I also added some comments for Rustdoc generation. Let me know what you think so that I could know if it's the correct format to go about adding rustdocs to other files. @Vid201

@Vid201
Copy link
Member

Vid201 commented Jul 26, 2023

For the latest update, other than addressing the previous issues, I also added some comments for Rustdoc generation. Let me know what you think so that I could know if it's the correct format to go about adding rustdocs to other files. @Vid201

Hey, I checked and it looks good, it would be perfect to have that

bin/bundler/src/bundler.rs Outdated Show resolved Hide resolved
crates/primitives/src/consts.rs Outdated Show resolved Hide resolved
@@ -49,6 +49,7 @@ impl BundlerService {
Ok(uos)
}

// TODO: add send bundle to flashbots
Copy link
Member

Choose a reason for hiding this comment

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

add CLI mode: ./bundler --send-bundle flashbots or ./bundler --send-bundle eth-client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this, here's how I could implement it

add the send-bundle command in bin/bundler/bundler. If flashbots, bundler should use the send_next_bundle_flashbots method by default. There are three places I could indicate the intent to send bundle via flashbots

Let me know which is the best option

Copy link
Member

Choose a reason for hiding this comment

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

I would make SendBundleMode enum and add an additional field to the Bundler struct. Enum is parsed from CLI and passed as an additiona field to the bundler_service_run which pushes it to the Bundler struct constructor.

@da-bao-jian
Copy link
Contributor Author

da-bao-jian commented Jul 27, 2023

As for testing, do you have any suggestions?

I could use flashbots builder on Goerli, but this requires Goerli ETH. In other words, not everyone is able to pass the test if he/she doesn't have Goerli ETH.

Alternatively, I could send an eth_simulate request. If the payload indicates success, it'll pass the test. I believe simulation requires no real payment.

@Vid201
Copy link
Member

Vid201 commented Jul 27, 2023

As for testing, do you have any suggestions?

I could use flashbots builder on Goerli, but this requires Goerli ETH. In other words, not everyone is able to pass the test if he/she doesn't have Goerli ETH.

Alternatively, I could send an eth_simulate request. If the payload indicates success, it'll pass the test. I believe simulation requires no real payment.

Makes sense. I think simulating is enough for the tests. Do you mean this endpoint: https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_callbundle ?

We can also have a test that is skipped during CI, but has to be manually run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send bundles (txs) to Flashbots
3 participants