Skip to main content

commonware_storage/qmdb/sync/
mod.rs

1//! Shared sync types and functionality for authenticated databases.
2//!
3//! # Trust Model
4//!
5//! Sources are untrusted, and their responses are verified against the requested target. The
6//! target itself is a trusted input chosen by the caller: sync does not select or authenticate it.
7//!
8//! Target updates form a forward-only sequence. Sync adopts only strictly advancing targets and
9//! discards the rest. Selecting a single target before this boundary lets sync focus on fetching
10//! and verifying its data instead of reconciling competing targets.
11
12use crate::qmdb::sync::engine::Config;
13use commonware_macros::boxed;
14
15pub mod engine;
16pub(crate) use engine::Engine;
17
18mod error;
19pub use error::{EngineError, Error, ServeError};
20
21mod gaps;
22pub(crate) mod journal;
23pub(crate) use journal::Journal;
24
25#[cfg(test)]
26pub(crate) mod harness;
27
28mod metrics;
29pub use metrics::Metrics;
30
31mod database;
32pub use database::Database;
33pub(crate) use database::{Config as DatabaseConfig, journal_covers_range, local_pinned_nodes};
34
35pub mod source;
36pub use source::{Feedback, Request, Response, ResponseOf, Source, max_response_size};
37
38mod target;
39pub use target::{CompactTarget, Target};
40
41mod requests;
42
43/// A [`Source`] of operations for the given database.
44pub trait SourceFor<DB: Database>:
45    Source<Family = DB::Family, Op = DB::Op, Digest = DB::Digest> + 'static
46{
47}
48
49impl<DB, S> SourceFor<DB> for S
50where
51    DB: Database,
52    S: Source<Family = DB::Family, Op = DB::Op, Digest = DB::Digest> + 'static,
53{
54}
55
56/// Create/open a database and sync it to a target state
57#[boxed]
58pub async fn sync<DB, S>(
59    config: Config<DB, S>,
60) -> Result<DB, Error<DB::Family, S::Error, DB::Digest>>
61where
62    DB: Database,
63    S: SourceFor<DB>,
64{
65    Engine::new(config).await?.sync().await
66}