tycho_core/storage/
config.rs1use std::time::Duration;
2
3use bytesize::ByteSize;
4use serde::{Deserialize, Serialize};
5use tycho_util::config::PartialConfig;
6use tycho_util::serde_helpers;
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialConfig)]
9#[serde(deny_unknown_fields, default)]
10pub struct CoreStorageConfig {
11 #[important]
15 pub cells_cache_size: ByteSize,
16
17 pub drop_interval: u32,
21
22 pub store_archives: bool,
26
27 pub archives_gc: Option<ArchivesGcConfig>,
31
32 pub states_gc: Option<StatesGcConfig>,
36
37 pub blocks_gc: Option<BlocksGcConfig>,
41
42 pub blocks_cache: BlocksCacheConfig,
44
45 pub blob_db: BlobDbConfig,
47}
48
49impl CoreStorageConfig {
50 #[cfg(any(test, feature = "test"))]
51 pub fn new_potato() -> Self {
52 Self {
53 cells_cache_size: ByteSize::kb(1024),
54 blob_db: BlobDbConfig {
55 pre_create_cas_tree: false,
56 },
57 archives_gc: None,
58 states_gc: None,
59 blocks_gc: None,
60 ..Default::default()
61 }
62 }
63
64 pub fn without_gc(mut self) -> Self {
65 self.archives_gc = None;
66 self.states_gc = None;
67 self.blocks_gc = None;
68 self
69 }
70}
71
72impl Default for CoreStorageConfig {
73 fn default() -> Self {
74 Self {
75 cells_cache_size: ByteSize::mb(256),
76 drop_interval: 3,
77 store_archives: true,
78 archives_gc: Some(ArchivesGcConfig::default()),
79 states_gc: Some(StatesGcConfig::default()),
80 blocks_gc: Some(BlocksGcConfig::default()),
81 blocks_cache: BlocksCacheConfig::default(),
82 blob_db: BlobDbConfig::default(),
83 }
84 }
85}
86
87#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
88#[serde(default, deny_unknown_fields)]
89pub struct ArchivesGcConfig {
90 #[serde(with = "serde_helpers::humantime")]
92 pub persistent_state_offset: Duration,
93}
94
95impl Default for ArchivesGcConfig {
96 fn default() -> Self {
97 Self {
98 persistent_state_offset: Duration::from_secs(300),
99 }
100 }
101}
102
103#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
104#[serde(default, deny_unknown_fields)]
105pub struct StatesGcConfig {
106 pub random_offset: bool,
110 #[serde(with = "serde_helpers::humantime")]
112 pub interval: Duration,
113}
114
115impl Default for StatesGcConfig {
116 fn default() -> Self {
117 Self {
118 random_offset: true,
119 interval: Duration::from_secs(60),
120 }
121 }
122}
123
124#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
125#[serde(default)]
126pub struct BlocksGcConfig {
127 #[serde(flatten)]
132 pub ty: BlocksGcType,
133
134 pub enable_for_sync: bool,
136
137 pub max_blocks_per_batch: Option<usize>,
139}
140
141impl Default for BlocksGcConfig {
142 fn default() -> Self {
143 Self {
144 ty: BlocksGcType::BeforeSafeDistance {
145 safe_distance: 1000,
146 min_interval: Duration::from_secs(60),
147 },
148 enable_for_sync: true,
149 max_blocks_per_batch: Some(100_000),
150 }
151 }
152}
153
154#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
155#[serde(tag = "type")]
156pub enum BlocksGcType {
157 BeforeSafeDistance {
159 safe_distance: u32,
161 #[serde(with = "serde_helpers::humantime")]
165 min_interval: Duration,
166 },
167 BeforePreviousKeyBlock,
169 BeforePreviousPersistentState,
171}
172
173#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
174#[serde(default, deny_unknown_fields)]
175pub struct BlocksCacheConfig {
176 #[serde(with = "serde_helpers::humantime")]
180 pub ttl: Duration,
181
182 pub size: ByteSize,
186}
187
188impl Default for BlocksCacheConfig {
189 fn default() -> Self {
190 Self {
191 ttl: Duration::from_secs(300),
192 size: ByteSize::mb(500),
193 }
194 }
195}
196
197#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(default, deny_unknown_fields)]
199pub struct BlobDbConfig {
200 pub pre_create_cas_tree: bool,
201}
202
203impl Default for BlobDbConfig {
204 fn default() -> Self {
205 Self {
206 pre_create_cas_tree: true,
207 }
208 }
209}