reth_rpc_server_types/constants.rs
1use reth_concurrency::sync::thread;
2use std::{cmp::max, time::Duration};
3
4/// The default port for the http server
5pub const DEFAULT_HTTP_RPC_PORT: u16 = 8545;
6
7/// The default port for the ws server
8pub const DEFAULT_WS_RPC_PORT: u16 = 8546;
9
10/// The default port for the auth server.
11pub const DEFAULT_AUTH_PORT: u16 = 8551;
12
13/// The default maximum block range allowed to filter
14pub const DEFAULT_MAX_BLOCKS_PER_FILTER: u64 = 100_000;
15
16/// The default maximum number of filters that can be installed at the same time.
17pub const DEFAULT_MAX_ACTIVE_FILTERS: usize = 10_000;
18
19/// The default maximum of logs in a single response.
20pub const DEFAULT_MAX_LOGS_PER_RESPONSE: usize = 20_000;
21
22/// The default maximum number of blocks for `trace_filter` requests.
23pub const DEFAULT_MAX_TRACE_FILTER_BLOCKS: u64 = 100;
24
25/// Setting for how many concurrent (heavier) _blocking_ IO requests are allowed.
26///
27/// What is considered a blocking IO request can depend on the RPC method. In general anything that
28/// requires IO is considered blocking and should be spawned as blocking. This setting is however,
29/// primarily intended for heavier blocking requests that require evm execution for example,
30/// `eth_call` and alike. This is intended to be used with a semaphore that must be acquired before
31/// a new task is spawned to avoid unnecessary pooling if the number of inflight requests exceeds
32/// the available threads in the pool.
33///
34/// tokio's blocking pool, has a default of 512 and could grow unbounded, since requests like
35/// `eth_call` also require a lot of cpu which will occupy the thread, we can set this to a lower
36/// value.
37pub const DEFAULT_MAX_BLOCKING_IO_REQUEST: usize = 256;
38
39/// The default maximum number tracing requests we're allowing concurrently.
40/// Tracing is mostly CPU bound so we're limiting the number of concurrent requests to something
41/// lower that the number of cores, in order to minimize the impact on the rest of the system.
42pub fn default_max_tracing_requests() -> usize {
43 // We reserve 2 cores for the rest of the system
44 const RESERVED: usize = 2;
45
46 thread::available_parallelism()
47 .map_or(25, |cpus| max(cpus.get().saturating_sub(RESERVED), RESERVED))
48}
49
50/// The default number of getproof calls we are allowing to run concurrently.
51pub const DEFAULT_PROOF_PERMITS: usize = 25;
52
53/// The default IPC endpoint
54pub const DEFAULT_IPC_ENDPOINT: &str = "/tmp/reth.ipc";
55
56/// The `engine_api` IPC endpoint
57pub const DEFAULT_ENGINE_API_IPC_ENDPOINT: &str = "/tmp/reth_engine_api.ipc";
58
59/// The default limit for blocks count in `eth_simulateV1`.
60pub const DEFAULT_MAX_SIMULATE_BLOCKS: u64 = 256;
61
62/// The default maximum number of calls in a single `eth_callMany`, `trace_callMany` or
63/// `debug_traceCallMany` request.
64pub const DEFAULT_MAX_CALL_MANY_CALLS: usize = 1024;
65
66/// The default timeout of an `eth_callMany`, `trace_callMany` or `debug_traceCallMany` request,
67/// matching geth's `eth_call` timeout. It starts with the request's first call, and no call
68/// starts after it expires.
69pub const DEFAULT_CALL_MANY_TIMEOUT: Duration = Duration::from_secs(5);
70
71/// The default maximum number of total storage slots for `eth_getStorageValues`.
72pub const DEFAULT_MAX_STORAGE_VALUES_SLOTS: usize = 1024;
73
74/// The default maximum number of storage slots (and, for multi-proofs, targets) accepted by a
75/// single `eth_getProof` or multi-proof request.
76///
77/// Bounds the work a request holds a proof permit for, since proof node selection scales with
78/// the number of requested slots.
79pub const DEFAULT_MAX_PROOF_SLOTS: usize = 1024;
80
81/// The default eth historical proof window.
82pub const DEFAULT_ETH_PROOF_WINDOW: u64 = 0;
83
84/// The default eth tx fee cap is 1 ETH
85pub const DEFAULT_TX_FEE_CAP_WEI: u128 = 1_000_000_000_000_000_000u128;
86
87/// Maximum eth historical proof window. Equivalent to roughly 6 months of data on a 12
88/// second block time, and a month on a 2 second block time.
89pub const MAX_ETH_PROOF_WINDOW: u64 = 28 * 24 * 60 * 60 / 2;
90
91/// Default timeout for send raw transaction sync in seconds.
92pub const RPC_DEFAULT_SEND_RAW_TX_SYNC_TIMEOUT_SECS: Duration = Duration::from_secs(30);
93
94/// GPO specific constants
95pub mod gas_oracle {
96 use alloy_primitives::U256;
97
98 /// The number of transactions sampled in a block
99 pub const SAMPLE_NUMBER: usize = 3_usize;
100
101 /// The default maximum number of blocks to use for the gas price oracle.
102 pub const MAX_HEADER_HISTORY: u64 = 1024;
103
104 /// The default maximum number of allowed reward percentiles
105 pub const MAX_REWARD_PERCENTILE_COUNT: u64 = 100;
106
107 /// Number of recent blocks to check for gas price
108 pub const DEFAULT_GAS_PRICE_BLOCKS: u32 = 20;
109
110 /// The percentile of gas prices to use for the estimate
111 pub const DEFAULT_GAS_PRICE_PERCENTILE: u32 = 60;
112
113 /// Maximum transaction priority fee (or gas price before London Fork) to be recommended by the
114 /// gas price oracle
115 pub const DEFAULT_MAX_GAS_PRICE: U256 = U256::from_limbs([500_000_000_000u64, 0, 0, 0]);
116
117 /// The default minimum gas price, under which the sample will be ignored
118 pub const DEFAULT_IGNORE_GAS_PRICE: U256 = U256::from_limbs([2, 0, 0, 0]);
119
120 /// The default gas limit for `eth_call` and adjacent calls.
121 ///
122 /// This is different from the default to regular 30M block gas limit
123 /// `ETHEREUM_BLOCK_GAS_LIMIT_30M` to allow for more complex calls.
124 pub const RPC_DEFAULT_GAS_CAP: u64 = 50_000_000;
125
126 /// Allowed error ratio for gas estimation
127 /// Taken from Geth's implementation in order to pass the hive tests
128 /// <https://github.com/ethereum/go-ethereum/blob/a5a4fa7032bb248f5a7c40f4e8df2b131c4186a4/internal/ethapi/api.go#L56>
129 pub const ESTIMATE_GAS_ERROR_RATIO: f64 = 0.015;
130
131 /// Gas required at the beginning of a call.
132 pub const CALL_STIPEND_GAS: u64 = 2_300;
133}
134
135/// Cache specific constants
136pub mod cache {
137 use std::time::Duration;
138
139 /// Default estimated block payload limit: 2 GiB.
140 pub const DEFAULT_BLOCK_CACHE_MAX_BYTES: usize = 2 * 1024 * 1024 * 1024;
141
142 /// Default estimated receipts payload limit: 1 GiB.
143 pub const DEFAULT_RECEIPT_CACHE_MAX_BYTES: usize = 1024 * 1024 * 1024;
144
145 /// Default estimated block access list payload limit: 500 MiB.
146 pub const DEFAULT_BAL_CACHE_MAX_BYTES: usize = 500 * 1024 * 1024;
147
148 /// Default idle timeout for cached blocks, receipts, and block access lists.
149 pub const DEFAULT_CACHE_IDLE_TIMEOUT: Duration = Duration::from_secs(60 * 60);
150
151 /// Default cache size for the block cache: 1000 blocks.
152 pub const DEFAULT_BLOCK_CACHE_MAX_LEN: u32 = 1000;
153
154 /// Default cache size for the receipts cache: 500 blocks' receipts.
155 pub const DEFAULT_RECEIPT_CACHE_MAX_LEN: u32 = 500;
156
157 /// Default cache size for the EVM BAL cache: 1000 block access lists.
158 pub const DEFAULT_BAL_CACHE_MAX_LEN: u32 = 1000;
159
160 /// Default number of concurrent database requests.
161 pub const DEFAULT_CONCURRENT_DB_REQUESTS: usize = 512;
162
163 /// Default maximum number of transaction hashes to cache for lookups.
164 pub const DEFAULT_MAX_CACHED_TX_HASHES: u32 = 100_000;
165}