1use alloy_eips::merge::EPOCH_SLOTS;
4use core::{num::NonZeroUsize, time::Duration};
5
6pub const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 50;
8
9pub const DEFAULT_NUM_STATE_MASKING_BLOCKS: u64 = 30;
11
12pub const MIN_PERSISTENCE_BACKPRESSURE_THRESHOLD: u64 = 16;
15
16pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 5;
18
19pub const DEFAULT_BACKFILL_RUN_THRESHOLD: u64 = EPOCH_SLOTS;
29
30pub const MAX_BACKFILL_RUN_THRESHOLD: u64 = 1024;
32
33pub const DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE: usize = 5;
35
36pub const DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD: u8 = 128;
38
39pub const SMALL_BLOCK_GAS_THRESHOLD: u64 = 20_000_000;
41
42pub const DEFAULT_RESERVED_CPU_CORES: usize = 1;
46
47pub const DEFAULT_SPARSE_TRIE_PRUNE_DEPTH: usize = 4;
52
53pub const DEFAULT_STATE_ROOT_TASK_TIMEOUT: Duration = Duration::from_secs(1);
55
56const DEFAULT_BLOCK_BUFFER_LIMIT: u32 = EPOCH_SLOTS as u32 * 2;
57const DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH: u32 = 256;
58const DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE: usize = 4;
59const DEFAULT_CROSS_BLOCK_CACHE_SIZE: usize = default_cross_block_cache_size();
60
61const fn assert_backpressure_threshold_invariant(
62 persistence_threshold: u64,
63 persistence_backpressure_threshold: u64,
64) {
65 debug_assert!(
66 persistence_backpressure_threshold > persistence_threshold,
67 "persistence_backpressure_threshold must be greater than persistence_threshold",
68 );
69}
70
71const fn assert_state_masking_invariant(
72 persistence_threshold: u64,
73 num_state_masking_blocks: u64,
74 memory_block_buffer_target: u64,
75) {
76 let valid_window = match num_state_masking_blocks.checked_add(memory_block_buffer_target) {
77 Some(window) => window < persistence_threshold,
78 None => false,
79 };
80 debug_assert!(
81 num_state_masking_blocks == 0 || valid_window,
82 "num_state_masking_blocks + memory_block_buffer_target must be less than persistence_threshold",
83 );
84}
85
86const fn default_cross_block_cache_size() -> usize {
87 if cfg!(test) {
88 1024 * 1024 } else if cfg!(target_pointer_width = "32") {
90 usize::MAX } else {
92 4 * 1024 * 1024 * 1024 }
94}
95
96pub fn has_enough_parallelism() -> bool {
105 #[cfg(feature = "std")]
106 {
107 std::thread::available_parallelism().is_ok_and(|num| num.get() >= 5)
108 }
109 #[cfg(not(feature = "std"))]
110 false
111}
112
113#[derive(Debug, Clone)]
115pub struct TreeConfig {
116 persistence_threshold: u64,
119 num_state_masking_blocks: u64,
122 memory_block_buffer_target: u64,
127 persistence_backpressure_threshold: u64,
130 block_buffer_limit: u32,
133 backfill_run_threshold: u64,
136 max_invalid_header_cache_length: u32,
138 invalid_header_hit_eviction_threshold: u8,
143 max_execute_block_batch_size: usize,
148 disable_state_cache: bool,
150 disable_prewarming: bool,
152 txpool_prewarming: bool,
154 state_provider_metrics: bool,
156 cross_block_cache_size: usize,
158 has_enough_parallelism: bool,
168 multiproof_chunk_size: usize,
170 reserved_cpu_cores: usize,
172 precompile_cache_disabled: bool,
174 state_root_fallback: bool,
176 always_process_payload_attributes_on_canonical_head: bool,
190 allow_unwind_canonical_header: bool,
192 disable_cache_metrics: bool,
194 sparse_trie_prune_depth: usize,
196 slow_block_threshold: Option<Duration>,
200 disable_sparse_trie_cache_pruning: bool,
202 state_root_task_timeout: Option<Duration>,
207 share_execution_cache_with_payload_builder: bool,
209 share_sparse_trie_with_payload_builder: bool,
211 suppress_persistence_during_build: bool,
216 disable_bal_parallel_execution: bool,
219 disable_bal_parallel_state_root: bool,
222 disable_bal_batch_io: bool,
226 bal_prewarm_threads: Option<NonZeroUsize>,
228 prewarm_reuse: bool,
230 skip_state_root: bool,
235 #[cfg(feature = "trie-debug")]
239 proof_jitter: Option<Duration>,
240}
241
242impl Default for TreeConfig {
243 fn default() -> Self {
244 assert_backpressure_threshold_invariant(
245 DEFAULT_PERSISTENCE_THRESHOLD,
246 DEFAULT_PERSISTENCE_THRESHOLD * 2,
247 );
248 assert_state_masking_invariant(
249 DEFAULT_PERSISTENCE_THRESHOLD,
250 DEFAULT_NUM_STATE_MASKING_BLOCKS,
251 DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
252 );
253 Self {
254 persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
255 num_state_masking_blocks: DEFAULT_NUM_STATE_MASKING_BLOCKS,
256 memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
257 persistence_backpressure_threshold: DEFAULT_PERSISTENCE_THRESHOLD * 2,
258 block_buffer_limit: DEFAULT_BLOCK_BUFFER_LIMIT,
259 backfill_run_threshold: DEFAULT_BACKFILL_RUN_THRESHOLD,
260 max_invalid_header_cache_length: DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH,
261 invalid_header_hit_eviction_threshold: DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD,
262 max_execute_block_batch_size: DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE,
263 disable_state_cache: false,
264 disable_prewarming: false,
265 txpool_prewarming: false,
266 state_provider_metrics: false,
267 cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE,
268 has_enough_parallelism: has_enough_parallelism(),
269 multiproof_chunk_size: DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE,
270 reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
271 precompile_cache_disabled: false,
272 state_root_fallback: false,
273 always_process_payload_attributes_on_canonical_head: false,
274 allow_unwind_canonical_header: false,
275 disable_cache_metrics: false,
276 sparse_trie_prune_depth: DEFAULT_SPARSE_TRIE_PRUNE_DEPTH,
277 slow_block_threshold: None,
278 disable_sparse_trie_cache_pruning: false,
279 state_root_task_timeout: Some(DEFAULT_STATE_ROOT_TASK_TIMEOUT),
280 share_execution_cache_with_payload_builder: false,
281 share_sparse_trie_with_payload_builder: false,
282 suppress_persistence_during_build: false,
283 disable_bal_parallel_execution: false,
284 disable_bal_parallel_state_root: false,
285 disable_bal_batch_io: false,
286 bal_prewarm_threads: None,
287 prewarm_reuse: false,
288 skip_state_root: false,
289 #[cfg(feature = "trie-debug")]
290 proof_jitter: None,
291 }
292 }
293}
294
295impl TreeConfig {
296 #[expect(clippy::too_many_arguments)]
304 pub const fn new(
305 persistence_threshold: u64,
306 num_state_masking_blocks: u64,
307 memory_block_buffer_target: u64,
308 persistence_backpressure_threshold: u64,
309 block_buffer_limit: u32,
310 backfill_run_threshold: u64,
311 max_invalid_header_cache_length: u32,
312 invalid_header_hit_eviction_threshold: u8,
313 max_execute_block_batch_size: usize,
314 disable_state_cache: bool,
315 disable_prewarming: bool,
316 state_provider_metrics: bool,
317 cross_block_cache_size: usize,
318 has_enough_parallelism: bool,
319 multiproof_chunk_size: usize,
320 reserved_cpu_cores: usize,
321 precompile_cache_disabled: bool,
322 state_root_fallback: bool,
323 always_process_payload_attributes_on_canonical_head: bool,
324 allow_unwind_canonical_header: bool,
325 disable_cache_metrics: bool,
326 sparse_trie_prune_depth: usize,
327 slow_block_threshold: Option<Duration>,
328 state_root_task_timeout: Option<Duration>,
329 share_execution_cache_with_payload_builder: bool,
330 share_sparse_trie_with_payload_builder: bool,
331 ) -> Self {
332 assert!(multiproof_chunk_size > 0, "multiproof chunk size must be non-zero");
333 let num_state_masking_blocks =
334 if persistence_threshold == 0 { 0 } else { num_state_masking_blocks };
335 assert_backpressure_threshold_invariant(
336 persistence_threshold,
337 persistence_backpressure_threshold,
338 );
339 assert_state_masking_invariant(
340 persistence_threshold,
341 num_state_masking_blocks,
342 memory_block_buffer_target,
343 );
344 Self {
345 persistence_threshold,
346 num_state_masking_blocks,
347 memory_block_buffer_target,
348 persistence_backpressure_threshold,
349 block_buffer_limit,
350 backfill_run_threshold: clamp_backfill_run_threshold(backfill_run_threshold),
351 max_invalid_header_cache_length,
352 invalid_header_hit_eviction_threshold,
353 max_execute_block_batch_size,
354 disable_state_cache,
355 disable_prewarming,
356 txpool_prewarming: false,
357 state_provider_metrics,
358 cross_block_cache_size,
359 has_enough_parallelism,
360 multiproof_chunk_size,
361 reserved_cpu_cores,
362 precompile_cache_disabled,
363 state_root_fallback,
364 always_process_payload_attributes_on_canonical_head,
365 allow_unwind_canonical_header,
366 disable_cache_metrics,
367 sparse_trie_prune_depth,
368 slow_block_threshold,
369 disable_sparse_trie_cache_pruning: false,
370 state_root_task_timeout,
371 share_execution_cache_with_payload_builder,
372 share_sparse_trie_with_payload_builder,
373 suppress_persistence_during_build: false,
374 disable_bal_parallel_execution: false,
375 disable_bal_parallel_state_root: false,
376 disable_bal_batch_io: false,
377 bal_prewarm_threads: None,
378 prewarm_reuse: false,
379 skip_state_root: false,
380 #[cfg(feature = "trie-debug")]
381 proof_jitter: None,
382 }
383 }
384
385 pub const fn persistence_threshold(&self) -> u64 {
387 self.persistence_threshold
388 }
389
390 pub const fn num_state_masking_blocks(&self) -> u64 {
392 self.num_state_masking_blocks
393 }
394
395 pub const fn memory_block_buffer_target(&self) -> u64 {
397 self.memory_block_buffer_target
398 }
399
400 pub const fn persistence_backpressure_threshold(&self) -> u64 {
402 self.persistence_backpressure_threshold
403 }
404
405 pub const fn block_buffer_limit(&self) -> u32 {
407 self.block_buffer_limit
408 }
409
410 pub const fn backfill_run_threshold(&self) -> u64 {
412 self.backfill_run_threshold
413 }
414
415 pub const fn max_invalid_header_cache_length(&self) -> u32 {
417 self.max_invalid_header_cache_length
418 }
419
420 pub const fn invalid_header_hit_eviction_threshold(&self) -> u8 {
425 self.invalid_header_hit_eviction_threshold
426 }
427
428 pub const fn max_execute_block_batch_size(&self) -> usize {
430 self.max_execute_block_batch_size
431 }
432
433 pub const fn multiproof_chunk_size(&self) -> usize {
435 self.multiproof_chunk_size
436 }
437
438 pub const fn effective_multiproof_chunk_size(&self) -> usize {
440 self.multiproof_chunk_size
441 }
442
443 pub const fn reserved_cpu_cores(&self) -> usize {
445 self.reserved_cpu_cores
446 }
447
448 pub const fn state_provider_metrics(&self) -> bool {
450 self.state_provider_metrics
451 }
452
453 pub const fn disable_state_cache(&self) -> bool {
455 self.disable_state_cache
456 }
457
458 pub const fn disable_prewarming(&self) -> bool {
460 self.disable_prewarming
461 }
462
463 pub const fn txpool_prewarming(&self) -> bool {
465 self.txpool_prewarming
466 }
467
468 pub const fn cross_block_cache_size(&self) -> usize {
470 self.cross_block_cache_size
471 }
472
473 pub const fn precompile_cache_disabled(&self) -> bool {
475 self.precompile_cache_disabled
476 }
477
478 pub const fn state_root_fallback(&self) -> bool {
480 self.state_root_fallback
481 }
482
483 pub const fn with_always_process_payload_attributes_on_canonical_head(
485 mut self,
486 always_process_payload_attributes_on_canonical_head: bool,
487 ) -> Self {
488 self.always_process_payload_attributes_on_canonical_head =
489 always_process_payload_attributes_on_canonical_head;
490 self
491 }
492
493 pub const fn always_process_payload_attributes_on_canonical_head(&self) -> bool {
496 self.always_process_payload_attributes_on_canonical_head
497 }
498
499 pub const fn unwind_canonical_header(&self) -> bool {
501 self.allow_unwind_canonical_header
502 }
503
504 pub const fn with_persistence_threshold(mut self, persistence_threshold: u64) -> Self {
506 self.persistence_threshold = persistence_threshold;
507 if persistence_threshold == 0 {
508 self.num_state_masking_blocks = 0;
509 }
510 assert_backpressure_threshold_invariant(
511 self.persistence_threshold,
512 self.persistence_backpressure_threshold,
513 );
514 assert_state_masking_invariant(
515 self.persistence_threshold,
516 self.num_state_masking_blocks,
517 self.memory_block_buffer_target,
518 );
519 self
520 }
521
522 pub const fn with_num_state_masking_blocks(mut self, num_state_masking_blocks: u64) -> Self {
525 self.num_state_masking_blocks =
526 if self.persistence_threshold == 0 { 0 } else { num_state_masking_blocks };
527 assert_state_masking_invariant(
528 self.persistence_threshold,
529 self.num_state_masking_blocks,
530 self.memory_block_buffer_target,
531 );
532 self
533 }
534
535 pub const fn with_memory_block_buffer_target(
537 mut self,
538 memory_block_buffer_target: u64,
539 ) -> Self {
540 self.memory_block_buffer_target = memory_block_buffer_target;
541 assert_state_masking_invariant(
542 self.persistence_threshold,
543 self.num_state_masking_blocks,
544 self.memory_block_buffer_target,
545 );
546 self
547 }
548
549 pub const fn with_persistence_backpressure_threshold(
551 mut self,
552 persistence_backpressure_threshold: u64,
553 ) -> Self {
554 self.persistence_backpressure_threshold = persistence_backpressure_threshold;
555 assert_backpressure_threshold_invariant(
556 self.persistence_threshold,
557 self.persistence_backpressure_threshold,
558 );
559 self
560 }
561
562 pub const fn with_block_buffer_limit(mut self, block_buffer_limit: u32) -> Self {
564 self.block_buffer_limit = block_buffer_limit;
565 self
566 }
567
568 pub const fn with_backfill_run_threshold(mut self, backfill_run_threshold: u64) -> Self {
574 self.backfill_run_threshold = clamp_backfill_run_threshold(backfill_run_threshold);
575 let buffer_limit = self.backfill_run_threshold as u32 * 2;
576 if buffer_limit > self.block_buffer_limit {
577 self.block_buffer_limit = buffer_limit;
578 }
579 self
580 }
581
582 pub const fn with_max_invalid_header_cache_length(
584 mut self,
585 max_invalid_header_cache_length: u32,
586 ) -> Self {
587 self.max_invalid_header_cache_length = max_invalid_header_cache_length;
588 self
589 }
590
591 pub const fn with_invalid_header_hit_eviction_threshold(
593 mut self,
594 invalid_header_hit_eviction_threshold: u8,
595 ) -> Self {
596 self.invalid_header_hit_eviction_threshold = invalid_header_hit_eviction_threshold;
597 self
598 }
599
600 pub const fn with_max_execute_block_batch_size(
602 mut self,
603 max_execute_block_batch_size: usize,
604 ) -> Self {
605 self.max_execute_block_batch_size = max_execute_block_batch_size;
606 self
607 }
608
609 pub const fn without_state_cache(mut self, disable_state_cache: bool) -> Self {
611 self.disable_state_cache = disable_state_cache;
612 self
613 }
614
615 pub const fn without_prewarming(mut self, disable_prewarming: bool) -> Self {
617 self.disable_prewarming = disable_prewarming;
618 self
619 }
620
621 pub const fn with_txpool_prewarming(mut self, enabled: bool) -> Self {
623 self.txpool_prewarming = enabled;
624 self
625 }
626
627 pub const fn with_cross_block_cache_size(mut self, cross_block_cache_size: usize) -> Self {
629 self.cross_block_cache_size = cross_block_cache_size;
630 self
631 }
632
633 pub const fn with_has_enough_parallelism(mut self, has_enough_parallelism: bool) -> Self {
635 self.has_enough_parallelism = has_enough_parallelism;
636 self
637 }
638
639 pub const fn has_enough_parallelism(&self) -> bool {
641 self.has_enough_parallelism
642 }
643
644 pub const fn use_state_root_task(&self) -> bool {
649 !self.skip_state_root && !self.state_root_fallback && self.has_enough_parallelism
650 }
651
652 pub const fn with_state_provider_metrics(mut self, state_provider_metrics: bool) -> Self {
654 self.state_provider_metrics = state_provider_metrics;
655 self
656 }
657
658 pub const fn with_multiproof_chunk_size(mut self, multiproof_chunk_size: usize) -> Self {
664 assert!(multiproof_chunk_size > 0, "multiproof chunk size must be non-zero");
665 self.multiproof_chunk_size = multiproof_chunk_size;
666 self
667 }
668
669 pub const fn with_reserved_cpu_cores(mut self, reserved_cpu_cores: usize) -> Self {
671 self.reserved_cpu_cores = reserved_cpu_cores;
672 self
673 }
674
675 pub const fn without_precompile_cache(mut self, precompile_cache_disabled: bool) -> Self {
677 self.precompile_cache_disabled = precompile_cache_disabled;
678 self
679 }
680
681 pub const fn with_state_root_fallback(mut self, state_root_fallback: bool) -> Self {
683 self.state_root_fallback = state_root_fallback;
684 self
685 }
686
687 pub const fn with_unwind_canonical_header(mut self, unwind_canonical_header: bool) -> Self {
689 self.allow_unwind_canonical_header = unwind_canonical_header;
690 self
691 }
692
693 pub const fn disable_cache_metrics(&self) -> bool {
695 self.disable_cache_metrics
696 }
697
698 pub const fn without_cache_metrics(mut self, disable_cache_metrics: bool) -> Self {
700 self.disable_cache_metrics = disable_cache_metrics;
701 self
702 }
703
704 pub const fn sparse_trie_prune_depth(&self) -> usize {
706 self.sparse_trie_prune_depth
707 }
708
709 pub const fn with_sparse_trie_prune_depth(mut self, depth: usize) -> Self {
711 self.sparse_trie_prune_depth = depth;
712 self
713 }
714
715 pub const fn slow_block_threshold(&self) -> Option<Duration> {
721 self.slow_block_threshold
722 }
723
724 pub const fn with_slow_block_threshold(
726 mut self,
727 slow_block_threshold: Option<Duration>,
728 ) -> Self {
729 self.slow_block_threshold = slow_block_threshold;
730 self
731 }
732
733 pub const fn disable_sparse_trie_cache_pruning(&self) -> bool {
735 self.disable_sparse_trie_cache_pruning
736 }
737
738 pub const fn with_disable_sparse_trie_cache_pruning(mut self, value: bool) -> Self {
740 self.disable_sparse_trie_cache_pruning = value;
741 self
742 }
743
744 pub const fn state_root_task_timeout(&self) -> Option<Duration> {
746 self.state_root_task_timeout
747 }
748
749 pub const fn with_state_root_task_timeout(mut self, timeout: Option<Duration>) -> Self {
751 self.state_root_task_timeout = timeout;
752 self
753 }
754
755 pub const fn share_execution_cache_with_payload_builder(&self) -> bool {
757 self.share_execution_cache_with_payload_builder
758 }
759
760 pub const fn share_sparse_trie_with_payload_builder(&self) -> bool {
762 self.share_sparse_trie_with_payload_builder
763 }
764
765 pub const fn with_share_execution_cache_with_payload_builder(
767 mut self,
768 share_execution_cache_with_payload_builder: bool,
769 ) -> Self {
770 self.share_execution_cache_with_payload_builder =
771 share_execution_cache_with_payload_builder;
772 self
773 }
774
775 pub const fn with_share_sparse_trie_with_payload_builder(
777 mut self,
778 share_sparse_trie_with_payload_builder: bool,
779 ) -> Self {
780 self.share_sparse_trie_with_payload_builder = share_sparse_trie_with_payload_builder;
781 self
782 }
783
784 pub const fn suppress_persistence_during_build(&self) -> bool {
786 self.suppress_persistence_during_build
787 }
788
789 pub const fn with_suppress_persistence_during_build(mut self, value: bool) -> Self {
791 self.suppress_persistence_during_build = value;
792 self
793 }
794
795 pub const fn disable_bal_parallel_execution(&self) -> bool {
797 self.disable_bal_parallel_execution
798 }
799
800 pub const fn without_bal_parallel_execution(
802 mut self,
803 disable_bal_parallel_execution: bool,
804 ) -> Self {
805 self.disable_bal_parallel_execution = disable_bal_parallel_execution;
806 self
807 }
808
809 pub const fn disable_bal_parallel_state_root(&self) -> bool {
811 self.disable_bal_parallel_state_root
812 }
813
814 pub const fn without_bal_parallel_state_root(
816 mut self,
817 disable_bal_parallel_state_root: bool,
818 ) -> Self {
819 self.disable_bal_parallel_state_root = disable_bal_parallel_state_root;
820 self
821 }
822
823 pub const fn disable_bal_batch_io(&self) -> bool {
825 self.disable_bal_batch_io
826 }
827
828 pub const fn without_bal_batch_io(mut self, disable_bal_batch_io: bool) -> Self {
830 self.disable_bal_batch_io = disable_bal_batch_io;
831 self
832 }
833
834 pub const fn bal_prewarm_threads(&self) -> Option<NonZeroUsize> {
836 self.bal_prewarm_threads
837 }
838
839 pub const fn with_bal_prewarm_threads(mut self, threads: NonZeroUsize) -> Self {
841 self.bal_prewarm_threads = Some(threads);
842 self
843 }
844
845 pub const fn prewarm_reuse(&self) -> bool {
847 self.prewarm_reuse
848 }
849
850 pub const fn with_prewarm_reuse(mut self, prewarm_reuse: bool) -> Self {
852 self.prewarm_reuse = prewarm_reuse;
853 self
854 }
855
856 pub const fn skip_state_root(&self) -> bool {
858 self.skip_state_root
859 }
860
861 pub const fn with_skip_state_root(mut self, skip_state_root: bool) -> Self {
863 self.skip_state_root = skip_state_root;
864 self
865 }
866
867 #[cfg(feature = "trie-debug")]
869 pub const fn proof_jitter(&self) -> Option<Duration> {
870 self.proof_jitter
871 }
872
873 #[cfg(feature = "trie-debug")]
875 pub const fn with_proof_jitter(mut self, proof_jitter: Option<Duration>) -> Self {
876 self.proof_jitter = proof_jitter;
877 self
878 }
879}
880
881const fn clamp_backfill_run_threshold(threshold: u64) -> u64 {
886 if threshold > MAX_BACKFILL_RUN_THRESHOLD {
887 MAX_BACKFILL_RUN_THRESHOLD
888 } else {
889 threshold
890 }
891}
892
893#[cfg(test)]
894mod tests {
895 use super::*;
896
897 #[test]
898 fn backfill_threshold_grows_block_buffer() {
899 let default = TreeConfig::default();
900 for (threshold, expected, buffer_limit) in
901 [(0, 0, 64), (500, 500, 1000), (1024, 1024, 2048), (u64::MAX, 1024, 2048)]
902 {
903 let config = default.clone().with_backfill_run_threshold(threshold);
904 assert_eq!(config.backfill_run_threshold(), expected);
905 assert_eq!(config.block_buffer_limit(), buffer_limit);
906 }
907 let config = default.with_block_buffer_limit(2000).with_backfill_run_threshold(500);
908 assert_eq!(config.block_buffer_limit(), 2000);
909 }
910
911 #[test]
912 #[should_panic(
913 expected = "persistence_backpressure_threshold must be greater than persistence_threshold"
914 )]
915 fn rejects_backpressure_threshold_at_or_below_persistence_threshold() {
916 let _ = TreeConfig::default()
917 .with_num_state_masking_blocks(0)
918 .with_persistence_threshold(4)
919 .with_persistence_backpressure_threshold(4);
920 }
921
922 #[test]
923 fn zero_persistence_threshold_disables_state_masking() {
924 let config = TreeConfig::default().with_persistence_threshold(0);
925 assert_eq!(config.num_state_masking_blocks(), 0);
926 let config = config.with_num_state_masking_blocks(u64::MAX);
927 assert_eq!(config.num_state_masking_blocks(), 0);
928 let config = config.with_memory_block_buffer_target(0);
929 assert_eq!(config.num_state_masking_blocks(), 0);
930 }
931
932 #[test]
933 #[should_panic(
934 expected = "num_state_masking_blocks + memory_block_buffer_target must be less than persistence_threshold"
935 )]
936 fn rejects_state_masking_window_at_or_above_persistence_threshold() {
937 let _ = TreeConfig::default()
938 .with_num_state_masking_blocks(0)
939 .with_persistence_threshold(4)
940 .with_memory_block_buffer_target(2)
941 .with_num_state_masking_blocks(2);
942 }
943
944 #[test]
945 #[should_panic(
946 expected = "num_state_masking_blocks + memory_block_buffer_target must be less than persistence_threshold"
947 )]
948 fn rejects_overflowing_state_masking_window() {
949 let _ = TreeConfig::default().with_num_state_masking_blocks(u64::MAX);
950 }
951}