aboutsummaryrefslogtreecommitdiffstats
path: root/src/access/holding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/access/holding.rs')
-rw-r--r--src/access/holding.rs46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/access/holding.rs b/src/access/holding.rs
index 3c6fd13..4fc41f5 100644
--- a/src/access/holding.rs
+++ b/src/access/holding.rs
@@ -9,10 +9,11 @@
//!
//! Everything else is closed: whatever isn't under `_continuum`, the policy, the swarm's
//! ID, users, bans, the swarm's topology, remakes and their acks. Nothing deletes or
-//! replaces an event. A change names its node, as signed (signatures are required): the
-//! genesis change's writer (`document::events`) names none, so no change under it is
-//! taken but the genesis change, which the epoch's root is. Which events the store takes
-//! is the store's (`federation::held`); this judges none.
+//! replaces an event. A change names its node, as signed (signatures are required), but
+//! for the changes founding the swarm, which every node builds and nobody signs: the
+//! genesis change, which the epoch's root is, and those of its writer putting the events
+//! a fork's root keeps (`document::events`), taken only as built byte for byte. Which
+//! events the store takes is the store's (`federation::held`); this judges none.
//!
//! In a swarm not holding a store, no change writes a policy naming one (`turns_store`):
//! a swarm holds a store from its genesis change, or not at all.
@@ -22,7 +23,8 @@ use sha2::{Digest, Sha256};
use super::rules::{Change, Refusal};
use crate::document::at::At;
use crate::document::inspect::{Action, Op, Path};
-use crate::document::{meta, store};
+use crate::document::{events, meta, store};
+use crate::federation::store::Id;
/// The most bytes an event of the fold `fold` may have.
fn largest(fold: &str) -> usize {
@@ -33,10 +35,44 @@ fn largest(fold: &str) -> usize {
}
}
+/// The events the store's root `root` keeps, by the fold `fold`: those of a fork's.
+fn keeps(fold: &str, root: &[u8]) -> Option<Vec<Id>> {
+ use crate::federation::store::Fold;
+ match fold {
+ crate::federation::fold::Federation::NAME => {
+ crate::federation::fold::Federation::parts(root).map(|(_, keeps)| keeps)
+ }
+ _ => None,
+ }
+}
+
+/// Whether `change`, naming no node, is one of those founding the swarm, which every node
+/// builds from the store's root and the events it keeps (`events::is_founding`).
+fn founding(at: &At<'_>, change: &Change<'_>, fold: &str) -> bool {
+ let Some(root) = events::swarm(at).and_then(|swarm| events::bytes(at, &swarm)) else {
+ return false;
+ };
+ let Some(keeps) = keeps(fold, &root) else {
+ return false;
+ };
+ let written: Vec<Vec<u8>> = change
+ .ops
+ .iter()
+ .filter_map(|op| match &op.action {
+ Action::PutBytes(bytes) => Some(bytes.clone()),
+ _ => None,
+ })
+ .collect();
+ events::is_founding(at, fold, (&root, &keeps), &change.hash, &written)
+}
+
/// Judges `change`, of a swarm holding a store of the fold `fold`, at its history `at`.
pub(crate) fn judge(at: &At<'_>, change: &Change<'_>, fold: &str) -> Result<(), Refusal> {
let refuse = |why: String| Err(Refusal::Rule(why));
let Some(node) = change.committer else {
+ if founding(at, change, fold) {
+ return Ok(());
+ }
return refuse("it names no node".to_owned());
};
let events = meta::path(&[meta::EVENTS]);