Skip to content

Commit

Permalink
feat(sender): update based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfourzerofour committed Sep 26, 2023
1 parent e26956c commit f8e3cdf
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
10 changes: 5 additions & 5 deletions bin/rundler/src/cli/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::Context;
use clap::Args;
use ethers::types::H256;
use rundler_builder::{
self, sender::TransactionSenderType, BuilderEvent, BuilderEventKind, BuilderTask,
BuilderTaskArgs, LocalBuilderBuilder,
self, BuilderEvent, BuilderEventKind, BuilderTask, BuilderTaskArgs, LocalBuilderBuilder,
TransactionSenderType,
};
use rundler_pool::RemotePoolClient;
use rundler_sim::{MempoolConfig, PriorityFeeMode};
Expand Down Expand Up @@ -93,7 +93,7 @@ pub struct BuilderArgs {
)]
pub submit_url: Option<String>,

/// Choice of what url you would like to send the transactions to.
/// Choice of what sender type to to use for transaction submission.
/// Defaults to the value of `raw`. Other options inclue `flashbots`,
/// `conditional` and `polygon_bloxroute`
#[arg(
Expand All @@ -103,7 +103,7 @@ pub struct BuilderArgs {
value_enum,
default_value = "raw"
)]
pub sender: TransactionSenderType,
pub sender_type: TransactionSenderType,

/// After submitting a bundle transaction, the maximum number of blocks to
/// wait for that transaction to mine before we try resending with higher
Expand Down Expand Up @@ -204,7 +204,7 @@ impl BuilderArgs {
use_bundle_priority_fee: common.use_bundle_priority_fee,
bundle_priority_fee_overhead_percent: common.bundle_priority_fee_overhead_percent,
priority_fee_mode,
sender: self.sender.clone(),
sender_type: self.sender_type.clone(),
eth_poll_interval: Duration::from_millis(common.eth_poll_interval_millis),
sim_settings: common.try_into()?,
mempool_configs,
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 @@ -7,6 +7,7 @@
//! Bundle builder implementation for the Rundler.

pub use emit::{BuilderEvent, BuilderEventKind};
pub use sender::TransactionSenderType;
pub use server::{
BuilderResult, BuilderServer, BuilderServerError, BundlingMode, LocalBuilderBuilder,
LocalBuilderHandle, RemoteBuilderClient,
Expand All @@ -19,7 +20,7 @@ mod bundle_sender;
mod emit;

/// Builder sender implementations
pub mod sender;
mod sender;

mod server;

Expand Down
10 changes: 4 additions & 6 deletions crates/builder/src/sender/flashbots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use ethers::{
transaction::eip2718::TypedTransaction, Address, Bytes, TransactionReceipt, TxHash, H256,
U256, U64,
},
utils::hex,
};
use ethers_signers::Signer;
use futures_timer::Delay;
Expand Down Expand Up @@ -180,11 +179,10 @@ impl FlashbotsClient {
}

async fn send_transaction(&self, raw_tx: Bytes) -> anyhow::Result<TxHash> {
let req = FlashbotsRequest {
transaction: hex::encode(raw_tx),
};
let response: FlashbotsResponse =
self.client.request("eth_sendRawTransaction", req).await?;
let response: FlashbotsResponse = self
.client
.request("eth_sendRawTransaction", (raw_tx,))
.await?;
Ok(response.tx_hash)
}
}
Expand Down
23 changes: 10 additions & 13 deletions crates/builder/src/sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub enum TransactionSenderType {
/// Bloxroute transaction sender
///
/// Currently only supported on Polygon mainnet
PolygonBloxRoute,
PolygonBloxroute,
}

