exocore_store/local/config.rs
1use std::time::Duration;
2
3use exocore_protos::core::NodeStoreConfig;
4
5/// Configuration for `Store`.
6#[derive(Clone, Copy)]
7pub struct StoreConfig {
8 /// Size of the channel of queries to be executed.
9 pub query_channel_size: usize,
10
11 /// Maximum number fo queries to execute in parallel.
12 pub query_parallelism: usize,
13
14 /// Size of the result channel of each watched query.
15 pub handle_watch_query_channel_size: usize,
16
17 /// Maximum number of events from chain engine to batch together if more are
18 /// available.
19 pub chain_events_batch_size: usize,
20
21 /// Timeout for mutations that were awaiting for entities to be returned.
22 pub mutation_tracker_timeout: Duration,
23
24 /// How often the garbage collection process will run.
25 ///
26 /// Since garbage collection doesn't happen on the whole index, but only on
27 /// entities that got flagged during search, it is better to run more
28 /// often than less. `GarbageCollectorConfig::queue_size` can be tweaked
29 /// to control rate of collection.
30 pub garbage_collect_interval: Duration,
31
32 /// Specifies the interval at which new blocks in the chain get indexed.
33 /// New blocks may not necessarily get immediately indexed if they don't
34 /// fall in the interval of `chain_index_min_depth` and
35 /// `chain_index_depth_leeway`.
36 ///
37 /// Indexation can also be prevented if user queries were recently executed
38 /// (see `chain_index_deferred_query_secs`)
39 ///
40 /// If '0' is specified, deferred indexation is disabled and blocks are
41 /// indexed when the chain layer emits events.
42 pub chain_index_deferred_interval: Option<Duration>,
43
44 /// Specifies the minimum interval to wait before indexing chain blocks
45 /// after receiving a user query. It prevents potential slow downs caused
46 /// by chain indexation if a user query get executed frequently.
47 pub chain_index_deferred_query_interval: Duration,
48
49 /// Specifies the maximum interval for which indexation may be blocked by
50 /// incoming user queries.
51 pub chain_index_deferred_max_interval: Duration,
52}
53
54impl Default for StoreConfig {
55 fn default() -> Self {
56 StoreConfig {
57 query_channel_size: 1000,
58 query_parallelism: 4,
59 handle_watch_query_channel_size: 100,
60 chain_events_batch_size: 50,
61 mutation_tracker_timeout: Duration::from_secs(5),
62 garbage_collect_interval: Duration::from_secs(13),
63 chain_index_deferred_interval: Some(Duration::from_secs(5)),
64 chain_index_deferred_query_interval: Duration::from_secs(15),
65 chain_index_deferred_max_interval: Duration::from_secs(5 * 60),
66 }
67 }
68}
69
70impl From<NodeStoreConfig> for StoreConfig {
71 fn from(proto: NodeStoreConfig) -> Self {
72 let mut config = StoreConfig::default();
73
74 if let Some(v) = proto.query_parallelism {
75 config.query_parallelism = v as usize;
76 }
77
78 if let Some(index) = &proto.index {
79 if let Some(gc) = &index.garbage_collector {
80 if let Some(v) = gc.run_interval_secs {
81 config.garbage_collect_interval = Duration::from_secs(v as u64);
82 }
83 }
84
85 if let Some(secs) = index.chain_index_deferred_interval_secs {
86 config.chain_index_deferred_interval = Some(Duration::from_secs(secs));
87 }
88
89 if let Some(secs) = index.chain_index_deferred_query_secs {
90 config.chain_index_deferred_query_interval = Duration::from_secs(secs);
91 }
92
93 if let Some(secs) = index.chain_index_deferred_max_secs {
94 config.chain_index_deferred_max_interval = Duration::from_secs(secs);
95 }
96 }
97
98 config
99 }
100}