Skip to content

Commit 3fe6c0c

Browse files
authored
fix(call): overwrite gas when exceed the RPC_DEFAULT_GAS_CAP (#17847)
1 parent f1da87e commit 3fe6c0c

File tree

1 file changed

+8
-7
lines changed
  • crates/rpc/rpc-eth-api/src/helpers

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use reth_rpc_eth_types::{
3737
cache::db::{StateCacheDbRefMutWrapper, StateProviderTraitObjWrapper},
3838
error::{api::FromEvmHalt, ensure_success, FromEthApiError},
3939
simulate::{self, EthSimulateError},
40-
EthApiError, RevertError, RpcInvalidTransactionError, StateCacheDb,
40+
EthApiError, RevertError, StateCacheDb,
4141
};
4242
use reth_storage_api::{BlockIdReader, ProviderTx};
4343
use revm::{
@@ -48,7 +48,7 @@ use revm::{
4848
Database, DatabaseCommit,
4949
};
5050
use revm_inspectors::{access_list::AccessListInspector, transfer::TransferInspector};
51-
use tracing::trace;
51+
use tracing::{trace, warn};
5252

5353
/// Result type for `eth_simulateV1` RPC method.
5454
pub type SimulatedBlocksResult<N, E> = Result<Vec<SimulatedBlock<RpcBlock<N>>>, E>;
@@ -728,11 +728,12 @@ pub trait Call:
728728
DB: Database + DatabaseCommit + OverrideBlockHashes,
729729
EthApiError: From<<DB as Database>::Error>,
730730
{
731-
if request.as_ref().gas_limit() > Some(self.call_gas_limit()) {
732-
// configured gas exceeds limit
733-
return Err(
734-
EthApiError::InvalidTransaction(RpcInvalidTransactionError::GasTooHigh).into()
735-
)
731+
if let Some(requested_gas) = request.as_ref().gas_limit() {
732+
let global_gas_cap = self.call_gas_limit();
733+
if global_gas_cap != 0 && global_gas_cap < requested_gas {
734+
warn!(target: "rpc::eth::call", ?request, ?global_gas_cap, "Capping gas limit to global gas cap");
735+
request.as_mut().set_gas_limit(global_gas_cap);
736+
}
736737
}
737738

738739
// apply configured gas cap

0 commit comments

Comments
 (0)