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: add api bindings for eth_simulateV1 #10050

Merged
merged 1 commit into from
Aug 5, 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
29 changes: 24 additions & 5 deletions crates/rpc/rpc-eth-api/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Implementation of the [`jsonrpsee`] generated [`EthApiServer`] trait. Handles RPC requests for
//! the `eth_` namespace.

use crate::helpers::{
transaction::UpdateRawTxForwarder, EthApiSpec, EthBlocks, EthCall, EthFees, EthState,
EthTransactions, FullEthApi,
};
use alloy_dyn_abi::TypedData;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::{
Expand All @@ -9,18 +13,14 @@ use reth_primitives::{
use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
use reth_rpc_types::{
serde_helpers::JsonStorageKey,
simulate::{SimBlock, SimulatedBlock},
state::{EvmOverrides, StateOverride},
AnyTransactionReceipt, BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse,
FeeHistory, Header, Index, RichBlock, StateContext, SyncStatus, Transaction,
TransactionRequest, Work,
};
use tracing::trace;

use crate::helpers::{
transaction::UpdateRawTxForwarder, EthApiSpec, EthBlocks, EthCall, EthFees, EthState,
EthTransactions, FullEthApi,
};

/// Helper trait, unifies functionality that must be supported to implement all RPC methods for
/// server.
pub trait FullEthApiServer: EthApiServer + FullEthApi + UpdateRawTxForwarder + Clone {}
Expand Down Expand Up @@ -192,6 +192,15 @@ pub trait EthApi {
#[method(name = "getHeaderByHash")]
async fn header_by_hash(&self, hash: B256) -> RpcResult<Option<Header>>;

/// `eth_simulateV1` executes an arbitrary number of transactions on top of the requested state.
/// The transactions are packed into individual blocks. Overrides can be provided.
mattsse marked this conversation as resolved.
Show resolved Hide resolved
#[method(name = "simulateV1")]
async fn simulate_v1(
&self,
opts: SimBlock,
block_number: Option<BlockId>,
) -> RpcResult<Vec<SimulatedBlock>>;

/// Executes a new message call immediately without creating a transaction on the block chain.
#[method(name = "call")]
async fn call(
Expand Down Expand Up @@ -566,6 +575,16 @@ where
Ok(EthBlocks::rpc_block_header(self, hash.into()).await?)
}

/// Handler for: `eth_simulateV1`
async fn simulate_v1(
&self,
opts: SimBlock,
block_number: Option<BlockId>,
) -> RpcResult<Vec<SimulatedBlock>> {
trace!(target: "rpc::eth", ?block_number, "Serving eth_simulateV1");
Ok(EthCall::simulate_v1(self, opts, block_number).await?)
}

/// Handler for: `eth_call`
async fn call(
&self,
Expand Down
16 changes: 14 additions & 2 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Loads a pending block from database. Helper trait for `eth_` transaction, call and trace RPC
//! methods.

use crate::{AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError};
use futures::Future;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::{
Expand All @@ -26,15 +27,14 @@ use reth_rpc_server_types::constants::gas_oracle::{
CALL_STIPEND_GAS, ESTIMATE_GAS_ERROR_RATIO, MIN_TRANSACTION_GAS,
};
use reth_rpc_types::{
simulate::{SimBlock, SimulatedBlock},
state::{EvmOverrides, StateOverride},
BlockId, Bundle, EthCallResponse, StateContext, TransactionInfo, TransactionRequest,
};
use revm::{Database, DatabaseCommit};
use revm_inspectors::access_list::AccessListInspector;
use tracing::trace;

use crate::{AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError};

use super::{LoadBlock, LoadPendingBlock, LoadState, LoadTransaction, SpawnBlocking, Trace};

/// Execution related functions for the [`EthApiServer`](crate::EthApiServer) trait in
Expand All @@ -50,6 +50,18 @@ pub trait EthCall: Call + LoadPendingBlock {
Call::estimate_gas_at(self, request, at, state_override)
}

/// `eth_simulateV1` executes an arbitrary number of transactions on top of the requested state.
/// The transactions are packed into individual blocks. Overrides can be provided.
///
/// See also: <https://github.com/ethereum/go-ethereum/pull/27720>
fn simulate_v1(
&self,
_opts: SimBlock,
_block_number: Option<BlockId>,
) -> impl Future<Output = Result<Vec<SimulatedBlock>, Self::Error>> + Send {
async move { Err(EthApiError::Unsupported("eth_simulateV1 is not supported.").into()) }
}

/// Executes the call request (`eth_call`) and returns the output
fn call(
&self,
Expand Down
Loading