reth::rpc::api::servers::eth::helpers::call

Trait Call

pub trait Call: LoadState + SpawnBlocking
where Self::Evm: ConfigureEvm<Header = Header>,
{
Show 13 methods // Required methods fn call_gas_limit(&self) -> u64; fn max_simulate_blocks(&self) -> u64; // Provided methods fn with_state_at_block<F, R>( &self, at: BlockId, f: F, ) -> Result<R, Self::Error> where F: FnOnce(StateProviderTraitObjWrapper<'_>) -> Result<R, Self::Error> { ... } fn transact<DB>( &self, db: DB, env: EnvWithHandlerCfg, ) -> Result<(ResultAndState, EnvWithHandlerCfg), Self::Error> where DB: Database, EthApiError: From<<DB as Database>::Error> { ... } fn transact_with_inspector<DB>( &self, db: DB, env: EnvWithHandlerCfg, inspector: impl GetInspector<DB>, ) -> Result<(ResultAndState, EnvWithHandlerCfg), Self::Error> where DB: Database, EthApiError: From<<DB as Database>::Error> { ... } fn transact_call_at( &self, request: TransactionRequest, at: BlockId, overrides: EvmOverrides, ) -> impl Future<Output = Result<(ResultAndState, EnvWithHandlerCfg), Self::Error>> + Send where Self: LoadPendingBlock { ... } fn spawn_with_state_at_block<F, R>( &self, at: BlockId, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + Send where F: FnOnce(StateProviderTraitObjWrapper<'_>) -> Result<R, Self::Error> + Send + 'static, R: Send + 'static { ... } fn spawn_with_call_at<F, R>( &self, request: TransactionRequest, at: BlockId, overrides: EvmOverrides, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + Send where Self: LoadPendingBlock, F: FnOnce(StateCacheDbRefMutWrapper<'_, '_>, EnvWithHandlerCfg) -> Result<R, Self::Error> + Send + 'static, R: Send + 'static { ... } fn spawn_replay_transaction<F, R>( &self, hash: FixedBytes<32>, f: F, ) -> impl Future<Output = Result<Option<R>, Self::Error>> + Send where Self: LoadBlock + LoadPendingBlock + LoadTransaction, F: FnOnce(TransactionInfo, ResultAndState, CacheDB<StateProviderDatabase<StateProviderTraitObjWrapper<'_>>>) -> Result<R, Self::Error> + Send + 'static, R: Send + 'static { ... } fn replay_transactions_until<'a, DB, I>( &self, db: &mut DB, cfg: CfgEnvWithHandlerCfg, block_env: BlockEnv, transactions: I, target_tx_hash: FixedBytes<32>, ) -> Result<usize, Self::Error> where DB: Database + DatabaseCommit, EthApiError: From<<DB as Database>::Error>, I: IntoIterator<Item = (&'a Address, &'a TransactionSigned)> { ... } fn create_txn_env( &self, block_env: &BlockEnv, request: TransactionRequest, ) -> Result<TxEnv, Self::Error> { ... } fn build_call_evm_env( &self, cfg: CfgEnvWithHandlerCfg, block: BlockEnv, request: TransactionRequest, ) -> Result<EnvWithHandlerCfg, Self::Error> { ... } fn prepare_call_env<DB>( &self, cfg: CfgEnvWithHandlerCfg, block: BlockEnv, request: TransactionRequest, db: &mut CacheDB<DB>, overrides: EvmOverrides, ) -> Result<EnvWithHandlerCfg, Self::Error> where DB: DatabaseRef, EthApiError: From<<DB as DatabaseRef>::Error> { ... }
}
Expand description

Executes code on state.

Required Methods§

fn call_gas_limit(&self) -> u64

Returns default gas limit to use for eth_call and tracing RPC methods.

Data access in default trait method implementations.

fn max_simulate_blocks(&self) -> u64

Returns the maximum number of blocks accepted for eth_simulateV1.

Provided Methods§

