Skip to content

Commit

Permalink
fix(builder): rework raw sender to support dropped/conditional/split-…
Browse files Browse the repository at this point in the history
…rpcs correctly
  • Loading branch information
dancoombs committed Jun 18, 2024
1 parent 3bb74c4 commit 12d649e
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 232 deletions.
58 changes: 49 additions & 9 deletions bin/rundler/src/cli/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use anyhow::Context;
use clap::Args;
use rundler_builder::{
self, BloxrouteSenderArgs, BuilderEvent, BuilderEventKind, BuilderTask, BuilderTaskArgs,
EntryPointBuilderSettings, FlashbotsSenderArgs, LocalBuilderBuilder, TransactionSenderArgs,
TransactionSenderKind,
EntryPointBuilderSettings, FlashbotsSenderArgs, LocalBuilderBuilder, RawSenderArgs,
TransactionSenderArgs, TransactionSenderKind,
};
use rundler_pool::RemotePoolClient;
use rundler_sim::{MempoolConfigs, PriorityFeeMode};
Expand Down Expand Up @@ -115,14 +115,48 @@ pub struct BuilderArgs {
/// If present, the url of the ETH provider that will be used to send
/// transactions. Defaults to the value of `node_http`.
///
/// Only used when BUILDER_SENDER is "raw" or "conditional"
/// Only used when BUILDER_SENDER is "raw"
#[arg(
long = "builder.submit_url",
name = "builder.submit_url",
env = "BUILDER_SUBMIT_URL"
)]
pub submit_url: Option<String>,

/// If present, the url of the ETH provider that will be used to check
/// transaction status. Else will use the node http for status.
///
/// Only used when BUILDER_SENDER is "raw"
#[arg(
long = "builder.use_submit_for_status",
name = "builder.use_submit_for_status",
env = "BUILDER_USE_SUBMIT_FOR_STATUS",
default_value = "false"
)]
pub use_submit_for_status: bool,

/// Use the conditional RPC endpoint for transaction submission.
///
/// Only used when BUILDER_SENDER is "raw"
#[arg(
long = "builder.use_conditional_rpc",
name = "builder.use_conditional_rpc",
env = "BUILDER_USE_CONDITIONAL_RPC",
default_value = "false"
)]
pub use_conditional_rpc: bool,

/// If the "dropped" status is unsupported by the status provider.
///
/// Only used when BUILDER_SENDER is "raw"
#[arg(
long = "builder.dropped_status_unsupported",
name = "builder.dropped_status_unsupported",
env = "BUILDER_DROPPED_STATUS_UNSUPPORTED",
default_value = "false"
)]
pub dropped_status_unsupported: bool,

/// A list of builders to pass into the Flashbots Relay RPC.
///
/// Only used when BUILDER_SENDER is "flashbots"
Expand Down Expand Up @@ -216,7 +250,6 @@ impl BuilderArgs {
.node_http
.clone()
.context("should have a node HTTP URL")?;
let submit_url = self.submit_url.clone().unwrap_or_else(|| rpc_url.clone());

let mempool_configs = match &common.mempool_config_path {
Some(path) => get_json_config::<MempoolConfigs>(path, &common.aws_region)
Expand Down Expand Up @@ -264,7 +297,7 @@ impl BuilderArgs {
));
}

let sender_args = self.sender_args(&chain_spec)?;
let sender_args = self.sender_args(&chain_spec, &rpc_url)?;

