Skip to content

Commit

Permalink
feat: cleaned up prepare_call_env() (#11469)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
varun-doshi and mattsse authored Oct 4, 2024
1 parent af1eb61 commit 5fd6906
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
29 changes: 4 additions & 25 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ pub trait EthCall: Call + LoadPendingBlock {
)?;

let block = block.ok_or(EthApiError::HeaderNotFound(target_block))?;
let gas_limit = self.call_gas_limit();

// we're essentially replaying the transactions in the block here, hence we need the
// state that points to the beginning of the block, which is the state at
Expand Down Expand Up @@ -302,14 +301,7 @@ pub trait EthCall: Call + LoadPendingBlock {
let overrides = EvmOverrides::new(state_overrides, block_overrides.clone());

let env = this
.prepare_call_env(
cfg.clone(),
block_env.clone(),
tx,
gas_limit,
&mut db,
overrides,
)
.prepare_call_env(cfg.clone(), block_env.clone(), tx, &mut db, overrides)
.map(Into::into)?;
let (res, _) = this.transact(&mut db, env)?;

Expand Down Expand Up @@ -559,14 +551,7 @@ pub trait Call: LoadState + SpawnBlocking {
let mut db =
CacheDB::new(StateProviderDatabase::new(StateProviderTraitObjWrapper(&state)));

let env = this.prepare_call_env(
cfg,
block_env,
request,
this.call_gas_limit(),
&mut db,
overrides,
)?;
let env = this.prepare_call_env(cfg, block_env, request, &mut db, overrides)?;

f(StateCacheDbRefMutWrapper(&mut db), env)
})
Expand Down Expand Up @@ -1099,26 +1084,20 @@ pub trait Call: LoadState + SpawnBlocking {
mut cfg: CfgEnvWithHandlerCfg,
mut block: BlockEnv,
mut request: TransactionRequest,
gas_limit: u64,
db: &mut CacheDB<DB>,
overrides: EvmOverrides,
) -> Result<EnvWithHandlerCfg, Self::Error>
where
DB: DatabaseRef,
EthApiError: From<<DB as DatabaseRef>::Error>,
{
// TODO(mattsse): cleanup, by not disabling gaslimit and instead use self.call_gas_limit
if request.gas > Some(gas_limit) {
if request.gas > Some(self.call_gas_limit()) {
// configured gas exceeds limit
return Err(
EthApiError::InvalidTransaction(RpcInvalidTransactionError::GasTooHigh).into()
)
}

// we want to disable this in eth_call, since this is common practice used by other node
// impls and providers <https://github.com/foundry-rs/foundry/issues/4388>
cfg.disable_block_gas_limit = true;

// Disabled because eth_call is sometimes used with eoa senders
// See <https://github.com/paradigmxyz/reth/issues/1959>
cfg.disable_eip3607 = true;
Expand Down Expand Up @@ -1154,7 +1133,7 @@ pub trait Call: LoadState + SpawnBlocking {
// <https://github.com/ledgerwatch/erigon/blob/eae2d9a79cb70dbe30b3a6b79c436872e4605458/cmd/rpcdaemon/commands/trace_adhoc.go#L956
// https://github.com/ledgerwatch/erigon/blob/eae2d9a79cb70dbe30b3a6b79c436872e4605458/eth/ethconfig/config.go#L94>
trace!(target: "rpc::eth::call", ?env, "Applying gas limit cap as the maximum gas limit");
env.tx.gas_limit = gas_limit;
env.tx.gas_limit = self.call_gas_limit();
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ where
let opts = opts.unwrap_or_default();
let block = block.ok_or(EthApiError::HeaderNotFound(target_block))?;
let GethDebugTracingCallOptions { tracing_options, mut state_overrides, .. } = opts;
let gas_limit = self.inner.eth_api.call_gas_limit();

// we're essentially replaying the transactions in the block here, hence we need the state
// that points to the beginning of the block, which is the state at the parent block
Expand Down Expand Up @@ -570,7 +569,6 @@ where
cfg.clone(),
block_env.clone(),
tx,
gas_limit,
&mut db,
overrides,
)?;
Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ where
let at = block_id.unwrap_or(BlockId::pending());
let (cfg, block_env, at) = self.inner.eth_api.evm_env_at(at).await?;

let gas_limit = self.inner.eth_api.call_gas_limit();
let this = self.clone();
// execute all transactions on top of each other and record the traces
self.eth_api()
Expand All @@ -168,7 +167,6 @@ where
cfg.clone(),
block_env.clone(),
call,
gas_limit,
&mut db,
Default::default(),
)?;
Expand Down

0 comments on commit 5fd6906

Please sign in to comment.