chore: rm bad cap function (#11562)

This commit is contained in:
Matthias Seitz
2024-10-08 16:25:00 +02:00
committed by GitHub
parent c13ab7a292
commit c61ae1371b
2 changed files with 7 additions and 16 deletions

View File

@@ -28,8 +28,8 @@ use reth_rpc_eth_types::{
cache::db::{StateCacheDbRefMutWrapper, StateProviderTraitObjWrapper},
error::ensure_success,
revm_utils::{
apply_block_overrides, apply_state_overrides, caller_gas_allowance,
cap_tx_gas_limit_with_caller_allowance, get_precompiles, CallFees,
apply_block_overrides, apply_state_overrides, caller_gas_allowance, get_precompiles,
CallFees,
},
simulate::{self, EthSimulateError},
EthApiError, RevertError, RpcInvalidTransactionError, StateCacheDb,
@@ -379,8 +379,9 @@ pub trait EthCall: Call + LoadPendingBlock {
let mut db = CacheDB::new(StateProviderDatabase::new(state));
if request.gas.is_none() && env.tx.gas_price > U256::ZERO {
let cap = caller_gas_allowance(&mut db, &env.tx)?;
// no gas limit was provided in the request, so we need to cap the request's gas limit
cap_tx_gas_limit_with_caller_allowance(&mut db, &mut env.tx)?;
env.tx.gas_limit = cap.min(env.block.gas_limit).saturating_to();
}
let from = request.from.unwrap_or_default();

View File

@@ -23,25 +23,15 @@ pub fn get_precompiles(spec_id: SpecId) -> impl IntoIterator<Item = Address> {
Precompiles::new(spec).addresses().copied().map(Address::from)
}
/// Caps the configured [`TxEnv`] `gas_limit` with the allowance of the caller.
pub fn cap_tx_gas_limit_with_caller_allowance<DB>(db: &mut DB, env: &mut TxEnv) -> EthResult<()>
where
DB: Database,
EthApiError: From<<DB as Database>::Error>,
{
if let Ok(gas_limit) = caller_gas_allowance(db, env)?.try_into() {
env.gas_limit = gas_limit;
}
Ok(())
}
/// Calculates the caller gas allowance.
///
/// `allowance = (account.balance - tx.value) / tx.gas_price`
///
/// Returns an error if the caller has insufficient funds.
/// Caution: This assumes non-zero `env.gas_price`. Otherwise, zero allowance will be returned.
///
/// Note: this takes the mut [Database] trait because the loaded sender can be reused for the
/// following operation like `eth_call`.
pub fn caller_gas_allowance<DB>(db: &mut DB, env: &TxEnv) -> EthResult<U256>
where
DB: Database,