feat: mev_simBundle (#11252)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Skanda Bhat
2024-09-28 18:53:05 +05:30
committed by GitHub
parent 2aa3dd0fd8
commit 4850c298f0
3 changed files with 77 additions and 1 deletions

View File

@@ -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.

View File

@@ -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;

View File

@@ -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) }
}
}