reth_engine_primitives/
config.rs1pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 2;
5
6pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 2;
8
9pub const DEFAULT_MAX_PROOF_TASK_CONCURRENCY: u64 = 256;
11
12pub const DEFAULT_RESERVED_CPU_CORES: usize = 1;
16
17const DEFAULT_BLOCK_BUFFER_LIMIT: u32 = 256;
18const DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH: u32 = 256;
19const DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE: usize = 4;
20const DEFAULT_CROSS_BLOCK_CACHE_SIZE: u64 = 4 * 1024 * 1024 * 1024;
21
22pub fn has_enough_parallelism() -> bool {
31 #[cfg(feature = "std")]
32 {
33 std::thread::available_parallelism().is_ok_and(|num| num.get() >= 5)
34 }
35 #[cfg(not(feature = "std"))]
36 false
37}
38
39#[derive(Debug)]
41pub struct TreeConfig {
42 persistence_threshold: u64,
45 memory_block_buffer_target: u64,
50 block_buffer_limit: u32,
53 max_invalid_header_cache_length: u32,
55 max_execute_block_batch_size: usize,
60 legacy_state_root: bool,
63 always_compare_trie_updates: bool,
66 disable_caching_and_prewarming: bool,
68 state_provider_metrics: bool,
70 cross_block_cache_size: u64,
72 has_enough_parallelism: bool,
74 max_proof_task_concurrency: u64,
76 reserved_cpu_cores: usize,
78 precompile_cache_enabled: bool,
80}
81
82impl Default for TreeConfig {
83 fn default() -> Self {
84 Self {
85 persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
86 memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
87 block_buffer_limit: DEFAULT_BLOCK_BUFFER_LIMIT,
88 max_invalid_header_cache_length: DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH,
89 max_execute_block_batch_size: DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE,
90 legacy_state_root: false,
91 always_compare_trie_updates: false,
92 disable_caching_and_prewarming: false,
93 state_provider_metrics: false,
94 cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE,
95 has_enough_parallelism: has_enough_parallelism(),
96 max_proof_task_concurrency: DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
97 reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
98 precompile_cache_enabled: false,
99 }
100 }
101}
102
103impl TreeConfig {
104 #[expect(clippy::too_many_arguments)]
106 pub const fn new(
107 persistence_threshold: u64,
108 memory_block_buffer_target: u64,
109 block_buffer_limit: u32,
110 max_invalid_header_cache_length: u32,
111 max_execute_block_batch_size: usize,
112 legacy_state_root: bool,
113 always_compare_trie_updates: bool,
114 disable_caching_and_prewarming: bool,
115 state_provider_metrics: bool,
116 cross_block_cache_size: u64,
117 has_enough_parallelism: bool,
118 max_proof_task_concurrency: u64,
119 reserved_cpu_cores: usize,
120 precompile_cache_enabled: bool,
121 ) -> Self {
122 Self {
123 persistence_threshold,
124 memory_block_buffer_target,
125 block_buffer_limit,
126 max_invalid_header_cache_length,
127 max_execute_block_batch_size,
128 legacy_state_root,
129 always_compare_trie_updates,
130 disable_caching_and_prewarming,
131 state_provider_metrics,
132 cross_block_cache_size,
133 has_enough_parallelism,
134 max_proof_task_concurrency,
135 reserved_cpu_cores,
136 precompile_cache_enabled,
137 }
138 }
139
140 pub const fn persistence_threshold(&self) -> u64 {
142 self.persistence_threshold
143 }
144
145 pub const fn memory_block_buffer_target(&self) -> u64 {
147 self.memory_block_buffer_target
148 }
149
150 pub const fn block_buffer_limit(&self) -> u32 {
152 self.block_buffer_limit
153 }
154
155 pub const fn max_invalid_header_cache_length(&self) -> u32 {
157 self.max_invalid_header_cache_length
158 }
159
160 pub const fn max_execute_block_batch_size(&self) -> usize {
162 self.max_execute_block_batch_size
163 }
164
165 pub const fn max_proof_task_concurrency(&self) -> u64 {
167 self.max_proof_task_concurrency
168 }
169
170 pub const fn reserved_cpu_cores(&self) -> usize {
172 self.reserved_cpu_cores
173 }
174
175 pub const fn legacy_state_root(&self) -> bool {
178 self.legacy_state_root
179 }
180
181 pub const fn state_provider_metrics(&self) -> bool {
183 self.state_provider_metrics
184 }
185
186 pub const fn disable_caching_and_prewarming(&self) -> bool {
188 self.disable_caching_and_prewarming
189 }
190
191 pub const fn always_compare_trie_updates(&self) -> bool {
194 self.always_compare_trie_updates
195 }
196
197 pub const fn cross_block_cache_size(&self) -> u64 {
199 self.cross_block_cache_size
200 }
201
202 pub const fn precompile_cache_enabled(&self) -> bool {
204 self.precompile_cache_enabled
205 }
206
207 pub const fn with_persistence_threshold(mut self, persistence_threshold: u64) -> Self {
209 self.persistence_threshold = persistence_threshold;
210 self
211 }
212
213 pub const fn with_memory_block_buffer_target(
215 mut self,
216 memory_block_buffer_target: u64,
217 ) -> Self {
218 self.memory_block_buffer_target = memory_block_buffer_target;
219 self
220 }
221
222 pub const fn with_block_buffer_limit(mut self, block_buffer_limit: u32) -> Self {
224 self.block_buffer_limit = block_buffer_limit;
225 self
226 }
227
228 pub const fn with_max_invalid_header_cache_length(
230 mut self,
231 max_invalid_header_cache_length: u32,
232 ) -> Self {
233 self.max_invalid_header_cache_length = max_invalid_header_cache_length;
234 self
235 }
236
237 pub const fn with_max_execute_block_batch_size(
239 mut self,
240 max_execute_block_batch_size: usize,
241 ) -> Self {
242 self.max_execute_block_batch_size = max_execute_block_batch_size;
243 self
244 }
245
246 pub const fn with_legacy_state_root(mut self, legacy_state_root: bool) -> Self {
248 self.legacy_state_root = legacy_state_root;
249 self
250 }
251
252 pub const fn without_caching_and_prewarming(
254 mut self,
255 disable_caching_and_prewarming: bool,
256 ) -> Self {
257 self.disable_caching_and_prewarming = disable_caching_and_prewarming;
258 self
259 }
260
261 pub const fn with_always_compare_trie_updates(
264 mut self,
265 always_compare_trie_updates: bool,
266 ) -> Self {
267 self.always_compare_trie_updates = always_compare_trie_updates;
268 self
269 }
270
271 pub const fn with_cross_block_cache_size(mut self, cross_block_cache_size: u64) -> Self {
273 self.cross_block_cache_size = cross_block_cache_size;
274 self
275 }
276
277 pub const fn with_has_enough_parallelism(mut self, has_enough_parallelism: bool) -> Self {
279 self.has_enough_parallelism = has_enough_parallelism;
280 self
281 }
282
283 pub const fn with_state_provider_metrics(mut self, state_provider_metrics: bool) -> Self {
285 self.state_provider_metrics = state_provider_metrics;
286 self
287 }
288
289 pub const fn with_max_proof_task_concurrency(
291 mut self,
292 max_proof_task_concurrency: u64,
293 ) -> Self {
294 self.max_proof_task_concurrency = max_proof_task_concurrency;
295 self
296 }
297
298 pub const fn with_reserved_cpu_cores(mut self, reserved_cpu_cores: usize) -> Self {
300 self.reserved_cpu_cores = reserved_cpu_cores;
301 self
302 }
303
304 pub const fn with_precompile_cache_enabled(mut self, precompile_cache_enabled: bool) -> Self {
306 self.precompile_cache_enabled = precompile_cache_enabled;
307 self
308 }
309
310 pub const fn use_state_root_task(&self) -> bool {
312 self.has_enough_parallelism && !self.legacy_state_root
313 }
314}