Skip to content

Commit fc8606b

Browse files
restructure grafting
1 parent c69f9c8 commit fc8606b

6 files changed

Lines changed: 233 additions & 143 deletions

File tree

storage/src/qmdb/any/sync/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ macro_rules! impl_sync_database {
158158
type Config = $config;
159159
type Digest = H::Digest;
160160

161-
162161
async fn from_sync_result(
163162
context: Self::Context,
164163
config: Self::Config,

storage/src/qmdb/current/batch.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ mod trait_impls {
944944
db: &CurrentDb<F, E, C, I, H, update::Unordered<K, V>, N, S>,
945945
metadata: Option<V::Value>,
946946
) -> Result<Self::Merkleized, crate::qmdb::Error<F>> {
947-
Self::merkleize(self, db, metadata).await
947+
self.merkleize(db, metadata).await
948948
}
949949
}
950950

@@ -978,7 +978,7 @@ mod trait_impls {
978978
db: &CurrentDb<F, E, C, I, H, update::Ordered<K, V>, N, S>,
979979
metadata: Option<V::Value>,
980980
) -> Result<Self::Merkleized, crate::qmdb::Error<F>> {
981-
Self::merkleize(self, db, metadata).await
981+
self.merkleize(db, metadata).await
982982
}
983983
}
984984

@@ -1020,15 +1020,15 @@ mod trait_impls {
10201020
type Batch = UnmerkleizedBatch<F, H, update::Unordered<K, V>, N, S>;
10211021

10221022
fn new_batch(&self) -> Self::Batch {
1023-
Self::new_batch(self)
1023+
self.new_batch()
10241024
}
10251025

10261026
fn apply_batch(
10271027
&mut self,
10281028
batch: Self::Merkleized,
10291029
) -> impl Future<Output = Result<core::ops::Range<Location<F>>, crate::qmdb::Error<F>>>
10301030
{
1031-
Self::apply_batch(self, batch)
1031+
self.apply_batch(batch)
10321032
}
10331033
}
10341034

@@ -1053,15 +1053,15 @@ mod trait_impls {
10531053
type Batch = UnmerkleizedBatch<F, H, update::Ordered<K, V>, N, S>;
10541054

10551055
fn new_batch(&self) -> Self::Batch {
1056-
Self::new_batch(self)
1056+
self.new_batch()
10571057
}
10581058

10591059
fn apply_batch(
10601060
&mut self,
10611061
batch: Self::Merkleized,
10621062
) -> impl Future<Output = Result<core::ops::Range<Location<F>>, crate::qmdb::Error<F>>>
10631063
{
1064-
Self::apply_batch(self, batch)
1064+
self.apply_batch(batch)
10651065
}
10661066
}
10671067
}

storage/src/qmdb/current/grafting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub(super) fn transformed_inactive_peaks<F: Family, D>(
186186
)
187187
}
188188

189-
/// Compute a grafted root according to `spec`.
189+
/// Compute a grafted root using the hasher's peak-bagging policy.
190190
///
191191
/// The grafting transform is applied before final peak bagging. Any inactive boundary must be
192192
/// representable by whole transformed grafted peaks; otherwise the request is rejected.

storage/src/qmdb/current/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,9 @@
223223
//!
224224
//! This combines two (or three) components into a single hash:
225225
//!
226-
//! - **ops root**: The root of the operations tree computed using the QMDB root spec for
227-
//! the Merkle family (the inner [crate::qmdb::any] database's root). Used for state sync,
228-
//! where a client downloads operations and verifies each batch against this root using QMDB
229-
//! range proofs.
226+
//! - **Ops root**: The root of the raw operations tree (the inner [crate::qmdb::any] database's
227+
//! root). Used for state sync, where a client downloads operations and verifies each batch
228+
//! against this root using standard Merkle range proofs.
230229
//!
231230
//! - **Grafted root**: The root of the grafted tree (overlaying bitmap chunks
232231
//! with ops subtree roots). Used for proofs about operation values and their activity status.
@@ -236,8 +235,8 @@
236235
//! usually incomplete. Its digest and bit count are folded into the canonical root hash.
237236
//!
238237
//! The canonical root is returned by [Db](db::Db)`::`[root()](db::Db::root).
239-
//! The ops root is returned by the `sync::Database` trait's `root()` method, since the sync
240-
//! engine verifies batches against the ops root, not the canonical root.
238+
//! The ops root is returned by the `sync::Database` trait's `root()` method, since the sync engine
239+
//! verifies batches against the ops root, not the canonical root.
241240
//!
242241
//! For state sync, the sync engine targets the ops root and verifies each batch against it.
243242
//! After sync, the bitmap and grafted tree are reconstructed deterministically from the
@@ -259,6 +258,7 @@ use crate::{
259258
operation::{Operation, Update},
260259
Config as AnyConfig,
261260
},
261+
bitmap::Shared,
262262
operation::Committable,
263263
},
264264
translator::Translator,
@@ -353,7 +353,7 @@ where
353353
// populates it during snapshot rebuild.
354354
let bitmap = BitMap::<N>::new_with_pruned_chunks(pruned_chunks)
355355
.map_err(|_| crate::qmdb::Error::<F>::DataCorrupted("pruned chunks overflow"))?;
356-
let bitmap = Arc::new(crate::qmdb::bitmap::Shared::<N>::new(bitmap));
356+
let bitmap = Arc::new(Shared::<N>::new(bitmap));
357357

358358
let any = any::init_with_bitmap(context.with_label("any"), config.into(), Some(bitmap)).await?;
359359

@@ -3638,11 +3638,11 @@ pub mod tests {
36383638
});
36393639
}
36403640

3641-
/// Regression: a `current::Db` over `mmb::Family` commits its ops root with the QMDB root spec,
3642-
/// so [`crate::qmdb::verify_proof`] must use that spec to accept proofs returned by
3643-
/// `ops_historical_proof`.
3641+
/// Regression: a `current::Db` over `mmb::Family` bags its ops root with backward-fold, so
3642+
/// [`crate::qmdb::verify_proof`] must use a hasher with that bagging to accept proofs returned
3643+
/// by `ops_historical_proof`.
36443644
#[test_traced("INFO")]
3645-
fn test_current_mmb_ops_historical_proof_verifies_with_qmdb_spec() {
3645+
fn test_current_mmb_ops_historical_proof_verifies_with_backward_bagging() {
36463646
use crate::{merkle::hasher::Standard, qmdb::verify_proof};
36473647
use commonware_utils::NZU64;
36483648

0 commit comments

Comments
 (0)