mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix(mev): Fix issues in mev_simBundle. (#14502)
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
//! `Eth` Sim bundle implementation and helpers.
|
//! `Eth` Sim bundle implementation and helpers.
|
||||||
|
|
||||||
|
use alloy_consensus::BlockHeader;
|
||||||
use alloy_eips::BlockNumberOrTag;
|
use alloy_eips::BlockNumberOrTag;
|
||||||
use alloy_primitives::U256;
|
use alloy_primitives::U256;
|
||||||
use alloy_rpc_types_eth::{BlockId, BlockOverrides};
|
use alloy_rpc_types_eth::{BlockId, BlockOverrides};
|
||||||
@ -13,7 +14,7 @@ use reth_provider::ProviderTx;
|
|||||||
use reth_revm::database::StateProviderDatabase;
|
use reth_revm::database::StateProviderDatabase;
|
||||||
use reth_rpc_api::MevSimApiServer;
|
use reth_rpc_api::MevSimApiServer;
|
||||||
use reth_rpc_eth_api::{
|
use reth_rpc_eth_api::{
|
||||||
helpers::{Call, EthTransactions, LoadPendingBlock},
|
helpers::{block::LoadBlock, Call, EthTransactions},
|
||||||
FromEthApiError, FromEvmError,
|
FromEthApiError, FromEvmError,
|
||||||
};
|
};
|
||||||
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError};
|
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError};
|
||||||
@ -83,7 +84,7 @@ impl<Eth> EthSimBundle<Eth> {
|
|||||||
|
|
||||||
impl<Eth> EthSimBundle<Eth>
|
impl<Eth> EthSimBundle<Eth>
|
||||||
where
|
where
|
||||||
Eth: EthTransactions + LoadPendingBlock + Call + 'static,
|
Eth: EthTransactions + LoadBlock + Call + 'static,
|
||||||
{
|
{
|
||||||
/// Flattens a potentially nested bundle into a list of individual transactions in a
|
/// Flattens a potentially nested bundle into a list of individual transactions in a
|
||||||
/// `FlattenedBundleItem` with their associated metadata. This handles recursive bundle
|
/// `FlattenedBundleItem` with their associated metadata. This handles recursive bundle
|
||||||
@ -221,7 +222,7 @@ where
|
|||||||
Ok(items)
|
Ok(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn sim_bundle(
|
async fn sim_bundle_inner(
|
||||||
&self,
|
&self,
|
||||||
request: SendBundleRequest,
|
request: SendBundleRequest,
|
||||||
overrides: SimBundleOverrides,
|
overrides: SimBundleOverrides,
|
||||||
@ -234,8 +235,10 @@ where
|
|||||||
// Also, flatten the bundle here so that its easier to process
|
// Also, flatten the bundle here so that its easier to process
|
||||||
let flattened_bundle = self.parse_and_flatten_bundle(&request)?;
|
let flattened_bundle = self.parse_and_flatten_bundle(&request)?;
|
||||||
|
|
||||||
let block_id = parent_block.unwrap_or(BlockId::Number(BlockNumberOrTag::Pending));
|
let block_id = parent_block.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
|
||||||
let (mut evm_env, current_block) = self.eth_api().evm_env_at(block_id).await?;
|
let (mut evm_env, current_block_id) = self.eth_api().evm_env_at(block_id).await?;
|
||||||
|
let current_block = self.eth_api().block_with_senders(current_block_id).await?;
|
||||||
|
let current_block = current_block.ok_or(EthApiError::HeaderNotFound(block_id))?;
|
||||||
|
|
||||||
// apply overrides
|
// apply overrides
|
||||||
if let Some(block_number) = number {
|
if let Some(block_number) = number {
|
||||||
@ -263,9 +266,9 @@ where
|
|||||||
let sim_response = self
|
let sim_response = self
|
||||||
.inner
|
.inner
|
||||||
.eth_api
|
.eth_api
|
||||||
.spawn_with_state_at_block(current_block, move |state| {
|
.spawn_with_state_at_block(current_block_id, move |state| {
|
||||||
// Setup environment
|
// Setup environment
|
||||||
let current_block_number = current_block.as_u64().unwrap();
|
let current_block_number = current_block.number();
|
||||||
let coinbase = evm_env.block_env.coinbase;
|
let coinbase = evm_env.block_env.coinbase;
|
||||||
let basefee = evm_env.block_env.basefee;
|
let basefee = evm_env.block_env.basefee;
|
||||||
let db = CacheDB::new(StateProviderDatabase::new(state));
|
let db = CacheDB::new(StateProviderDatabase::new(state));
|
||||||
@ -405,10 +408,7 @@ where
|
|||||||
revert: None,
|
revert: None,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await
|
.await?;
|
||||||
.map_err(|_| {
|
|
||||||
EthApiError::InvalidParams(EthSimBundleError::BundleTimeout.to_string())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(sim_response)
|
Ok(sim_response)
|
||||||
}
|
}
|
||||||
@ -417,7 +417,7 @@ where
|
|||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl<Eth> MevSimApiServer for EthSimBundle<Eth>
|
impl<Eth> MevSimApiServer for EthSimBundle<Eth>
|
||||||
where
|
where
|
||||||
Eth: EthTransactions + LoadPendingBlock + Call + 'static,
|
Eth: EthTransactions + LoadBlock + Call + 'static,
|
||||||
{
|
{
|
||||||
async fn sim_bundle(
|
async fn sim_bundle(
|
||||||
&self,
|
&self,
|
||||||
@ -434,11 +434,11 @@ where
|
|||||||
.unwrap_or(DEFAULT_SIM_TIMEOUT);
|
.unwrap_or(DEFAULT_SIM_TIMEOUT);
|
||||||
|
|
||||||
let bundle_res =
|
let bundle_res =
|
||||||
tokio::time::timeout(timeout, Self::sim_bundle(self, request, overrides, true))
|
tokio::time::timeout(timeout, Self::sim_bundle_inner(self, request, overrides, true))
|
||||||
.await
|
.await
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
EthApiError::InvalidParams(EthSimBundleError::BundleTimeout.to_string())
|
EthApiError::InvalidParams(EthSimBundleError::BundleTimeout.to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
bundle_res.map_err(Into::into)
|
bundle_res.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user