fn with_state_at_block<F, R>(&self, at: BlockId, f: F) -> Result<R, Self::Error>
where F: FnOnce(StateProviderTraitObjWrapper<'_>) -> Result<R, Self::Error>,

Executes the closure with the state that corresponds to the given BlockId.

fn transact<DB>( &self, db: DB, env: EnvWithHandlerCfg, ) -> Result<(ResultAndState, EnvWithHandlerCfg), Self::Error>
where DB: Database, EthApiError: From<<DB as Database>::Error>,

Executes the EnvWithHandlerCfg against the given Database without committing state changes.

fn transact_with_inspector<DB>( &self, db: DB, env: EnvWithHandlerCfg, inspector: impl GetInspector<DB>, ) -> Result<(ResultAndState, EnvWithHandlerCfg), Self::Error>
where DB: Database, EthApiError: From<<DB as Database>::Error>,

Executes the EnvWithHandlerCfg against the given Database without committing state changes.

fn transact_call_at( &self, request: TransactionRequest, at: BlockId, overrides: EvmOverrides, ) -> impl Future<Output = Result<(ResultAndState, EnvWithHandlerCfg), Self::Error>> + Send
where Self: LoadPendingBlock,

Executes the call request at the given BlockId.

fn spawn_with_state_at_block<F, R>( &self, at: BlockId, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + Send
where F: FnOnce(StateProviderTraitObjWrapper<'_>) -> Result<R, Self::Error> + Send + 'static, R: Send + 'static,

Executes the closure with the state that corresponds to the given BlockId on a new task

fn spawn_with_call_at<F, R>( &self, request: TransactionRequest, at: BlockId, overrides: EvmOverrides, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + Send
where Self: LoadPendingBlock, F: FnOnce(StateCacheDbRefMutWrapper<'_, '_>, EnvWithHandlerCfg) -> Result<R, Self::Error> + Send + 'static, R: Send + 'static,

Prepares the state and env for the given TransactionRequest at the given BlockId and executes the closure on a new task returning the result of the closure.

This returns the configured EnvWithHandlerCfg for the given TransactionRequest at the given BlockId and with configured call settings: prepare_call_env.

This is primarily used by eth_call.

§Blocking behaviour

This assumes executing the call is relatively more expensive on IO than CPU because it transacts a single transaction on an empty in memory database. Because eth_calls are usually allowed to consume a lot of gas, this also allows a lot of memory operations so we assume this is not primarily CPU bound and instead spawn the call on a regular tokio task instead, where blocking IO is less problematic.

fn spawn_replay_transaction<F, R>( &self, hash: FixedBytes<32>, f: F, ) -> impl Future<Output = Result<Option<R>, Self::Error>> + Send

Retrieves the transaction if it exists and executes it.

Before the transaction is executed, all previous transaction in the block are applied to the state by executing them first. The callback f is invoked with the ResultAndState after the transaction was executed and the database that points to the beginning of the transaction.

Note: Implementers should use a threadpool where blocking is allowed, such as BlockingTaskPool.

fn replay_transactions_until<'a, DB, I>( &self, db: &mut DB, cfg: CfgEnvWithHandlerCfg, block_env: BlockEnv, transactions: I, target_tx_hash: FixedBytes<32>, ) -> Result<usize, Self::Error>

Replays all the transactions until the target transaction is found.

All transactions before the target transaction are executed and their changes are written to the runtime db (CacheDB).

Note: This assumes the target transaction is in the given iterator. Returns the index of the target transaction in the given iterator.

fn create_txn_env( &self, block_env: &BlockEnv, request: TransactionRequest, ) -> Result<TxEnv, Self::Error>

Configures a new TxEnv for the TransactionRequest

All TxEnv fields are derived from the given TransactionRequest, if fields are None, they fall back to the BlockEnv’s settings.

fn build_call_evm_env( &self, cfg: CfgEnvWithHandlerCfg, block: BlockEnv, request: TransactionRequest, ) -> Result<EnvWithHandlerCfg, Self::Error>

Creates a new EnvWithHandlerCfg to be used for executing the TransactionRequest in eth_call.

Note: this does not access the Database to check the sender.

fn prepare_call_env<DB>( &self, cfg: CfgEnvWithHandlerCfg, block: BlockEnv, request: TransactionRequest, db: &mut CacheDB<DB>, overrides: EvmOverrides, ) -> Result<EnvWithHandlerCfg, Self::Error>

Prepares the EnvWithHandlerCfg for execution of calls.

Does not commit any changes to the underlying database.

§EVM settings

This modifies certain EVM settings to mirror geth’s SkipAccountChecks when transacting requests, see also: https://github.com/ethereum/go-ethereum/blob/380688c636a654becc8f114438c2a5d93d2db032/core/state_transition.go#L145-L148:

  • disable_eip3607 is set to true
  • disable_base_fee is set to true
  • nonce is set to None

In addition, this changes the block’s gas limit to the configured Self::call_gas_limit.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Provider, Pool, Network, EvmConfig> Call for EthApi<Provider, Pool, Network, EvmConfig>
where EthApi<Provider, Pool, Network, EvmConfig>: LoadState + SpawnBlocking, <EthApi<Provider, Pool, Network, EvmConfig> as RpcNodeCore>::Evm: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm<Header = Header>,