From 8017b0e69f0350c2a35629ae71d511ddf7a3aa9c Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 14:55:03 +0000 Subject: A node of a swarm holding a store, on a set of events (--store-document) With store-root or store-id, store-document names the file of the store's own document, a set of events: the node holds its store there and nothing in the Automerge document, syncs with nodes holding a set and no others, and goes on from the file when started again. Without a file yet it begins from the root (StoreStart::set); joining by the ID alone needs a file. What a checkpoint forgot is kept for store-keeps-forgotten (30 days). The file stands for store-file, and no checkpoint is pinned. The set is written to its file where it changed, every five seconds with the store's worker and as the node stops (Holding::save), what a checkpoint forgot longer ago let go of first. Simulations: a node behind catches up; a node goes on from its file. --- src/config/mod.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/config') diff --git a/src/config/mod.rs b/src/config/mod.rs index efc190d..9c82673 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -215,6 +215,22 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ "With store-root or store-id: where the node keeps what is its own of its store across restarts, written whenever it changes: the events it refused by what it took before (of two versions changing one, the second), and those its operator had it drop. It reads its store anew from its document whenever it starts: without the file, it may then take what it refused. A file that doesn't read stops the node from starting.", ), #[cfg(feature = "federation")] + option( + "store-document", + Kind::Text, + "PATH", + None, + "With store-root or store-id: hold the store in a document of its own kind, a set of events (docs/document.md), kept in this file, instead of in the Automerge document a swarm syncs otherwise. The node then syncs with nodes holding such a set, and with no others: a swarm is of one kind. The file holds the store's events, what the node refused of its own and what its operator had it drop, and its members' entries; started again, the node goes on from it. Can't be combined with store-file, which the file stands for, nor with store-checkpoint.", + ), + #[cfg(feature = "federation")] + option( + "store-keeps-forgotten", + Kind::Duration, + "DURATION", + Some("30d"), + "With store-document: for how long the node keeps what a checkpoint its store moved to forgot, for nodes still before that checkpoint, which build it from that. A node behind for longer starts from a checkpoint its operator pins.", + ), + #[cfg(feature = "federation")] option( "store-checkpoint", Kind::Text, @@ -809,6 +825,14 @@ pub(crate) struct Settings { #[cfg(feature = "federation")] pub(crate) store_checkpoint: Option, #[cfg(feature = "federation")] + pub(crate) store_document: Option, + #[cfg(feature = "federation")] + #[serde( + default = "default_store_keeps_forgotten", + with = "crate::units::duration_option" + )] + pub(crate) store_keeps_forgotten: Duration, + #[cfg(feature = "federation")] pub(crate) store_party: Option, #[cfg(feature = "federation")] #[serde(default)] @@ -1070,6 +1094,10 @@ fn default_neighbours() -> usize { fn default_electorate_window() -> Duration { Duration::from_secs(7 * 24 * 3600) } +#[cfg(feature = "federation")] +fn default_store_keeps_forgotten() -> Duration { + Duration::from_secs(30 * 24 * 3600) +} fn default_clock_skew_warn() -> Duration { Duration::from_secs(2) } @@ -1332,6 +1360,7 @@ impl Settings { let of_a_store = [ ("store-file", self.store_file.is_some()), ("store-checkpoint", self.store_checkpoint.is_some()), + ("store-document", self.store_document.is_some()), ("store-party", self.store_party.is_some()), ("store-readers", !self.store_readers.is_empty()), ( @@ -1355,6 +1384,16 @@ impl Settings { return Ok(()); } }; + if self.store_document.is_some() { + if self.store_file.is_some() { + bail!("store-document holds what store-file would: unset store-file"); + } + if self.store_checkpoint.is_some() { + bail!( + "store-document: a set of events starts from its root or from its file, from no pinned checkpoint: unset store-checkpoint" + ); + } + } match &self.store_party { None => bail!( "{store}: set store-party, the party this node is of: in a swarm holding a store, nodes sync with the nodes its parties list, each as its party's" @@ -1482,6 +1521,8 @@ impl Settings { #[cfg(feature = "federation")] ("store-checkpoint", self.store_checkpoint.is_some()), #[cfg(feature = "federation")] + ("store-document", self.store_document.is_some()), + #[cfg(feature = "federation")] ("store-party", self.store_party.is_some()), #[cfg(feature = "federation")] ("store-readers", !self.store_readers.is_empty()), -- cgit v1.3.1