impl FromStr for TransactionSenderType {
Expand All @@ -94,8 +94,8 @@ impl FromStr for TransactionSenderType {
"raw" => Ok(TransactionSenderType::Raw),
"conditional" => Ok(TransactionSenderType::Conditional),
"flashbots" => Ok(TransactionSenderType::Flashbots),
"polygon_bloxroute" => Ok(TransactionSenderType::PolygonBloxRoute),
_ => bail!("Hello"),
"polygon_bloxroute" => Ok(TransactionSenderType::PolygonBloxroute),
_ => bail!("Invalid sender input. Must be one of either 'raw', 'conditional', 'flashbots' or 'polygon_bloxroute'"),
}
}
}
Expand All @@ -106,7 +106,7 @@ impl TransactionSenderType {
TransactionSenderType::Raw => "raw",
TransactionSenderType::Conditional => "conditional",
TransactionSenderType::Flashbots => "flashbots",
TransactionSenderType::PolygonBloxRoute => "polygon_bloxroute",
TransactionSenderType::PolygonBloxroute => "polygon_bloxroute",
}
.to_string()
}
Expand All @@ -118,25 +118,25 @@ impl TransactionSenderType {
chain_id: u64,
eth_poll_interval: Duration,
bloxroute_header: &Option<String>,
) -> Result<TransactionSenderEnum<C, S>, SenderErrors> {
) -> Result<TransactionSenderEnum<C, S>, SenderConstructorErrors> {
let sender = match self {
Self::Raw => TransactionSenderEnum::Raw(RawTransactionSender::new(client, signer)),
Self::Conditional => TransactionSenderEnum::Conditional(
ConditionalTransactionSender::new(client, signer),
),
Self::Flashbots => {
if chain_id != Chain::Mainnet as u64 {
return Err(SenderErrors::InvalidChainForSender(
return Err(SenderConstructorErrors::InvalidChainForSender(
chain_id,
self.into_snake_case(),
));
}
TransactionSenderEnum::Flashbots(FlashbotsTransactionSender::new(client, signer)?)
}
Self::PolygonBloxRoute => {
Self::PolygonBloxroute => {
if let Some(header) = bloxroute_header {
if chain_id == Chain::Polygon as u64 {
return Err(SenderErrors::InvalidChainForSender(
return Err(SenderConstructorErrors::InvalidChainForSender(
chain_id,
self.into_snake_case(),
));
Expand All @@ -149,7 +149,7 @@ impl TransactionSenderType {
header,
)?)
} else {
return Err(SenderErrors::BloxRouteMissingToken);
return Err(SenderConstructorErrors::BloxRouteMissingToken);
}
}
};
Expand All @@ -159,16 +159,13 @@ impl TransactionSenderType {

/// Custom errors for sender implementations
#[derive(Debug, thiserror::Error)]
pub enum SenderErrors {
pub(crate) enum SenderConstructorErrors {
/// Anyhow error fallback
#[error(transparent)]
Internal(#[from] anyhow::Error),
/// Invalid Chain ID error for sender
#[error("Chain ID: {0} cannot be used with the {1} sender")]
InvalidChainForSender(u64, String),
/// Unknown sender type error
#[error("Unknown sender type: {0}")]
UnknownSenderType(String),
/// Bloxroute missing token error
#[error("Missing token for Bloxroute API")]
BloxRouteMissingToken,
Expand Down
6 changes: 3 additions & 3 deletions crates/builder/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ pub struct Args {
pub bundle_priority_fee_overhead_percent: u64,
/// Priority fee mode to use for operation priority fee minimums
pub priority_fee_mode: PriorityFeeMode,
/// What sender should be used by the builder
pub sender: TransactionSenderType,
/// Sender to be used by the builder
pub sender_type: TransactionSenderType,
/// RPC node poll interval
pub eth_poll_interval: Duration,
/// Operation simulation settings
Expand Down Expand Up @@ -272,7 +272,7 @@ where
let submit_provider =
eth::new_provider(&self.args.submit_url, self.args.eth_poll_interval)?;

let transaction_sender = self.args.sender.clone().into_sender(
let transaction_sender = self.args.sender_type.clone().into_sender(
submit_provider,
signer,
self.args.chain_id,
Expand Down
4 changes: 2 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ List of command line options for configuring the Builder.
- env: *BUILDER_MAX_BUNDLE_SIZE*
- `--builder.submit_url`: If present, the URL of the ETH provider that will be used to send transactions. Defaults to the value of `node_http`.
- env: *BUILDER_SUBMIT_URL*
- `--builder.use_conditional_send_transaction`: If true, will use the provider's `eth_sendRawTransactionConditional` method instead of `eth_sendRawTransaction`, passing in expected storage values determined through simulation. Must not be set on networks which do not support this method (default: `false`)
- env: *BUILDER_USE_CONDITIONAL_SEND_TRANSACTION*
- `--builder.sender`: Choice of what sender type to to use for transaction submission. (default: `raw`, options: `raw`, `conditional`, `flashbots`, `polygon_bloxroute`)
- env: *BUILDER_SENDER*
- `--builder.max_blocks_to_wait_for_mine`: After submitting a bundle transaction, the maximum number of blocks to wait for that transaction to mine before trying to resend with higher gas fees (default: `2`)
- env: *BUILDER_MAX_BLOCKS_TO_WAIT_FOR_MINE*
- `--builder.replacement_fee_percent_increase`: Percentage amount to increase gas fees when retrying a transaction after it failed to mine (default: `10`)
Expand Down

0 comments on commit f8e3cdf

Please sign in to comment.