reth_engine_primitives/
config.rs
1pub 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 cross_block_cache_size: u64,
70 has_enough_parallelism: bool,
72 max_proof_task_concurrency: u64,
74 reserved_cpu_cores: usize,
76}
77
78impl Default for TreeConfig {
79 fn default() -> Self {
80 Self {
81 persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
82 memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
83 block_buffer_limit: DEFAULT_BLOCK_BUFFER_LIMIT,
84 max_invalid_header_cache_length: DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH,
85 max_execute_block_batch_size: DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE,
86 legacy_state_root: false,
87 always_compare_trie_updates: false,
88 disable_caching_and_prewarming: false,
89 cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE,
90 has_enough_parallelism: has_enough_parallelism(),
91 max_proof_task_concurrency: DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
92 reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
93 }
94 }
95}
96
97impl TreeConfig {
98 #[expect(clippy::too_many_arguments)]
100 pub const fn new(
101 persistence_threshold: u64,
102 memory_block_buffer_target: u64,
103 block_buffer_limit: u32,
104 max_invalid_header_cache_length: u32,
105 max_execute_block_batch_size: usize,
106 legacy_state_root: bool,
107 always_compare_trie_updates: bool,
108 disable_caching_and_prewarming: bool,
109 cross_block_cache_size: u64,
110 has_enough_parallelism: bool,
111 max_proof_task_concurrency: u64,
112 reserved_cpu_cores: usize,
113 ) -> Self {
114 Self {
115 persistence_threshold,
116 memory_block_buffer_target,
117 block_buffer_limit,
118 max_invalid_header_cache_length,
119 max_execute_block_batch_size,
120 legacy_state_root,
121 always_compare_trie_updates,
122 disable_caching_and_prewarming,
123 cross_block_cache_size,
124 has_enough_parallelism,
125 max_proof_task_concurrency,
126 reserved_cpu_cores,
127 }
128 }
129
130 pub const fn persistence_threshold(&self) -> u64 {
132 self.persistence_threshold
133 }
134
135 pub const fn memory_block_buffer_target(&self) -> u64 {
137 self.memory_block_buffer_target
138 }
139
140 pub const fn block_buffer_limit(&self) -> u32 {
142 self.block_buffer_limit
143 }
144
145 pub const fn max_invalid_header_cache_length(&self) -> u32 {
147 self.max_invalid_header_cache_length
148 }
149
150 pub const fn max_execute_block_batch_size(&self) -> usize {
152 self.max_execute_block_batch_size
153 }
154
155 pub const fn max_proof_task_concurrency(&self) -> u64 {
157 self.max_proof_task_concurrency
158 }
159
160 pub const fn reserved_cpu_cores(&self) -> usize {
162 self.reserved_cpu_cores
163 }
164
165 pub const fn legacy_state_root(&self) -> bool {
168 self.legacy_state_root
169 }
170
171 pub const fn disable_caching_and_prewarming(&self) -> bool {
173 self.disable_caching_and_prewarming
174 }
175
176 pub const fn always_compare_trie_updates(&self) -> bool {
179 self.always_compare_trie_updates
180 }
181
182 pub const fn cross_block_cache_size(&self) -> u64 {
184 self.cross_block_cache_size
185 }
186
187 pub const fn with_persistence_threshold(mut self, persistence_threshold: u64) -> Self {
189 self.persistence_threshold = persistence_threshold;
190 self
191 }
192
193 pub const fn with_memory_block_buffer_target(
195 mut self,
196 memory_block_buffer_target: u64,
197 ) -> Self {
198 self.memory_block_buffer_target = memory_block_buffer_target;
199 self
200 }
201
202 pub const fn with_block_buffer_limit(mut self, block_buffer_limit: u32) -> Self {
204 self.block_buffer_limit = block_buffer_limit;
205 self
206 }
207
208 pub const fn with_max_invalid_header_cache_length(
210 mut self,
211 max_invalid_header_cache_length: u32,
212 ) -> Self {
213 self.max_invalid_header_cache_length = max_invalid_header_cache_length;
214 self
215 }
216
217 pub const fn with_max_execute_block_batch_size(
219 mut self,
220 max_execute_block_batch_size: usize,
221 ) -> Self {
222 self.max_execute_block_batch_size = max_execute_block_batch_size;
223 self
224 }
225
226 pub const fn with_legacy_state_root(mut self, legacy_state_root: bool) -> Self {
228 self.legacy_state_root = legacy_state_root;
229 self
230 }
231
232 pub const fn without_caching_and_prewarming(
234 mut self,
235 disable_caching_and_prewarming: bool,
236 ) -> Self {
237 self.disable_caching_and_prewarming = disable_caching_and_prewarming;
238 self
239 }
240
241 pub const fn with_always_compare_trie_updates(
244 mut self,
245 always_compare_trie_updates: bool,
246 ) -> Self {
247 self.always_compare_trie_updates = always_compare_trie_updates;
248 self
249 }
250
251 pub const fn with_cross_block_cache_size(mut self, cross_block_cache_size: u64) -> Self {
253 self.cross_block_cache_size = cross_block_cache_size;
254 self
255 }
256
257 pub const fn with_has_enough_parallelism(mut self, has_enough_parallelism: bool) -> Self {
259 self.has_enough_parallelism = has_enough_parallelism;
260 self
261 }
262
263 pub const fn with_max_proof_task_concurrency(
265 mut self,
266 max_proof_task_concurrency: u64,
267 ) -> Self {
268 self.max_proof_task_concurrency = max_proof_task_concurrency;
269 self
270 }
271
272 pub const fn with_reserved_cpu_cores(mut self, reserved_cpu_cores: usize) -> Self {
274 self.reserved_cpu_cores = reserved_cpu_cores;
275 self
276 }
277
278 pub const fn use_state_root_task(&self) -> bool {
280 self.has_enough_parallelism && !self.legacy_state_root
281 }
282}