pub struct Checkpoint {
pub frontier: BTreeMap<String, FrontierEntry>,
pub scopes: Vec<String>,
pub state_hash: String,
pub checkpoint_hash: String,
pub state: SyncState,
}Expand description
A serialized fold at a frontier — see the module docs for the design.
Fields§
§frontier: BTreeMap<String, FrontierEntry>device_id → last covered op ({seq, hlc, head}). A device absent
here has NO ops below the frontier (its full chain is retained).
scopes: Vec<String>Sorted, deduped scope tags covered (crate::oplog::Scope::tag) —
whole-chain checkpointing, see module docs.
state_hash: Stringstate_hash of state — the divergence invariant (“same frontier
⇒ same snapshot hash”). Recomputed and enforced on
Checkpoint::load.
checkpoint_hash: StringWhole-record content address covering frontier + scopes + state (see
module docs for why state-only addressing forks chains). The file
name; recomputed and enforced on Checkpoint::load.
state: SyncStateThe folded state at the frontier (possibly retention-compacted by
crate::compact::plan_compaction).
Implementations§
Source§impl Checkpoint
impl Checkpoint
Sourcepub fn assemble(
frontier: BTreeMap<String, FrontierEntry>,
scopes: Vec<String>,
state: SyncState,
) -> Self
pub fn assemble( frontier: BTreeMap<String, FrontierEntry>, scopes: Vec<String>, state: SyncState, ) -> Self
Assemble a checkpoint from its parts, stamping both hashes — the one
construction path, so a Checkpoint value is coherent by build.
Sourcepub fn from_ops(ops: &[OpRecord]) -> Result<Self, ChainError>
pub fn from_ops(ops: &[OpRecord]) -> Result<Self, ChainError>
Checkpoint an op-set: verify it (the B1 verify-before-fold
contract), fold it, and record the per-device frontier + scopes.
The state is the exact fold — retention is applied separately by
crate::compact::plan_compaction, so the equivalence
fold_onto(checkpoint.state, tail) == fold(full log) holds exactly.
Sourcepub fn content_hash(&self) -> String
pub fn content_hash(&self) -> String
Recompute the whole-record content address from the checkpoint’s
fields (everything except checkpoint_hash itself, over the
canonical serialization). Covers the frontier and scopes, not just
the state — see the module docs for the chain-fork this prevents.
Sourcepub fn verify(&self) -> Result<(), CheckpointError>
pub fn verify(&self) -> Result<(), CheckpointError>
Recompute BOTH hashes and reject any mismatch — the load-verify half
of the durability discipline (also callable on an in-memory
checkpoint received from a peer). state_hash proves the state;
checkpoint_hash proves the whole record, so a tampered frontier
is caught too.
Sourcepub fn file_name(&self) -> String
pub fn file_name(&self) -> String
Content-addressed file name: <checkpoint_hash>.checkpoint.json.
Same frontier + same retention ⇒ same record ⇒ same file (the relay
dedup the proposal leans on) — and, because the address covers the
whole record, same file ⇒ same checkpoint.
Sourcepub fn save(&self, dir: &Path) -> Result<PathBuf>
pub fn save(&self, dir: &Path) -> Result<PathBuf>
Durably write the checkpoint into dir (created if needed):
temp file → fsync → atomic rename → best-effort dir fsync. Returns
the final path. Writing the same checkpoint twice is idempotent
(content-addressed name, rename-over-identical).
Sourcepub fn load(path: &Path) -> Result<Self, CheckpointError>
pub fn load(path: &Path) -> Result<Self, CheckpointError>
Load a checkpoint and verify it: both stored hashes must
recompute from the stored content (Checkpoint::verify), and the
file’s name must BE the content address — a renamed or
wrongly-addressed file is rejected (CheckpointError::AddressMismatch)
so a store can never serve checkpoint X under checkpoint Y’s name.
Never fold a snapshot that doesn’t prove itself.
Trait Implementations§
Source§impl Clone for Checkpoint
impl Clone for Checkpoint
Source§fn clone(&self) -> Checkpoint
fn clone(&self) -> Checkpoint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Checkpoint
impl Debug for Checkpoint
Source§impl<'de> Deserialize<'de> for Checkpoint
impl<'de> Deserialize<'de> for Checkpoint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for Checkpoint
impl PartialEq for Checkpoint
Source§fn eq(&self, other: &Checkpoint) -> bool
fn eq(&self, other: &Checkpoint) -> bool
self and other values to be equal, and is used by ==.