Ok(BuilderTaskArgs {
entry_points,
Expand All @@ -281,7 +314,6 @@ impl BuilderArgs {
redis_lock_ttl_millis: self.redis_lock_ttl_millis,
max_bundle_size: self.max_bundle_size,
max_bundle_gas: common.max_bundle_gas,
submit_url,
bundle_priority_fee_overhead_percent: common.bundle_priority_fee_overhead_percent,
priority_fee_mode,
sender_args,
Expand All @@ -294,10 +326,18 @@ impl BuilderArgs {
})
}

fn sender_args(&self, chain_spec: &ChainSpec) -> anyhow::Result<TransactionSenderArgs> {
fn sender_args(
&self,
chain_spec: &ChainSpec,
rpc_url: &str,
) -> anyhow::Result<TransactionSenderArgs> {
match self.sender_type {
TransactionSenderKind::Raw => Ok(TransactionSenderArgs::Raw),
TransactionSenderKind::Conditional => Ok(TransactionSenderArgs::Conditional),
TransactionSenderKind::Raw => Ok(TransactionSenderArgs::Raw(RawSenderArgs {
submit_url: self.submit_url.clone().unwrap_or_else(|| rpc_url.into()),
use_submit_for_status: self.use_submit_for_status,
dropped_status_supported: !self.dropped_status_unsupported,
use_conditional_rpc: self.use_conditional_rpc,
})),
TransactionSenderKind::Flashbots => {
if !chain_spec.flashbots_enabled {
return Err(anyhow::anyhow!("Flashbots sender is not enabled for chain"));
Expand Down
3 changes: 2 additions & 1 deletion crates/builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub use emit::{BuilderEvent, BuilderEventKind};

mod sender;
pub use sender::{
BloxrouteSenderArgs, FlashbotsSenderArgs, TransactionSenderArgs, TransactionSenderKind,
BloxrouteSenderArgs, FlashbotsSenderArgs, RawSenderArgs, TransactionSenderArgs,
TransactionSenderKind,
};

mod server;
Expand Down
130 changes: 0 additions & 130 deletions crates/builder/src/sender/conditional.rs

This file was deleted.

62 changes: 47 additions & 15 deletions crates/builder/src/sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
// If not, see https://www.gnu.org/licenses/.

mod bloxroute;
mod conditional;
mod flashbots;
mod raw;
use std::{sync::Arc, time::Duration};

use anyhow::Context;
use async_trait::async_trait;
pub(crate) use bloxroute::PolygonBloxrouteTransactionSender;
pub(crate) use conditional::ConditionalTransactionSender;
use enum_dispatch::enum_dispatch;
use ethers::{
prelude::SignerMiddleware,
Expand Down Expand Up @@ -111,7 +109,6 @@ where
FS: Signer + 'static,
{
Raw(RawTransactionSender<C, S>),
Conditional(ConditionalTransactionSender<C, S>),
Flashbots(FlashbotsTransactionSender<C, S, FS>),
PolygonBloxroute(PolygonBloxrouteTransactionSender<C, S>),
}
Expand All @@ -122,8 +119,6 @@ where
pub enum TransactionSenderKind {
/// Raw transaction sender
Raw,
/// Conditional transaction sender
Conditional,
/// Flashbots transaction sender
Flashbots,
/// Bloxroute transaction sender
Expand All @@ -134,15 +129,26 @@ pub enum TransactionSenderKind {
#[derive(Debug, Clone)]
pub enum TransactionSenderArgs {
/// Raw transaction sender
Raw,
/// Conditional transaction sender
Conditional,
Raw(RawSenderArgs),
/// Flashbots transaction sender
Flashbots(FlashbotsSenderArgs),
/// Bloxroute transaction sender
Bloxroute(BloxrouteSenderArgs),
}

/// Raw sender arguments
#[derive(Debug, Clone)]
pub struct RawSenderArgs {
/// Submit URL
pub submit_url: String,
/// Use submit for status
pub use_submit_for_status: bool,
/// If the "dropped" status is supported by the status provider
pub dropped_status_supported: bool,
/// If the sender should use the conditional endpoint
pub use_conditional_rpc: bool,
}

/// Bloxroute sender arguments
#[derive(Debug, Clone)]
pub struct BloxrouteSenderArgs {
Expand All @@ -166,21 +172,47 @@ pub struct FlashbotsSenderArgs {
impl TransactionSenderArgs {
pub(crate) fn into_sender<C: JsonRpcClient + 'static, S: Signer + 'static>(
self,
client: Arc<Provider<C>>,
rpc_provider: Arc<Provider<C>>,
submit_provider: Option<Arc<Provider<C>>>,
signer: S,
eth_poll_interval: Duration,
) -> std::result::Result<TransactionSenderEnum<C, S, LocalWallet>, SenderConstructorErrors>
{
let sender = match self {
Self::Raw => TransactionSenderEnum::Raw(RawTransactionSender::new(client, signer)),
Self::Conditional => TransactionSenderEnum::Conditional(
ConditionalTransactionSender::new(client, signer),
),
Self::Raw(args) => {
if let Some(submit_provider) = submit_provider {
if args.use_submit_for_status {
TransactionSenderEnum::Raw(RawTransactionSender::new(
Arc::clone(&submit_provider),
submit_provider,
signer,
args.dropped_status_supported,
args.use_conditional_rpc,
))
} else {
TransactionSenderEnum::Raw(RawTransactionSender::new(
rpc_provider,
submit_provider,
signer,
args.dropped_status_supported,
args.use_conditional_rpc,
))
}
} else {
TransactionSenderEnum::Raw(RawTransactionSender::new(
Arc::clone(&rpc_provider),
rpc_provider,
signer,
args.dropped_status_supported,
args.use_conditional_rpc,
))
}
}
Self::Flashbots(args) => {
let flashbots_signer = args.auth_key.parse().context("should parse auth key")?;

TransactionSenderEnum::Flashbots(FlashbotsTransactionSender::new(
client,
rpc_provider,
signer,
flashbots_signer,
args.builders,
Expand All @@ -190,7 +222,7 @@ impl TransactionSenderArgs {
}
Self::Bloxroute(args) => {
TransactionSenderEnum::PolygonBloxroute(PolygonBloxrouteTransactionSender::new(
client,
rpc_provider,
signer,
eth_poll_interval,
&args.header,
Expand Down
Loading

0 comments on commit 12d649e

Please sign in to comment.