reth_rpc_server_types/constants.rs
1use std::{cmp::max, time::Duration};
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 of blocks for `trace_filter` requests.
19pub const DEFAULT_MAX_TRACE_FILTER_BLOCKS: u64 = 100;
20
21/// Setting for how many concurrent (heavier) _blocking_ IO requests are allowed.
22///
23/// What is considered a blocking IO request can depend on the RPC method. In general anything that
24/// requires IO is considered blocking and should be spawned as blocking. This setting is however,
25/// primarily intended for heavier blocking requests that require evm execution for example,
26/// `eth_call` and alike. This is intended to be used with a semaphore that must be acquired before
27/// a new task is spawned to avoid unnecessary pooling if the number of inflight requests exceeds
28/// the available threads in the pool.
29///
30/// tokio's blocking pool, has a default of 512 and could grow unbounded, since requests like
31/// `eth_call` also require a lot of cpu which will occupy the thread, we can set this to a lower
32/// value.
33pub const DEFAULT_MAX_BLOCKING_IO_REQUEST: usize = 256;
34
35/// The default maximum number tracing requests we're allowing concurrently.
36/// Tracing is mostly CPU bound so we're limiting the number of concurrent requests to something
37/// lower that the number of cores, in order to minimize the impact on the rest of the system.
38pub fn default_max_tracing_requests() -> usize {
39 // We reserve 2 cores for the rest of the system
40 const RESERVED: usize = 2;
41
42 std::thread::available_parallelism()
43 .map_or(25, |cpus| max(cpus.get().saturating_sub(RESERVED), RESERVED))
44}
45
46/// The default number of getproof calls we are allowing to run concurrently.
47pub const DEFAULT_PROOF_PERMITS: usize = 25;
48
49/// The default IPC endpoint
50#[cfg(windows)]
51pub const DEFAULT_IPC_ENDPOINT: &str = r"\\.\pipe\reth.ipc";
52
53/// The default IPC endpoint
54#[cfg(not(windows))]
55pub const DEFAULT_IPC_ENDPOINT: &str = "/tmp/reth.ipc";
56
57/// The engine_api IPC endpoint
58#[cfg(windows)]
59pub const DEFAULT_ENGINE_API_IPC_ENDPOINT: &str = r"\\.\pipe\reth_engine_api.ipc";
60
61/// The `engine_api` IPC endpoint
62#[cfg(not(windows))]
63pub const DEFAULT_ENGINE_API_IPC_ENDPOINT: &str = "/tmp/reth_engine_api.ipc";
64
65/// The default limit for blocks count in `eth_simulateV1`.
66pub const DEFAULT_MAX_SIMULATE_BLOCKS: u64 = 256;
67
68/// The default eth historical proof window.
69pub const DEFAULT_ETH_PROOF_WINDOW: u64 = 0;
70
71/// The default eth tx fee cap is 1 ETH
72pub const DEFAULT_TX_FEE_CAP_WEI: u128 = 1_000_000_000_000_000_000u128;
73
74/// Maximum eth historical proof window. Equivalent to roughly 6 months of data on a 12
75/// second block time, and a month on a 2 second block time.
76pub const MAX_ETH_PROOF_WINDOW: u64 = 28 * 24 * 60 * 60 / 2;
77
78/// Default timeout for send raw transaction sync in seconds.
79pub const RPC_DEFAULT_SEND_RAW_TX_SYNC_TIMEOUT_SECS: Duration = Duration::from_secs(30);
80
81/// GPO specific constants
82pub mod gas_oracle {
83 use alloy_primitives::U256;
84
85 /// The number of transactions sampled in a block
86 pub const SAMPLE_NUMBER: usize = 3_usize;
87
88 /// The default maximum number of blocks to use for the gas price oracle.
89 pub const MAX_HEADER_HISTORY: u64 = 1024;
90
91 /// The default maximum number of allowed reward percentiles
92 pub const MAX_REWARD_PERCENTILE_COUNT: u64 = 100;
93
94 /// Number of recent blocks to check for gas price
95 pub const DEFAULT_GAS_PRICE_BLOCKS: u32 = 20;
96
97 /// The percentile of gas prices to use for the estimate
98 pub const DEFAULT_GAS_PRICE_PERCENTILE: u32 = 60;
99
100 /// Maximum transaction priority fee (or gas price before London Fork) to be recommended by the
101 /// gas price oracle
102 pub const DEFAULT_MAX_GAS_PRICE: U256 = U256::from_limbs([500_000_000_000u64, 0, 0, 0]);
103
104 /// The default minimum gas price, under which the sample will be ignored
105 pub const DEFAULT_IGNORE_GAS_PRICE: U256 = U256::from_limbs([2u64, 0, 0, 0]);
106
107 /// The default gas limit for `eth_call` and adjacent calls.
108 ///
109 /// This is different from the default to regular 30M block gas limit
110 /// `ETHEREUM_BLOCK_GAS_LIMIT_30M` to allow for more complex calls.
111 pub const RPC_DEFAULT_GAS_CAP: u64 = 50_000_000;
112
113 /// Allowed error ratio for gas estimation
114 /// Taken from Geth's implementation in order to pass the hive tests
115 /// <https://github.com/ethereum/go-ethereum/blob/a5a4fa7032bb248f5a7c40f4e8df2b131c4186a4/internal/ethapi/api.go#L56>
116 pub const ESTIMATE_GAS_ERROR_RATIO: f64 = 0.015;
117
118 /// Gas required at the beginning of a call.
119 pub const CALL_STIPEND_GAS: u64 = 2_300;
120}
121
122/// Cache specific constants
123pub mod cache {
124 /// Default cache size for the block cache: 5000 blocks.
125 pub const DEFAULT_BLOCK_CACHE_MAX_LEN: u32 = 5000;
126
127 /// Default cache size for the receipts cache: 2000 receipts.
128 pub const DEFAULT_RECEIPT_CACHE_MAX_LEN: u32 = 2000;
129
130 /// Default cache size for the header cache: 1000 headers.
131 pub const DEFAULT_HEADER_CACHE_MAX_LEN: u32 = 1000;
132
133 /// Default number of concurrent database requests.
134 pub const DEFAULT_CONCURRENT_DB_REQUESTS: usize = 512;
135}