|
3 | 3 | //! Contains implementation of [crate::qmdb::sync::Database] for all [Db](crate::qmdb::current::db::Db) |
4 | 4 | //! variants (ordered/unordered, fixed/variable). |
5 | 5 | //! |
6 | | -//! The canonical root of a `current` database combines the QMDB ops root, grafted tree root, and |
| 6 | +//! The canonical root of a `current` database combines the ops root, grafted tree root, and |
7 | 7 | //! optional partial chunk into a single hash (see the [Root structure](super) section in the |
8 | | -//! module documentation). The sync engine operates on the **QMDB ops root**, not the canonical |
9 | | -//! root: it downloads operations and verifies each batch against the QMDB ops-root spec for the |
10 | | -//! Merkle family. |
11 | | -//! [crate::qmdb::current::proof::OpsRootWitness] can be used by callers that need to authenticate |
12 | | -//! the synced ops root against a trusted canonical root; the sync engine does not perform this |
13 | | -//! check itself. |
| 8 | +//! module documentation). The sync engine operates on the **ops root**, not the canonical root: |
| 9 | +//! it downloads operations and verifies each batch against the ops root using standard merkle |
| 10 | +//! range proofs (identical to `any` sync). [crate::qmdb::current::proof::OpsRootWitness] can be |
| 11 | +//! used by callers that need to authenticate the synced ops root against a trusted canonical root; |
| 12 | +//! the sync engine does not perform this check itself. |
14 | 13 | //! |
15 | 14 | //! After all operations are synced, the bitmap and grafted tree are reconstructed |
16 | 15 | //! deterministically from the operations. The canonical root is then computed from the |
17 | | -//! QMDB ops root, the reconstructed grafted tree root, and any partial chunk. |
| 16 | +//! ops root, the reconstructed grafted tree root, and any partial chunk. |
18 | 17 | //! |
19 | 18 | //! The [Database]`::`[root()](crate::qmdb::sync::Database::root) |
20 | | -//! implementation returns the **QMDB ops root** (not the canonical root) because that is what the |
| 19 | +//! implementation returns the **ops root** (not the canonical root) because that is what the |
21 | 20 | //! sync engine verifies against. |
22 | 21 | //! |
23 | 22 | //! For pruned databases (`range.start > 0`), grafted pinned nodes for the pruned region are |
@@ -52,6 +51,7 @@ use crate::{ |
52 | 51 | }, |
53 | 52 | FixedValue, VariableValue, |
54 | 53 | }, |
| 54 | + bitmap::Shared, |
55 | 55 | current::{ |
56 | 56 | db, grafting, |
57 | 57 | ordered::{ |
@@ -137,17 +137,19 @@ where |
137 | 137 | ) |
138 | 138 | .await?; |
139 | 139 |
|
140 | | - // Pre-build the activity-status bitmap with the pruned-chunk count derived from the sync |
141 | | - // range, then hand it to `any::Db::init_from_log` which becomes the sole owner. Floor |
142 | | - // division is intentional: chunks entirely below range.start are pruned. If range.start |
143 | | - // is not chunk-aligned, the partial leading chunk is reconstructed by `init_from_log`, |
144 | | - // which pads the gap between `pruned_chunks * CHUNK_SIZE_BITS` and the journal's |
145 | | - // inactivity floor with inactive (false) bits. |
| 140 | + // Initialize bitmap with pruned chunks. |
| 141 | + // |
| 142 | + // Floor division is intentional: chunks entirely below range.start are pruned. |
| 143 | + // If range.start is not chunk-aligned, the partial leading chunk is reconstructed by |
| 144 | + // init_from_log, which pads the gap between `pruned_chunks * CHUNK_SIZE_BITS` and the |
| 145 | + // journal's inactivity floor with inactive (false) bits. |
146 | 146 | let pruned_chunks = (*range.start() / BitMap::<N>::CHUNK_SIZE_BITS) as usize; |
147 | 147 | let bitmap = BitMap::<N>::new_with_pruned_chunks(pruned_chunks) |
148 | 148 | .map_err(|_| qmdb::Error::<F>::DataCorrupted("pruned chunks overflow"))?; |
149 | | - let bitmap = Arc::new(qmdb::bitmap::Shared::<N>::new(bitmap)); |
| 149 | + let bitmap = Arc::new(Shared::<N>::new(bitmap)); |
150 | 150 |
|
| 151 | + // Build any::Db, handing it the pre-allocated bitmap. `init_from_log` populates the bitmap |
| 152 | + // during replay. |
151 | 153 | let any: AnyDb<F, E, J, I, H, U, N, S> = AnyDb::init_from_log(index, log, Some(bitmap)).await?; |
152 | 154 |
|
153 | 155 | // Fetch grafted pinned nodes from the ops tree. For each position the grafted family |
@@ -333,7 +335,7 @@ macro_rules! impl_current_sync_database { |
333 | 335 | true |
334 | 336 | } |
335 | 337 |
|
336 | | - /// Returns the QMDB ops root (not the canonical root), since the sync engine verifies |
| 338 | + /// Returns the ops root (not the canonical root), since the sync engine verifies |
337 | 339 | /// batches against the ops tree. |
338 | 340 | fn root(&self) -> Self::Digest { |
339 | 341 | self.any.root() |
@@ -373,7 +375,7 @@ impl_current_sync_database!( |
373 | 375 | // --- Resolver implementations --- |
374 | 376 | // |
375 | 377 | // The resolver for `current` databases serves ops-level proofs (not grafted proofs) from |
376 | | -// the inner `any` db. The sync engine verifies each batch against the QMDB ops root. |
| 378 | +// the inner `any` db. The sync engine verifies each batch against the ops root. |
377 | 379 |
|
378 | 380 | macro_rules! impl_current_resolver { |
379 | 381 | ($db:ident, $op:ident, $val_bound:ident, $key_bound:path $(; $($where_extra:tt)+)?) => { |
|
0 commit comments