From d5cc9482dd527ef9beb82671f6f35832b3280d57 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 03:22:31 +0000 Subject: held: a store starts from the checkpoint its document holds A remake's snapshot holds the store's checkpoint at `_continuum/checkpoint` where it isn't the root (`docs/store.md`, What the document holds), and none of what came before it. A node reading its store anew from such a document starts there, with what the checkpoint keeps; one pinning a checkpoint finds it there too, where it can't build it from the events. --- src/document/events.rs | 16 ++++++++++++++++ src/document/meta.rs | 2 ++ 2 files changed, 18 insertions(+) (limited to 'src/document') diff --git a/src/document/events.rs b/src/document/events.rs index 95e99c9..1079999 100644 --- a/src/document/events.rs +++ b/src/document/events.rs @@ -163,6 +163,22 @@ pub(crate) fn started(fold: &str, root: &[u8], kept: &[Vec]) -> anyhow::Resu Ok(doc.with_actor(ActorId::random())) } +/// The checkpoint `doc` holds at `_continuum/checkpoint`, where a remake's snapshot holds +/// one other than the root (`snapshot`). +pub(crate) fn checkpoint(doc: &impl ReadDoc) -> Option> { + let continuum = match doc.get(automerge::ROOT, meta::ROOT) { + Ok(Some((Value::Object(ObjType::Map), id))) => id, + _ => return None, + }; + match doc.get(&continuum, meta::CHECKPOINT) { + Ok(Some((Value::Scalar(value), _))) => match value.as_ref() { + ScalarValue::Bytes(bytes) => Some(bytes.clone()), + _ => None, + }, + _ => None, + } +} + /// The ID of the store `doc` holds, its swarm's, where it holds one. pub(crate) fn swarm(doc: &impl ReadDoc) -> Option { match store::read_plain(doc, &meta::path(&[meta::SWARM])) { diff --git a/src/document/meta.rs b/src/document/meta.rs index 7a9a489..af7aac7 100644 --- a/src/document/meta.rs +++ b/src/document/meta.rs @@ -48,6 +48,8 @@ pub(crate) const SESSIONS: &str = "sessions"; pub(crate) const LOCAL: &str = "local"; #[cfg(feature = "federation")] pub(crate) const EVENTS: &str = "events"; +#[cfg(feature = "federation")] +pub(crate) const CHECKPOINT: &str = "checkpoint"; /// The store path `_continuum/`. pub(crate) fn path(parts: &[&str]) -> Vec { -- cgit v1.3.1