aboutsummaryrefslogtreecommitdiffstats
path: root/src/access
diff options
context:
space:
mode:
Diffstat (limited to 'src/access')
-rw-r--r--src/access/screen.rs78
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() {