Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Commit 50e8409

Browse files
authored
feat: expose EvmEnv to caller_gas_allowance (paradigmxyz#18302)
1 parent 0bd1bb2 commit 50e8409

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

crates/rpc/rpc-eth-api/src/helpers/call.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
401401
evm_env.cfg_env.disable_eip3607 = true;
402402

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

487488
/// Executes the closure with the state that corresponds to the given [`BlockId`].
@@ -799,7 +800,7 @@ pub trait Call:
799800
if tx_env.gas_price() > 0 {
800801
// If gas price is specified, cap transaction gas limit with caller allowance
801802
trace!(target: "rpc::eth::call", ?tx_env, "Applying gas limit cap with caller allowance");
802-
let cap = self.caller_gas_allowance(db, &tx_env)?;
803+
let cap = self.caller_gas_allowance(db, &evm_env, &tx_env)?;
803804
// ensure we cap gas_limit to the block's
804805
tx_env.set_gas_limit(cap.min(evm_env.block_env.gas_limit));
805806
}

crates/rpc/rpc-eth-api/src/helpers/estimate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ pub trait EstimateCall: Call {
102102
// The caller allowance is check by doing `(account.balance - tx.value) / tx.gas_price`
103103
if tx_env.gas_price() > 0 {
104104
// cap the highest gas limit by max gas caller can afford with given gas price
105-
highest_gas_limit = highest_gas_limit.min(self.caller_gas_allowance(&mut db, &tx_env)?);
105+
highest_gas_limit =
106+
highest_gas_limit.min(self.caller_gas_allowance(&mut db, &evm_env, &tx_env)?);
106107
}
107108

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

0 commit comments

Comments
 (0)