diff options
| author | tv <tv@krebsco.de> | 2026-11-16 19:44:37 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-16 21:25:59 +0100 |
| commit | 0ba4c7363cfa2a9963ecd6a06392ea5c4dac3ad1 (patch) | |
| tree | fa40cfbfda010601eff9f9db148c5aa793aca0b2 /src/access | |
| parent | 3fccc4f6859cf0b4d93e7d166142e1ab9255723f (diff) | |
node: a swarm holding a store, started from its root or joined by its ID
Behind the `federation` feature, two options:
* `--store-root PATH` starts a swarm holding a store, or goes on with one, from the
store's root, as bytes in the file, which the federation must take as a root. With no
document to start on, the node builds the genesis change from it, as every node given
the root does, and is ready at once; a document to start on must be of the root's
swarm.
* `--store-id ID` joins one through seeds by its ID, the root's SHA-256 in hex. An empty
document of the first epoch takes as its root only that store's genesis change, built
again from the root it holds (`document::events::is_genesis`), whatever peers name:
the root pin doesn't wait for seeds, nor is disputed.
Either names the swarm the node joins, which a state file must remember too, and can't
be combined with the other, nor with what makes a new swarm's first change (`--genesis`,
`--bootstrap-users`, `--bootstrap-keys`, `--bootstrap-policy`, `--remake`,
`--genesis-root`). The root is read as a file of its own kind (`store`), counted among
the node's files.
Diffstat (limited to 'src/access')
| -rw-r--r-- | src/access/screen.rs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/access/screen.rs b/src/access/screen.rs index bbcedcf..885badc 100644 --- a/src/access/screen.rs +++ b/src/access/screen.rs @@ -81,6 +81,12 @@ pub(crate) struct Screening { /// Whether the document held a policy, known or not, since this node took it up /// (`policed`). policed: bool, + /// The store this node's swarm holds, by its root's ID (`--store-root`, + /// `--store-id`): an empty document of the first epoch takes as its root only that + /// store's genesis change (`document::events::is_genesis`), whatever peers name. + /// Kept from one document to the next. + #[cfg(feature = "federation")] + pub(crate) store: Option<crate::federation::store::Id>, } /// Which change an empty document of the first epoch takes as its root: any (nothing @@ -143,6 +149,18 @@ impl Screening { } } + /// Itself, for a swarm holding the store `store`, if any. + pub(crate) fn holding( + self, + #[cfg(feature = "federation")] store: Option<crate::federation::store::Id>, + ) -> Self { + Screening { + #[cfg(feature = "federation")] + store, + ..self + } + } + /// Whether `doc` holds anything at the policy's place, a policy known or not or what /// reads as none (an envelope holding `null`), in any of the maps on the way to it, a /// read showing them or not (`store::held_anywhere`), or did since this node took it up: @@ -166,6 +184,8 @@ impl Screening { epoch_seq, root_pin: std::mem::take(&mut self.root_pin), policed: self.policed, + #[cfg(feature = "federation")] + store: self.store, ..Screening::default() }; } @@ -791,6 +811,29 @@ pub(crate) fn apply_bytes( } }); } + #[cfg(feature = "federation")] + if epoch.generation == 0 + && doc.get_heads().is_empty() + && let Some(store) = &screening.store + { + use crate::federation::store::Fold; + changes.retain(|change| { + if !change.deps().is_empty() + || crate::document::events::is_genesis( + change, + crate::federation::fold::Federation::NAME, + store, + ) + { + return true; + } + pinned_out.push(( + change.clone(), + format!("a root other than the genesis change of the store {store}"), + )); + false + }); + } let mut refused_roots = Vec::new(); for (change, why) in pinned_out { screening.refusals.insert(change.hash(), change.hash()); @@ -1252,6 +1295,41 @@ mod tests { assert_ne!(ours.get_actor(), &actor); } + /// An empty document of a swarm holding a store takes as its root only that store's + /// genesis change, under the root's writer or not. + #[cfg(feature = "federation")] + #[test] + fn a_store_takes_its_genesis_change_as_its_root() { + use crate::document::events; + use crate::federation::store::{Fold, Id}; + let root = b"a root".to_vec(); + let id = Id::of(&root); + let screening = std::sync::Mutex::new(Screening::default().holding(Some(id))); + let offer = |doc: &mut Document, change: &Change| { + apply_bytes( + doc, + Epoch::GENESIS, + 0, + change.raw_bytes(), + &screening, + None, + &mut crate::document::PatchLog::inactive(), + ) + .unwrap() + }; + let mut forged = Document::new().with_actor(events::genesis_writer(&id)); + crate::document::testing::change(&mut forged, |doc| { + store::write_path(doc, &path("_continuum/swarm"), &json!(id.to_string())).unwrap(); + }); + let forged = forged.get_last_local_change().unwrap().clone(); + let mut doc = Document::new(); + offer(&mut doc, &forged); + assert!(doc.get_heads().is_empty()); + let genesis = events::genesis(crate::federation::fold::Federation::NAME, &root); + offer(&mut doc, &genesis); + assert_eq!(doc.get_heads(), vec![genesis.hash()]); + } + /// Judged as its writer saw the registry: a grant earlier in the same batch counts. #[test] fn a_grant_in_the_same_batch_counts() { |
