Skip to content
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
9 changes: 5 additions & 4 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
evm_env.cfg_env.disable_eip3607 = true;

if request.as_ref().gas_limit().is_none() && tx_env.gas_price() > 0 {
let cap = this.caller_gas_allowance(&mut db, &tx_env)?;
let cap = this.caller_gas_allowance(&mut db, &evm_env, &tx_env)?;
// no gas limit was provided in the request, so we need to cap the request's gas
// limit
tx_env.set_gas_limit(cap.min(evm_env.block_env.gas_limit));
Expand Down Expand Up @@ -479,9 +479,10 @@ pub trait Call:
fn caller_gas_allowance(
&self,
mut db: impl Database<Error: Into<EthApiError>>,
env: &TxEnvFor<Self::Evm>,
_evm_env: &EvmEnvFor<Self::Evm>,
tx_env: &TxEnvFor<Self::Evm>,
) -> Result<u64, Self::Error> {
alloy_evm::call::caller_gas_allowance(&mut db, env).map_err(Self::Error::from_eth_err)
alloy_evm::call::caller_gas_allowance(&mut db, tx_env).map_err(Self::Error::from_eth_err)
}

/// Executes the closure with the state that corresponds to the given [`BlockId`].
Expand Down Expand Up @@ -799,7 +800,7 @@ pub trait Call:
if tx_env.gas_price() > 0 {
// If gas price is specified, cap transaction gas limit with caller allowance
trace!(target: "rpc::eth::call", ?tx_env, "Applying gas limit cap with caller allowance");
let cap = self.caller_gas_allowance(db, &tx_env)?;
let cap = self.caller_gas_allowance(db, &evm_env, &tx_env)?;
// ensure we cap gas_limit to the block's
tx_env.set_gas_limit(cap.min(evm_env.block_env.gas_limit));
}
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc/rpc-eth-api/src/helpers/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ pub trait EstimateCall: Call {
// The caller allowance is check by doing `(account.balance - tx.value) / tx.gas_price`
if tx_env.gas_price() > 0 {
// cap the highest gas limit by max gas caller can afford with given gas price
highest_gas_limit = highest_gas_limit.min(self.caller_gas_allowance(&mut db, &tx_env)?);
highest_gas_limit =
highest_gas_limit.min(self.caller_gas_allowance(&mut db, &evm_env, &tx_env)?);
}

// If the provided gas limit is less than computed cap, use that
Expand Down