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_codec::Encode;
14use commonware_macros::boxed;
15
16pub mod engine;
17pub(crate) use engine::Engine;
18
19mod error;
20pub use error::{EngineError, Error, ServeError};
21
22mod gaps;
23pub(crate) mod journal;
24pub(crate) use journal::Journal;
25
26mod metrics;
27pub use metrics::Metrics;
28
29mod database;
30pub use database::Database;
31pub(crate) use database::{Config as DatabaseConfig, journal_covers_range, local_pinned_nodes};
32
33pub mod source;
34pub use source::{FeedbackTx, Request, Response, Source};
35
36mod target;
37pub use target::{CompactTarget, Target};
38
39mod requests;
40
41/// A [`Source`] of operations for the given database.
42pub trait SourceFor<DB: Database>:
43    Source<Family = DB::Family, Op = DB::Op, Digest = DB::Digest> + 'static
44{
45}
46
47impl<DB, S> SourceFor<DB> for S
48where
49    DB: Database,
50    S: Source<Family = DB::Family, Op = DB::Op, Digest = DB::Digest> + 'static,
51{
52}
53
54/// Create/open a database and sync it to a target state
55#[boxed]
56pub async fn sync<DB, S>(
57    config: Config<DB, S>,
58) -> Result<DB, Error<DB::Family, S::Error, DB::Digest>>
59where
60    DB: Database,
61    DB::Op: Encode,
62    S: SourceFor<DB>,
63{
64    Engine::new(config).await?.sync().await
65}