feat: wrap gas limit into a new type (#3841)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Altuğ Bakan
2023-07-19 21:26:16 +02:00
committed by GitHub
parent 0fcb338e25
commit 7476120d81
5 changed files with 37 additions and 15 deletions

View File

@@ -17,13 +17,13 @@ use reth_rpc::{
DEFAULT_BLOCK_CACHE_MAX_LEN, DEFAULT_ENV_CACHE_MAX_LEN, DEFAULT_RECEIPT_CACHE_MAX_LEN,
},
gas_oracle::GasPriceOracleConfig,
RPC_DEFAULT_GAS_CAP,
},
JwtError, JwtSecret,
};
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,
@@ -139,7 +139,7 @@ pub struct RpcServerArgs {
alias = "rpc.gascap",
value_name = "GAS_CAP",
value_parser = RangedU64ValueParser::<u64>::new().range(1..),
default_value_t = RPC_DEFAULT_GAS_CAP
default_value_t = RPC_DEFAULT_GAS_CAP.into()
)]
pub rpc_gas_cap: u64,
@@ -513,7 +513,7 @@ mod tests {
fn test_rpc_gas_cap() {
let args = CommandParser::<RpcServerArgs>::parse_from(["reth"]).args;
let config = args.eth_config();
assert_eq!(config.rpc_gas_cap, RPC_DEFAULT_GAS_CAP);
assert_eq!(config.rpc_gas_cap, Into::<u64>::into(RPC_DEFAULT_GAS_CAP));
let args =
CommandParser::<RpcServerArgs>::parse_from(["reth", "--rpc.gascap", "1000"]).args;

View File

@@ -7,13 +7,6 @@ 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";

View File

@@ -1,8 +1,8 @@
use crate::constants::RPC_DEFAULT_GAS_CAP;
use reth_rpc::{
eth::{
cache::{EthStateCache, EthStateCacheConfig},
gas_oracle::GasPriceOracleConfig,
RPC_DEFAULT_GAS_CAP,
},
EthApi, EthFilter, EthPubSub,
};
@@ -51,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: RPC_DEFAULT_GAS_CAP,
rpc_gas_cap: RPC_DEFAULT_GAS_CAP.into(),
}
}
}

View File

@@ -87,7 +87,7 @@ where
network: Network,
eth_cache: EthStateCache,
gas_oracle: GasPriceOracle<Provider>,
gas_cap: u64,
gas_cap: impl Into<GasCap>,
) -> Self {
Self::with_spawner(
provider,
@@ -95,7 +95,7 @@ where
network,
eth_cache,
gas_oracle,
gas_cap,
gas_cap.into().into(),
Box::<TokioTaskExecutor>::default(),
)
}
@@ -370,6 +370,35 @@ where
}
}
/// 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: GasCap = GasCap(50_000_000);
/// The wrapper type for gas limit
#[derive(Debug, Clone, Copy)]
pub struct GasCap(u64);
impl Default for GasCap {
fn default() -> Self {
RPC_DEFAULT_GAS_CAP
}
}
impl From<u64> for GasCap {
fn from(gas_cap: u64) -> Self {
Self(gas_cap)
}
}
impl From<GasCap> for u64 {
fn from(gas_cap: GasCap) -> Self {
gas_cap.0
}
}
/// Container type `EthApi`
struct EthApiInner<Provider, Pool, Network> {
/// The transaction pool.

View File

@@ -12,7 +12,7 @@ pub mod revm_utils;
mod signer;
pub(crate) mod utils;
pub use api::{EthApi, EthApiSpec, EthTransactions, TransactionSource};
pub use api::{EthApi, EthApiSpec, EthTransactions, TransactionSource, RPC_DEFAULT_GAS_CAP};
pub use filter::EthFilter;
pub use id_provider::EthSubscriptionIdProvider;
pub use pubsub::EthPubSub;