fix(rpc): use max gas limit if no transaction gas is specified (#3260)

This commit is contained in:
Alexey Shekhirin
2023-06-21 20:35:59 +01:00
committed by GitHub
parent 77167134d0
commit 2596934464

View File

@@ -2,7 +2,8 @@
use crate::eth::error::{EthApiError, EthResult, RpcInvalidTransactionError};
use reth_primitives::{
AccessList, Address, TransactionSigned, TransactionSignedEcRecovered, TxHash, H256, U256,
constants::ETHEREUM_BLOCK_GAS_LIMIT, AccessList, Address, TransactionSigned,
TransactionSignedEcRecovered, TxHash, H256, U256,
};
use reth_revm::env::{fill_tx_env, fill_tx_env_with_recovered};
use reth_rpc_types::{
@@ -236,10 +237,21 @@ where
apply_block_overrides(*block_overrides, &mut env.block);
}
if request_gas.is_none() && env.tx.gas_price > U256::ZERO {
trace!(target: "rpc::eth::call", ?env, "Applying gas limit cap");
// 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(db, &mut env.tx)?;
if request_gas.is_none() {
// No gas limit was provided in the request, so we need to cap the transaction gas limit
if env.tx.gas_price > U256::ZERO {
// If gas price is specified, cap transaction gas limit with caller allowance
trace!(target: "rpc::eth::call", ?env, "Applying gas limit cap with caller allowance");
cap_tx_gas_limit_with_caller_allowance(db, &mut env.tx)?;
} else {
// If no gas price is specified, use maximum allowed gas limit. The reason for this is
// that both Erigon and Geth use pre-configured gas cap even if it's possible
// to derive the gas limit from the block:
// 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 = ETHEREUM_BLOCK_GAS_LIMIT;
}
}
Ok(env)