Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
chore: use 50M default gas limit for calls in rpc (paradigmxyz#3812)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 17, 2023
1 parent eb32fd3 commit 01e1344
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 17 deletions.
5 changes: 1 addition & 4 deletions bin/reth/src/args/rpc_server_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use clap::{
};
use futures::TryFutureExt;
use reth_network_api::{NetworkInfo, Peers};
use reth_primitives::constants::ETHEREUM_BLOCK_GAS_LIMIT;
use reth_provider::{
BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, EvmEnvProvider, HeaderProvider,
StateProviderFactory,
Expand All @@ -24,6 +23,7 @@ use reth_rpc::{
use reth_rpc_builder::{
auth::{AuthServerConfig, AuthServerHandle},
constants,
constants::RPC_DEFAULT_GAS_CAP,
error::RpcError,
EthConfig, IpcServerBuilder, RethRpcModule, RpcModuleBuilder, RpcModuleConfig,
RpcModuleSelection, RpcServerConfig, RpcServerHandle, ServerBuilder, TransportRpcModuleConfig,
Expand All @@ -49,9 +49,6 @@ pub(crate) const RPC_DEFAULT_MAX_CONNECTIONS: u32 = 100;
/// Default number of incoming connections.
pub(crate) const RPC_DEFAULT_MAX_TRACING_REQUESTS: u32 = 25;

/// Default max gas limit for `eth_call` and call tracing RPC methods.
pub(crate) const RPC_DEFAULT_GAS_CAP: u64 = ETHEREUM_BLOCK_GAS_LIMIT;

/// Parameters for configuring the rpc more granularity via CLI
#[derive(Debug, Args, PartialEq, Eq, Default)]
#[command(next_help_heading = "RPC")]
Expand Down
7 changes: 7 additions & 0 deletions crates/rpc/rpc-builder/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ pub const DEFAULT_WS_RPC_PORT: u16 = 8546;
/// The default port for the auth server.
pub const DEFAULT_AUTH_PORT: u16 = 8551;

/// The default gas limit for eth_call and adjacent calls.
///
/// This is different from the default to regular 30M block gas limit
/// [ETHEREUM_BLOCK_GAS_LIMIT](reth_primitives::constants::ETHEREUM_BLOCK_GAS_LIMIT) to allow for
/// more complex calls.
pub const RPC_DEFAULT_GAS_CAP: u64 = 50_000_000;

/// The default IPC endpoint
#[cfg(windows)]
pub const DEFAULT_IPC_ENDPOINT: &str = r"\\.\pipe\reth.ipc";
Expand Down
8 changes: 5 additions & 3 deletions crates/rpc/rpc-builder/src/eth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use reth_primitives::constants::ETHEREUM_BLOCK_GAS_LIMIT;
use crate::constants::RPC_DEFAULT_GAS_CAP;
use reth_rpc::{
eth::{
cache::{EthStateCache, EthStateCacheConfig},
Expand Down Expand Up @@ -38,7 +38,9 @@ pub struct EthConfig {
pub max_tracing_requests: u32,
/// Maximum number of logs that can be returned in a single response in `eth_getLogs` calls.
pub max_logs_per_response: usize,
/// Maximum gas limit for `eth_call` and call tracing RPC methods.
/// Gas limit for `eth_call` and call tracing RPC methods.
///
/// Defaults to [RPC_DEFAULT_GAS_CAP]
pub rpc_gas_cap: u64,
}

Expand All @@ -49,7 +51,7 @@ impl Default for EthConfig {
gas_oracle: GasPriceOracleConfig::default(),
max_tracing_requests: DEFAULT_MAX_TRACING_REQUESTS,
max_logs_per_response: DEFAULT_MAX_LOGS_PER_RESPONSE,
rpc_gas_cap: ETHEREUM_BLOCK_GAS_LIMIT,
rpc_gas_cap: RPC_DEFAULT_GAS_CAP,
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,14 @@ where
let state = self.inner.eth_api.state_at(at)?;
let mut db = SubState::new(State::new(state));
let has_state_overrides = overrides.has_state();
let env = prepare_call_env(cfg, block_env, call, &mut db, overrides)?;
let env = prepare_call_env(
cfg,
block_env,
call,
self.inner.eth_api.call_gas_limit(),
&mut db,
overrides,
)?;

// If the caller provided state overrides we need to clone the DB so the js
// service has access these modifications
Expand Down
3 changes: 1 addition & 2 deletions crates/rpc/rpc/src/eth/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ where
}

/// Returns the configured gas limit cap for `eth_call` and tracing related calls
#[allow(unused)]
pub(crate) fn gas_cap(&self) -> u64 {
pub fn gas_cap(&self) -> u64 {
self.inner.gas_cap
}

Expand Down
13 changes: 11 additions & 2 deletions crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub(crate) type StateCacheDB<'r> = CacheDB<State<StateProviderBox<'r>>>;
/// Commonly used transaction related functions for the [EthApi] type in the `eth_` namespace
#[async_trait::async_trait]
pub trait EthTransactions: Send + Sync {
/// Returns default gas limit to use for `eth_call` and tracing RPC methods.
fn call_gas_limit(&self) -> u64;

/// Returns the state at the given [BlockId]
fn state_at(&self, at: BlockId) -> EthResult<StateProviderBox<'_>>;

Expand Down Expand Up @@ -226,6 +229,10 @@ where
Provider: BlockReaderIdExt + StateProviderFactory + EvmEnvProvider + 'static,
Network: NetworkInfo + Send + Sync + 'static,
{
fn call_gas_limit(&self) -> u64 {
self.inner.gas_cap
}

fn state_at(&self, at: BlockId) -> EthResult<StateProviderBox<'_>> {
self.state_at_block_id(at)
}
Expand Down Expand Up @@ -480,7 +487,8 @@ where
let state = self.state_at(at)?;
let mut db = SubState::new(State::new(state));

let env = prepare_call_env(cfg, block_env, request, &mut db, overrides)?;
let env =
prepare_call_env(cfg, block_env, request, self.call_gas_limit(), &mut db, overrides)?;
f(db, env)
}

Expand Down Expand Up @@ -520,7 +528,8 @@ where
let state = self.state_at(at)?;
let mut db = SubState::new(State::new(state));

let env = prepare_call_env(cfg, block_env, request, &mut db, overrides)?;
let env =
prepare_call_env(cfg, block_env, request, self.call_gas_limit(), &mut db, overrides)?;
inspect_and_return_db(db, env, inspector)
}

Expand Down
10 changes: 5 additions & 5 deletions crates/rpc/rpc/src/eth/revm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use crate::eth::error::{EthApiError, EthResult, RpcInvalidTransactionError};
use reth_primitives::{
constants::ETHEREUM_BLOCK_GAS_LIMIT, AccessList, Address, TransactionSigned,
TransactionSignedEcRecovered, TxHash, H256, U256,
AccessList, Address, TransactionSigned, TransactionSignedEcRecovered, TxHash, H256, U256,
};
use reth_revm::env::{fill_tx_env, fill_tx_env_with_recovered};
use reth_rpc_types::{
Expand Down Expand Up @@ -203,6 +202,7 @@ pub(crate) fn prepare_call_env<DB>(
mut cfg: CfgEnv,
block: BlockEnv,
request: CallRequest,
gas_limit: u64,
db: &mut CacheDB<DB>,
overrides: EvmOverrides,
) -> EthResult<Env>
Expand Down Expand Up @@ -247,10 +247,10 @@ where
// 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
// <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;
env.tx.gas_limit = gas_limit;
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ where
let (cfg, block_env, at) = self.inner.eth_api.evm_env_at(at).await?;

self.on_blocking_task(|this| async move {
let gas_limit = this.inner.eth_api.call_gas_limit();
// execute all transactions on top of each other and record the traces
this.inner.eth_api.with_state_at_block(at, move |state| {
let mut results = Vec::with_capacity(calls.len());
Expand All @@ -203,6 +204,7 @@ where
cfg.clone(),
block_env.clone(),
call,
gas_limit,
&mut db,
Default::default(),
)?;
Expand Down

0 comments on commit 01e1344

Please sign in to comment.