From f8e3cdfc278b51feffbb9d12e79dc77a530550b2 Mon Sep 17 00:00:00 2001 From: 0xfourzerofour Date: Tue, 26 Sep 2023 09:31:49 -0400 Subject: [PATCH] feat(sender): update based on comments --- bin/rundler/src/cli/builder.rs | 10 +++++----- crates/builder/src/lib.rs | 3 ++- crates/builder/src/sender/flashbots.rs | 10 ++++------ crates/builder/src/sender/mod.rs | 23 ++++++++++------------- crates/builder/src/task.rs | 6 +++--- docs/config.md | 4 ++-- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/bin/rundler/src/cli/builder.rs b/bin/rundler/src/cli/builder.rs index 58d33d756..6709afacc 100644 --- a/bin/rundler/src/cli/builder.rs +++ b/bin/rundler/src/cli/builder.rs @@ -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}; @@ -93,7 +93,7 @@ pub struct BuilderArgs { )] pub submit_url: Option, - /// 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( @@ -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 @@ -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, diff --git a/crates/builder/src/lib.rs b/crates/builder/src/lib.rs index e1d54a73f..afaced347 100644 --- a/crates/builder/src/lib.rs +++ b/crates/builder/src/lib.rs @@ -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, @@ -19,7 +20,7 @@ mod bundle_sender; mod emit; /// Builder sender implementations -pub mod sender; +mod sender; mod server; diff --git a/crates/builder/src/sender/flashbots.rs b/crates/builder/src/sender/flashbots.rs index 0a22ddaa7..8a97568c2 100644 --- a/crates/builder/src/sender/flashbots.rs +++ b/crates/builder/src/sender/flashbots.rs @@ -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; @@ -180,11 +179,10 @@ impl FlashbotsClient { } async fn send_transaction(&self, raw_tx: Bytes) -> anyhow::Result { - 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) } } diff --git a/crates/builder/src/sender/mod.rs b/crates/builder/src/sender/mod.rs index 61bab5ab2..01e66738b 100644 --- a/crates/builder/src/sender/mod.rs +++ b/crates/builder/src/sender/mod.rs @@ -83,7 +83,7 @@ pub enum TransactionSenderType { /// Bloxroute transaction sender /// /// Currently only supported on Polygon mainnet - PolygonBloxRoute, + PolygonBloxroute, } impl FromStr for TransactionSenderType { @@ -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'"), } } } @@ -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() } @@ -118,7 +118,7 @@ impl TransactionSenderType { chain_id: u64, eth_poll_interval: Duration, bloxroute_header: &Option, - ) -> Result, SenderErrors> { + ) -> Result, SenderConstructorErrors> { let sender = match self { Self::Raw => TransactionSenderEnum::Raw(RawTransactionSender::new(client, signer)), Self::Conditional => TransactionSenderEnum::Conditional( @@ -126,17 +126,17 @@ impl TransactionSenderType { ), 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(), )); @@ -149,7 +149,7 @@ impl TransactionSenderType { header, )?) } else { - return Err(SenderErrors::BloxRouteMissingToken); + return Err(SenderConstructorErrors::BloxRouteMissingToken); } } }; @@ -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, diff --git a/crates/builder/src/task.rs b/crates/builder/src/task.rs index d265aee6f..e557c63fd 100644 --- a/crates/builder/src/task.rs +++ b/crates/builder/src/task.rs @@ -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 @@ -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, diff --git a/docs/config.md b/docs/config.md index dd04ed5ff..7dfca0bef 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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`)