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

feat: mev_simBundle #11252

Merged
merged 6 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/rpc/rpc/src/eth/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use reth_rpc_eth_api::{
EthCallBundleApiServer,
};
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError, RpcInvalidTransactionError};

/// `Eth` bundle implementation.
pub struct EthBundle<Eth> {
/// All nested fields bundled together.
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
76 changes: 76 additions & 0 deletions crates/rpc/rpc/src/eth/sim_bundle.rs
Original file line number Diff line number Diff line change
@@ -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<Eth> {
/// All nested fields bundled together.
inner: Arc<EthSimBundleInner<Eth>>,
}

impl<Eth> EthSimBundle<Eth> {
/// 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<Eth> EthSimBundle<Eth>
where
Eth: EthTransactions + LoadPendingBlock + Call + 'static,
{
/// Simulates a bundle of transactions.
pub async fn sim_bundle(
&self,
request: SendBundleRequest,
overrides: SimBundleOverrides,
) -> RpcResult<SimBundleResponse> {
info!("mev_simBundle called, request: {:?}, overrides: {:?}", request, overrides);
Err(EthApiError::Unsupported("mev_simBundle is not supported").into())
}
}

#[async_trait::async_trait]
impl<Eth> MevSimApiServer for EthSimBundle<Eth>
where
Eth: EthTransactions + LoadPendingBlock + Call + 'static,
{
async fn sim_bundle(
&self,
request: SendBundleRequest,
overrides: SimBundleOverrides,
) -> RpcResult<SimBundleResponse> {
Self::sim_bundle(self, request, overrides).await
}
}

/// Container type for `EthSimBundle` internals
#[derive(Debug)]
struct EthSimBundleInner<Eth> {
/// 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<Eth> std::fmt::Debug for EthSimBundle<Eth> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EthSimBundle").finish_non_exhaustive()
}
}

impl<Eth> Clone for EthSimBundle<Eth> {
fn clone(&self) -> Self {
Self { inner: Arc::clone(&self.inner) }
}
}
Loading