reth_rpc_server_types/
constants.rs

1use std::cmp::max;
2
3/// The default port for the http server
4pub const DEFAULT_HTTP_RPC_PORT: u16 = 8545;
5
6/// The default port for the ws server
7pub const DEFAULT_WS_RPC_PORT: u16 = 8546;
8
9/// The default port for the auth server.
10pub const DEFAULT_AUTH_PORT: u16 = 8551;
11
12/// The default maximum block range allowed to filter
13pub const DEFAULT_MAX_BLOCKS_PER_FILTER: u64 = 100_000;
14
15/// The default maximum of logs in a single response.
16pub const DEFAULT_MAX_LOGS_PER_RESPONSE: usize = 20_000;
17
18/// The default maximum number tracing requests we're allowing concurrently.
19/// Tracing is mostly CPU bound so we're limiting the number of concurrent requests to something
20/// lower that the number of cores, in order to minimize the impact on the rest of the system.
21pub fn default_max_tracing_requests() -> usize {
22    // We reserve 2 cores for the rest of the system
23    const RESERVED: usize = 2;
24
25    std::thread::available_parallelism()
26        .map_or(25, |cpus| max(cpus.get().saturating_sub(RESERVED), RESERVED))
27}
28
29/// The default number of getproof calls we are allowing to run concurrently.
30pub const DEFAULT_PROOF_PERMITS: usize = 25;
31
32/// The default IPC endpoint
33#[cfg(windows)]
34pub const DEFAULT_IPC_ENDPOINT: &str = r"\\.\pipe\reth.ipc";
35
36/// The default IPC endpoint
37#[cfg(not(windows))]
38pub const DEFAULT_IPC_ENDPOINT: &str = "/tmp/reth.ipc";
39
40/// The engine_api IPC endpoint
41#[cfg(windows)]
42pub const DEFAULT_ENGINE_API_IPC_ENDPOINT: &str = r"\\.\pipe\reth_engine_api.ipc";
43
44/// The `engine_api` IPC endpoint
45#[cfg(not(windows))]
46pub const DEFAULT_ENGINE_API_IPC_ENDPOINT: &str = "/tmp/reth_engine_api.ipc";
47
48/// The default limit for blocks count in `eth_simulateV1`.
49pub const DEFAULT_MAX_SIMULATE_BLOCKS: u64 = 256;
50
51/// The default eth historical proof window.
52pub const DEFAULT_ETH_PROOF_WINDOW: u64 = 0;
53
54/// Maximum eth historical proof window. Equivalent to roughly 6 months of data on a 12
55/// second block time, and a month on a 2 second block time.
56pub const MAX_ETH_PROOF_WINDOW: u64 = 28 * 24 * 60 * 60 / 2;
57
58/// GPO specific constants
59pub mod gas_oracle {
60    use alloy_primitives::U256;
61
62    /// The number of transactions sampled in a block
63    pub const SAMPLE_NUMBER: usize = 3_usize;
64
65    /// The default maximum number of blocks to use for the gas price oracle.
66    pub const MAX_HEADER_HISTORY: u64 = 1024;
67
68    /// Number of recent blocks to check for gas price
69    pub const DEFAULT_GAS_PRICE_BLOCKS: u32 = 20;
70
71    /// The percentile of gas prices to use for the estimate
72    pub const DEFAULT_GAS_PRICE_PERCENTILE: u32 = 60;
73
74    /// Maximum transaction priority fee (or gas price before London Fork) to be recommended by the
75    /// gas price oracle
76    pub const DEFAULT_MAX_GAS_PRICE: U256 = U256::from_limbs([500_000_000_000u64, 0, 0, 0]);
77
78    /// The default minimum gas price, under which the sample will be ignored
79    pub const DEFAULT_IGNORE_GAS_PRICE: U256 = U256::from_limbs([2u64, 0, 0, 0]);
80
81    /// The default gas limit for `eth_call` and adjacent calls.
82    ///
83    /// This is different from the default to regular 30M block gas limit `ETHEREUM_BLOCK_GAS_LIMIT`
84    /// to allow for more complex calls.
85    pub const RPC_DEFAULT_GAS_CAP: u64 = 50_000_000;
86
87    /// Allowed error ratio for gas estimation
88    /// Taken from Geth's implementation in order to pass the hive tests
89    /// <https://github.com/ethereum/go-ethereum/blob/a5a4fa7032bb248f5a7c40f4e8df2b131c4186a4/internal/ethapi/api.go#L56>
90    pub const ESTIMATE_GAS_ERROR_RATIO: f64 = 0.015;
91
92    /// Gas required at the beginning of a call.
93    pub const CALL_STIPEND_GAS: u64 = 2_300;
94}
95
96/// Cache specific constants
97pub mod cache {
98    // TODO: memory based limiter is currently disabled pending <https://github.com/paradigmxyz/reth/issues/3503>
99    /// Default cache size for the block cache: 500MB
100    ///
101    /// With an average block size of ~100kb this should be able to cache ~5000 blocks.
102    pub const DEFAULT_BLOCK_CACHE_SIZE_BYTES_MB: usize = 500;
103
104    /// Default cache size for the receipts cache: 500MB
105    pub const DEFAULT_RECEIPT_CACHE_SIZE_BYTES_MB: usize = 500;
106
107    /// Default cache size for the env cache: 1MB
108    pub const DEFAULT_ENV_CACHE_SIZE_BYTES_MB: usize = 1;
109
110    /// Default cache size for the block cache: 5000 blocks.
111    pub const DEFAULT_BLOCK_CACHE_MAX_LEN: u32 = 5000;
112
113    /// Default cache size for the receipts cache: 2000 receipts.
114    pub const DEFAULT_RECEIPT_CACHE_MAX_LEN: u32 = 2000;
115
116    /// Default cache size for the header cache: 1000 headers.
117    pub const DEFAULT_HEADER_CACHE_MAX_LEN: u32 = 1000;
118
119    /// Default number of concurrent database requests.
120    pub const DEFAULT_CONCURRENT_DB_REQUESTS: usize = 512;
121}