1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//! Configuration types and constants for dig-coinstore.
//!
//! [`CoinStoreConfig`] holds every tunable parameter for opening a [`crate::coin_store::CoinStore`],
//! with a [`Default`] implementation and `with_*` builder methods (API-003). Named constants
//! mirror [`docs/resources/SPEC.md`](../../docs/resources/SPEC.md) Section 2.7 so defaults stay
//! traceable to the master spec and to Chia’s `coin_store.py` where noted.
//!
//! # Naming: `config::StorageBackend` vs `storage::StorageBackend`
//!
//! The **enum** [`StorageBackend`] selects which *engine* to open (LMDB vs RocksDB). The **trait**
//! [`crate::storage::StorageBackend`](crate::storage::StorageBackend) is the key-value abstraction
//! implemented by both engines (STO-001). Same English name, different namespaces—callers choose
//! `dig_coinstore::config::StorageBackend` for configuration and `dig_coinstore::storage::StorageBackend`
//! only when implementing or taking a trait object.
//!
//! # Requirement: API-003
//! # Spec: docs/requirements/domains/crate_api/specs/API-003.md
//! # SPEC.md: Sections 1.3, 2.6, 2.7
use ;
// ─────────────────────────────────────────────────────────────────────────────
// Constants (SPEC Section 2.7; API-003 default table)
// ─────────────────────────────────────────────────────────────────────────────
/// Default number of snapshots to retain before pruning.
///
/// # Spec link
/// SPEC.md §2.7 `DEFAULT_MAX_SNAPSHOTS`
pub const DEFAULT_MAX_SNAPSHOTS: usize = 10;
/// Maximum query results per batch. Matches Chia’s default `max_items=50000`.
///
/// # Spec link
/// SPEC.md §2.7 `DEFAULT_MAX_QUERY_RESULTS`; Chia
/// [`coin_store.py`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/full_node/coin_store.py)
pub const DEFAULT_MAX_QUERY_RESULTS: usize = 50_000;
/// Default LMDB environment map size (10 GiB).
///
/// # Spec link
/// SPEC.md §2.7 `DEFAULT_LMDB_MAP_SIZE`
pub const DEFAULT_LMDB_MAP_SIZE: usize = 10 * 1024 * 1024 * 1024;
/// Default RocksDB write buffer size (64 MiB).
///
/// # Spec link
/// SPEC.md §2.6
pub const DEFAULT_ROCKSDB_WRITE_BUFFER_SIZE: usize = 64 * 1024 * 1024;
/// Default RocksDB `max_open_files`.
///
/// # Spec link
/// SPEC.md §2.6
pub const DEFAULT_ROCKSDB_MAX_OPEN_FILES: i32 = 1000;
/// Bloom filter bits per key for RocksDB block-based tables (~1% FP rate at 10 bits).
///
/// # Spec link
/// SPEC.md §2.7 `BLOOM_FILTER_BITS`
pub const BLOOM_FILTER_BITS_PER_KEY: i32 = 10;
/// Default: bloom filters enabled for RocksDB point lookups (STO-004).
pub const DEFAULT_BLOOM_FILTER_ENABLED: bool = true;
// ─────────────────────────────────────────────────────────────────────────────
// StorageBackend (configuration enum — not the KV trait)
// ─────────────────────────────────────────────────────────────────────────────
/// Which persistent storage engine [`crate::coin_store::CoinStore`] should open.
///
/// Compile-time features must align: opening [`StorageBackend::Lmdb`] requires the
/// `lmdb-storage` feature; [`StorageBackend::RocksDb`] requires `rocksdb-storage`.
/// When **both** features are enabled, [`CoinStoreConfig::default`] chooses LMDB per
/// SPEC §2.6 / API-003 implementation notes (LMDB preferred for dual builds).
///
/// # Requirement: API-003
// ─────────────────────────────────────────────────────────────────────────────
// Default backend selection (feature-gated)
// ─────────────────────────────────────────────────────────────────────────────
/// Compute the spec default for [`StorageBackend`] from Cargo features.
///
/// Precedence: if `lmdb-storage` **and** `rocksdb-storage` → [`StorageBackend::Lmdb`];
/// else if only `lmdb-storage` → [`StorageBackend::Lmdb`]; else → [`StorageBackend::RocksDb`]
/// (covers default crate features and “neither feature” placeholder).
// ─────────────────────────────────────────────────────────────────────────────
// CoinStoreConfig
// ─────────────────────────────────────────────────────────────────────────────
/// Tunable parameters for constructing a [`crate::coin_store::CoinStore`].
///
/// Use [`Default::default`] for SPEC defaults, then chain `with_*` to override only what you need.
/// Field semantics follow SPEC §2.6; backend-specific fields apply only when that engine is open
/// (e.g. `lmdb_map_size` is ignored for RocksDB-only runs).
///
/// # Requirement: API-003
/// # Spec: docs/requirements/domains/crate_api/specs/API-003.md