From cf6562bd5cab6db56e810814b6aa77ba42f3ddb2 Mon Sep 17 00:00:00 2001 From: SkandaBhat Date: Thu, 26 Sep 2024 19:07:40 +0530 Subject: [PATCH 1/6] Add dummy implementation for mev_simBundle --- crates/rpc/rpc/src/eth/bundle.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/rpc/rpc/src/eth/bundle.rs b/crates/rpc/rpc/src/eth/bundle.rs index dd8f75898bfe..adeaf649c902 100644 --- a/crates/rpc/rpc/src/eth/bundle.rs +++ b/crates/rpc/rpc/src/eth/bundle.rs @@ -3,7 +3,10 @@ use std::sync::Arc; use alloy_primitives::{keccak256, U256}; -use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult}; +use alloy_rpc_types_mev::{ + EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult, SendBundleRequest, + SimBundleOverrides, SimBundleResponse, +}; use jsonrpsee::core::RpcResult; use reth_chainspec::EthChainSpec; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; @@ -21,12 +24,13 @@ use revm::{ use revm_primitives::{EnvKzgSettings, EnvWithHandlerCfg, SpecId, MAX_BLOB_GAS_PER_BLOCK}; use reth_provider::{ChainSpecProvider, HeaderProvider}; +use reth_rpc_api::MevSimApiServer; use reth_rpc_eth_api::{ helpers::{Call, EthTransactions, LoadPendingBlock}, EthCallBundleApiServer, }; use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError, RpcInvalidTransactionError}; - +use tracing::info; /// `Eth` bundle implementation. pub struct EthBundle { /// All nested fields bundled together. @@ -257,6 +261,16 @@ where }) .await } + + /// Simulates a bundle of transactions. + pub async fn sim_bundle( + &self, + request: SendBundleRequest, + overrides: SimBundleOverrides, + ) -> RpcResult { + info!("mev_simBundle called, request: {:?}, overrides: {:?}", request, overrides); + Err(EthApiError::Unsupported("mev_simBundle is not supported").into()) + } } #[async_trait::async_trait] @@ -269,6 +283,20 @@ where } } +#[async_trait::async_trait] +impl MevSimApiServer for EthBundle +where + Eth: EthTransactions + LoadPendingBlock + Call + 'static, +{ + async fn sim_bundle( + &self, + request: SendBundleRequest, + overrides: SimBundleOverrides, + ) -> RpcResult { + Self::sim_bundle(self, request, overrides).await.map_err(Into::into) + } +} + /// Container type for `EthBundle` internals #[derive(Debug)] struct EthBundleInner { From 27041da9658d8d5abf2412ea28270bb9864bf45c Mon Sep 17 00:00:00 2001 From: SkandaBhat Date: Fri, 27 Sep 2024 16:41:41 +0530 Subject: [PATCH 2/6] fix ambiguous use of into_rpc --- crates/rpc/rpc-builder/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 113cb93c4630..0a6a8ca451a2 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -1177,11 +1177,10 @@ where module.merge(eth_pubsub.clone().into_rpc()).expect("No conflicts"); module .merge( - EthBundle::new( + reth_rpc_api::EthCallBundleApiServer::into_rpc(EthBundle::new( eth_api.clone(), self.blocking_pool_guard.clone(), - ) - .into_rpc(), + )), ) .expect("No conflicts"); From e01e51bc397e526917d3135c487c2a89eb0a3658 Mon Sep 17 00:00:00 2001 From: SkandaBhat Date: Fri, 27 Sep 2024 16:44:16 +0530 Subject: [PATCH 3/6] lint fixes --- crates/rpc/rpc-builder/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 0a6a8ca451a2..ffd345f0be72 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -1176,12 +1176,12 @@ where module.merge(eth_filter.clone().into_rpc()).expect("No conflicts"); module.merge(eth_pubsub.clone().into_rpc()).expect("No conflicts"); module - .merge( - reth_rpc_api::EthCallBundleApiServer::into_rpc(EthBundle::new( + .merge(reth_rpc_api::EthCallBundleApiServer::into_rpc( + EthBundle::new( eth_api.clone(), self.blocking_pool_guard.clone(), - )), - ) + ), + )) .expect("No conflicts"); module.into() From 7485a63aa6835fd1e845b1df0ccc719b3c29ad15 Mon Sep 17 00:00:00 2001 From: SkandaBhat Date: Sat, 28 Sep 2024 15:28:22 +0530 Subject: [PATCH 4/6] separate EthSimBundle namespace --- crates/rpc/rpc/src/eth/bundle.rs | 29 +---------- crates/rpc/rpc/src/eth/mod.rs | 1 + crates/rpc/rpc/src/eth/sim_bundle.rs | 76 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 crates/rpc/rpc/src/eth/sim_bundle.rs diff --git a/crates/rpc/rpc/src/eth/bundle.rs b/crates/rpc/rpc/src/eth/bundle.rs index adeaf649c902..eb00adc4a73b 100644 --- a/crates/rpc/rpc/src/eth/bundle.rs +++ b/crates/rpc/rpc/src/eth/bundle.rs @@ -4,8 +4,7 @@ use std::sync::Arc; use alloy_primitives::{keccak256, U256}; use alloy_rpc_types_mev::{ - EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult, SendBundleRequest, - SimBundleOverrides, SimBundleResponse, + EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult }; use jsonrpsee::core::RpcResult; use reth_chainspec::EthChainSpec; @@ -24,13 +23,11 @@ use revm::{ use revm_primitives::{EnvKzgSettings, EnvWithHandlerCfg, SpecId, MAX_BLOB_GAS_PER_BLOCK}; use reth_provider::{ChainSpecProvider, HeaderProvider}; -use reth_rpc_api::MevSimApiServer; use reth_rpc_eth_api::{ helpers::{Call, EthTransactions, LoadPendingBlock}, EthCallBundleApiServer, }; use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError, RpcInvalidTransactionError}; -use tracing::info; /// `Eth` bundle implementation. pub struct EthBundle { /// All nested fields bundled together. @@ -261,16 +258,6 @@ where }) .await } - - /// Simulates a bundle of transactions. - pub async fn sim_bundle( - &self, - request: SendBundleRequest, - overrides: SimBundleOverrides, - ) -> RpcResult { - info!("mev_simBundle called, request: {:?}, overrides: {:?}", request, overrides); - Err(EthApiError::Unsupported("mev_simBundle is not supported").into()) - } } #[async_trait::async_trait] @@ -283,20 +270,6 @@ where } } -#[async_trait::async_trait] -impl MevSimApiServer for EthBundle -where - Eth: EthTransactions + LoadPendingBlock + Call + 'static, -{ - async fn sim_bundle( - &self, - request: SendBundleRequest, - overrides: SimBundleOverrides, - ) -> RpcResult { - Self::sim_bundle(self, request, overrides).await.map_err(Into::into) - } -} - /// Container type for `EthBundle` internals #[derive(Debug)] struct EthBundleInner { diff --git a/crates/rpc/rpc/src/eth/mod.rs b/crates/rpc/rpc/src/eth/mod.rs index 83db119f8804..99919110da7b 100644 --- a/crates/rpc/rpc/src/eth/mod.rs +++ b/crates/rpc/rpc/src/eth/mod.rs @@ -5,6 +5,7 @@ pub mod core; pub mod filter; pub mod helpers; pub mod pubsub; +pub mod sim_bundle; /// Implementation of `eth` namespace API. pub use bundle::EthBundle; diff --git a/crates/rpc/rpc/src/eth/sim_bundle.rs b/crates/rpc/rpc/src/eth/sim_bundle.rs new file mode 100644 index 000000000000..46dbb45d962e --- /dev/null +++ b/crates/rpc/rpc/src/eth/sim_bundle.rs @@ -0,0 +1,76 @@ +//! `Eth` Sim bundle implementation and helpers. + +use std::sync::Arc; + +use alloy_rpc_types_mev::{SendBundleRequest, SimBundleOverrides, SimBundleResponse}; +use jsonrpsee::core::RpcResult; +use reth_rpc_api::MevSimApiServer; +use reth_rpc_eth_api::helpers::{Call, EthTransactions, LoadPendingBlock}; +use reth_rpc_eth_types::EthApiError; +use reth_tasks::pool::BlockingTaskGuard; +use tracing::info; + +/// `Eth` sim bundle implementation. +pub struct EthSimBundle { + /// All nested fields bundled together. + inner: Arc>, +} + +impl EthSimBundle { + /// Create a new `EthSimBundle` instance. + pub fn new(eth_api: Eth, blocking_task_guard: BlockingTaskGuard) -> Self { + Self { inner: Arc::new(EthSimBundleInner { eth_api, blocking_task_guard }) } + } +} + +impl EthSimBundle +where + Eth: EthTransactions + LoadPendingBlock + Call + 'static, +{ + /// Simulates a bundle of transactions. + pub async fn sim_bundle( + &self, + request: SendBundleRequest, + overrides: SimBundleOverrides, + ) -> RpcResult { + info!("mev_simBundle called, request: {:?}, overrides: {:?}", request, overrides); + Err(EthApiError::Unsupported("mev_simBundle is not supported").into()) + } +} + +#[async_trait::async_trait] +impl MevSimApiServer for EthSimBundle +where + Eth: EthTransactions + LoadPendingBlock + Call + 'static, +{ + async fn sim_bundle( + &self, + request: SendBundleRequest, + overrides: SimBundleOverrides, + ) -> RpcResult { + Self::sim_bundle(self, request, overrides).await + } +} + +/// Container type for `EthSimBundle` internals +#[derive(Debug)] +struct EthSimBundleInner { + /// Access to commonly used code of the `eth` namespace + #[allow(dead_code)] + eth_api: Eth, + // restrict the number of concurrent tracing calls. + #[allow(dead_code)] + blocking_task_guard: BlockingTaskGuard, +} + +impl std::fmt::Debug for EthSimBundle { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("EthSimBundle").finish_non_exhaustive() + } +} + +impl Clone for EthSimBundle { + fn clone(&self) -> Self { + Self { inner: Arc::clone(&self.inner) } + } +} From 90af22e97e2e3b0090e2632cab61419f6bc02882 Mon Sep 17 00:00:00 2001 From: SkandaBhat Date: Sat, 28 Sep 2024 15:31:11 +0530 Subject: [PATCH 5/6] fix lint --- crates/rpc/rpc/src/eth/bundle.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/rpc/rpc/src/eth/bundle.rs b/crates/rpc/rpc/src/eth/bundle.rs index eb00adc4a73b..ee1f648f92ed 100644 --- a/crates/rpc/rpc/src/eth/bundle.rs +++ b/crates/rpc/rpc/src/eth/bundle.rs @@ -3,9 +3,7 @@ use std::sync::Arc; use alloy_primitives::{keccak256, U256}; -use alloy_rpc_types_mev::{ - EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult -}; +use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult}; use jsonrpsee::core::RpcResult; use reth_chainspec::EthChainSpec; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; From 53f01e5c828a1c135bc13acc785bc34a27eeacd5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 28 Sep 2024 15:09:46 +0200 Subject: [PATCH 6/6] undo fqs --- crates/rpc/rpc-builder/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index ffd345f0be72..113cb93c4630 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -1176,12 +1176,13 @@ where module.merge(eth_filter.clone().into_rpc()).expect("No conflicts"); module.merge(eth_pubsub.clone().into_rpc()).expect("No conflicts"); module - .merge(reth_rpc_api::EthCallBundleApiServer::into_rpc( + .merge( EthBundle::new( eth_api.clone(), self.blocking_pool_guard.clone(), - ), - )) + ) + .into_rpc(), + ) .expect("No conflicts"); module.into()