diff options
Diffstat (limited to 'src/access/screen.rs')
| -rw-r--r-- | src/access/screen.rs | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/src/access/screen.rs b/src/access/screen.rs index 885badc..f9c67bf 100644 --- a/src/access/screen.rs +++ b/src/access/screen.rs @@ -536,12 +536,14 @@ pub(crate) fn apply( let root = change.deps().is_empty(); // Written under a policy requiring signatures, and none vouches for it yet: it // waits. As that policy has it, not this document's, which may have none yet - // (a joiner's) or another: so every node waits for the same. + // (a joiner's) or another: so every node waits for the same. But for a change + // every node builds itself, which nobody signs. if judging && !root && signatures.is_some() && !vouched.contains(&hash) && reads.required(doc, &seen_at) + && !built_by_every_node(doc, &change) { unsigned.insert(hash); waiting.0.push(change); @@ -721,6 +723,23 @@ pub(crate) struct Outcome { pub(crate) fresh_actor: Option<crate::document::ActorId>, } +/// Whether `change` is one every node builds itself, and nobody signs: in a swarm holding a +/// store, one of its genesis change's writer, which only the changes founding the swarm +/// are, as judging has it (`access::holding`). +fn built_by_every_node(doc: &Document, change: &Change) -> bool { + #[cfg(feature = "federation")] + { + crate::document::events::swarm(doc).is_some_and(|swarm| { + *change.actor_id() == crate::document::events::genesis_writer(&swarm) + }) + } + #[cfg(not(feature = "federation"))] + { + let _ = (doc, change); + false + } +} + /// [`apply`] of the changes in `bytes`, as sync messages and downloads carry them, with /// what `screening` keeps for document `epoch_seq` (of `epoch`). Bytes that don't load /// as changes, or with a misplaced author (`changes::misplaced_author`), are refused @@ -1330,6 +1349,67 @@ mod tests { assert_eq!(doc.get_heads(), vec![genesis.hash()]); } + /// The changes founding a fork's swarm, unsigned: taken by an empty document, with + /// signatures required, where built byte for byte; another under their writer refused. + #[cfg(feature = "federation")] + #[test] + fn a_store_takes_the_changes_founding_a_fork() { + use crate::document::events; + use crate::federation::fold::Federation; + use crate::federation::harness::{self, Party, Spec}; + use crate::federation::store::{Fold, Id}; + let tv = Party::new("tv", 1); + let first = Spec::first(&[&tv], &[]); + let mut store = + crate::federation::store::memory::Store::<Federation>::new(first.root(), Vec::new()) + .unwrap(); + let root = store.id(); + let write = tv.write(&[root], "home/tv/x", harness::str("1")); + let head = Id::of(&write); + store.offer(write); + let mut fork = first.after(first.hash()); + fork.parties[0].nodes_since = 1; + let (fork_root, kept) = store.fork(&[head], &fork.json().bytes()).unwrap(); + assert_eq!(kept.len(), 1); + let id = Id::of(&fork_root); + let screening = std::sync::Mutex::new(Screening::default().holding(Some(id))); + let mut signatures = Signatures::default(); + let mut offer = |doc: &mut Document, changes: &[Change]| { + let bytes: Vec<u8> = changes + .iter() + .flat_map(|change| change.raw_bytes().to_vec()) + .collect(); + apply_bytes( + doc, + Epoch::GENESIS, + 0, + &bytes, + &screening, + Some(&mut signatures), + &mut crate::document::PatchLog::inactive(), + ) + .unwrap() + }; + let founding = events::founding(Federation::NAME, &fork_root, &kept); + assert_eq!(founding.len(), 2); + // Another change of the writer, putting what the root keeps: refused. + let mut crafted = Document::new().with_actor(events::genesis_writer(&id)); + crafted.apply_changes([founding[0].clone()]).unwrap(); + crate::document::testing::change(&mut crafted, |doc| { + store::write_path(doc, &path("_continuum/members/m"), &json!({})).unwrap(); + }); + let crafted = crafted.get_last_local_change().unwrap().clone(); + let mut doc = Document::new(); + offer(&mut doc, &[founding[0].clone(), crafted]); + assert_eq!(doc.get_heads(), vec![founding[0].hash()]); + offer(&mut doc, &founding[1..]); + assert_eq!(doc.get_heads(), vec![founding[1].hash()]); + assert_eq!( + events::bytes(&doc, &Id::of(&kept[0])), + Some(kept[0].clone()) + ); + } + /// Judged as its writer saw the registry: a grant earlier in the same batch counts. #[test] fn a_grant_in_the_same_batch_counts() { |
