pub trait Call: LoadState + SpawnBlocking {
Show 18 methods
// Required methods
fn call_gas_limit(&self) -> u64;
fn max_simulate_blocks(&self) -> u64;
fn evm_config(&self) -> &impl ConfigureEvm;
// 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<DB>(
&self,
db: &mut CacheDB<DB>,
cfg: CfgEnvWithHandlerCfg,
block_env: BlockEnv,
transactions: impl IntoIterator<Item = TransactionSignedEcRecovered>,
target_tx_hash: FixedBytes<32>,
) -> Result<usize, Self::Error>
where DB: DatabaseRef,
EthApiError: From<<DB as DatabaseRef>::Error> { ... }
fn estimate_gas_at(
&self,
request: TransactionRequest,
at: BlockId,
state_override: Option<HashMap<Address, AccountOverride>>,
) -> impl Future<Output = Result<Uint<256, 4>, Self::Error>> + Send
where Self: LoadPendingBlock { ... }
fn estimate_gas_with<S>(
&self,
cfg: CfgEnvWithHandlerCfg,
block: BlockEnv,
request: TransactionRequest,
state: S,
state_override: Option<HashMap<Address, AccountOverride>>,
) -> Result<Uint<256, 4>, Self::Error>
where S: StateProvider { ... }
fn update_estimated_gas_range(
&self,
result: ExecutionResult,
tx_gas_limit: u64,
highest_gas_limit: &mut u64,
lowest_gas_limit: &mut u64,
) -> Result<(), Self::Error> { ... }
fn map_out_of_gas_err<S>(
&self,
env_gas_limit: Uint<256, 4>,
env: EnvWithHandlerCfg,
db: &mut CacheDB<StateProviderDatabase<S>>,
) -> Self::Error
where S: StateProvider { ... }
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,
gas_limit: u64,
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
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
fn max_simulate_blocks(&self) -> u64
Returns the maximum number of blocks accepted for eth_simulateV1
.
fn evm_config(&self) -> &impl ConfigureEvm
fn evm_config(&self) -> &impl ConfigureEvm
Returns a handle for reading evm config.
Data access in default (L1) trait method implementations.
Provided Methods§
fn with_state_at_block<F, R>(&self, at: BlockId, f: F) -> Result<R, Self::Error>
fn with_state_at_block<F, R>(&self, at: BlockId, f: F) -> 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>
fn transact<DB>( &self, db: DB, env: EnvWithHandlerCfg, ) -> Result<(ResultAndState, EnvWithHandlerCfg), Self::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>
fn transact_with_inspector<DB>( &self, db: DB, env: EnvWithHandlerCfg, inspector: impl GetInspector<DB>, ) -> Result<(ResultAndState, EnvWithHandlerCfg), Self::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>> + Sendwhere
Self: LoadPendingBlock,
fn transact_call_at(
&self,
request: TransactionRequest,
at: BlockId,
overrides: EvmOverrides,
) -> impl Future<Output = Result<(ResultAndState, EnvWithHandlerCfg), Self::Error>> + Sendwhere
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
fn spawn_with_state_at_block<F, R>( &self, at: BlockId, f: F, ) -> impl Future<Output = Result<R, Self::Error>> + Send
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>> + Sendwhere
Self: LoadPendingBlock,
F: FnOnce(StateCacheDbRefMutWrapper<'_, '_>, EnvWithHandlerCfg) -> 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>> + Sendwhere
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
.
fn spawn_replay_transaction<F, R>(
&self,
hash: FixedBytes<32>,
f: F,
) -> impl Future<Output = Result<Option<R>, Self::Error>> + Sendwhere
Self: LoadBlock + LoadPendingBlock + LoadTransaction,
F: FnOnce(TransactionInfo, ResultAndState, CacheDB<StateProviderDatabase<StateProviderTraitObjWrapper<'_>>>) -> 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>> + Sendwhere
Self: LoadBlock + LoadPendingBlock + LoadTransaction,
F: FnOnce(TransactionInfo, ResultAndState, CacheDB<StateProviderDatabase<StateProviderTraitObjWrapper<'_>>>) -> Result<R, Self::Error> + Send + 'static,
R: Send + 'static,
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<DB>(
&self,
db: &mut CacheDB<DB>,
cfg: CfgEnvWithHandlerCfg,
block_env: BlockEnv,
transactions: impl IntoIterator<Item = TransactionSignedEcRecovered>,
target_tx_hash: FixedBytes<32>,
) -> Result<usize, Self::Error>
fn replay_transactions_until<DB>( &self, db: &mut CacheDB<DB>, cfg: CfgEnvWithHandlerCfg, block_env: BlockEnv, transactions: impl IntoIterator<Item = TransactionSignedEcRecovered>, 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 estimate_gas_at(
&self,
request: TransactionRequest,
at: BlockId,
state_override: Option<HashMap<Address, AccountOverride>>,
) -> impl Future<Output = Result<Uint<256, 4>, Self::Error>> + Sendwhere
Self: LoadPendingBlock,
fn estimate_gas_at(
&self,
request: TransactionRequest,
at: BlockId,
state_override: Option<HashMap<Address, AccountOverride>>,
) -> impl Future<Output = Result<Uint<256, 4>, Self::Error>> + Sendwhere
Self: LoadPendingBlock,
Estimate gas needed for execution of the request
at the BlockId
.
fn estimate_gas_with<S>(
&self,
cfg: CfgEnvWithHandlerCfg,
block: BlockEnv,
request: TransactionRequest,
state: S,
state_override: Option<HashMap<Address, AccountOverride>>,
) -> Result<Uint<256, 4>, Self::Error>where
S: StateProvider,
fn estimate_gas_with<S>(
&self,
cfg: CfgEnvWithHandlerCfg,
block: BlockEnv,
request: TransactionRequest,
state: S,
state_override: Option<HashMap<Address, AccountOverride>>,
) -> Result<Uint<256, 4>, Self::Error>where
S: StateProvider,
Estimates the gas usage of the request
with the state.
This will execute the TransactionRequest
and find the best gas limit via binary search.
§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 totrue
disable_base_fee
is set totrue
nonce
is set toNone
fn update_estimated_gas_range(
&self,
result: ExecutionResult,
tx_gas_limit: u64,
highest_gas_limit: &mut u64,
lowest_gas_limit: &mut u64,
) -> Result<(), Self::Error>
fn update_estimated_gas_range( &self, result: ExecutionResult, tx_gas_limit: u64, highest_gas_limit: &mut u64, lowest_gas_limit: &mut u64, ) -> Result<(), Self::Error>
Updates the highest and lowest gas limits for binary search based on the execution result.
This function refines the gas limit estimates used in a binary search to find the optimal gas limit for a transaction. It adjusts the highest or lowest gas limits depending on whether the execution succeeded, reverted, or halted due to specific reasons.
fn map_out_of_gas_err<S>(
&self,
env_gas_limit: Uint<256, 4>,
env: EnvWithHandlerCfg,
db: &mut CacheDB<StateProviderDatabase<S>>,
) -> Self::Errorwhere
S: StateProvider,
fn map_out_of_gas_err<S>(
&self,
env_gas_limit: Uint<256, 4>,
env: EnvWithHandlerCfg,
db: &mut CacheDB<StateProviderDatabase<S>>,
) -> Self::Errorwhere
S: StateProvider,
Executes the requests again after an out of gas error to check if the error is gas related or not
fn create_txn_env(
&self,
block_env: &BlockEnv,
request: TransactionRequest,
) -> Result<TxEnv, Self::Error>
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>
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,
gas_limit: u64,
db: &mut CacheDB<DB>,
overrides: EvmOverrides,
) -> Result<EnvWithHandlerCfg, Self::Error>
fn prepare_call_env<DB>( &self, cfg: CfgEnvWithHandlerCfg, block: BlockEnv, request: TransactionRequest, gas_limit: u64, db: &mut CacheDB<DB>, overrides: EvmOverrides, ) -> Result<EnvWithHandlerCfg, Self::Error>
Prepares the EnvWithHandlerCfg
for execution.
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 totrue
disable_base_fee
is set totrue
nonce
is set toNone
Additionally, the block gas limit so that higher tx gas limits can be used in eth_call
.
disable_block_gas_limit
is set totrue