diff options
| author | tv <tv@krebsco.de> | 2026-11-30 14:33:09 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 14:33:09 +0000 |
| commit | 8e97bcfa65e92da21df912cc5e19cf18027b82b8 (patch) | |
| tree | c0d5b42766e79b2215cb65a0214fc25607d73d5f /src/simtest/holding.rs | |
| parent | 362633603e9fc1912fd35807da5653dc1273a5be (diff) | |
swarm: a node whose store a set of events carries
Such a node (Holding::carrying) holds an Automerge document with
nothing in it, which nothing passes on, and its set is its document:
* swarm::set passes the set on. Where it stands goes in the node's
STATUSes as another kind's stamp, and a peer's is given to the set;
what the set says besides goes as a SYNC's body; what the set took, of
a peer or of the node itself, goes on to the node's other neighbours.
What compares stamps for an Automerge document's sake is handed the
node's own, and finds nothing to do; the Automerge sync isn't begun.
* The node writes its own entry (AppState::mutate_set): what writes
protocol data through a view writes to the members' entries as a
tree, and what the node's own reads as after is put as its next
entry, signed and passed on. Anything else is refused, and so is a
write to an Automerge document as such.
* An event the node writes (held::write) is offered to the set and
passed on; a set lacks nothing of its store to put again.
* The node's swarm is its store's, said at its start.
A simulation: three such nodes of two parties register, and each
holds the others' entries; events put on two of them reach all three,
and they come to stand alike, the documents they hold beside empty.
Diffstat (limited to 'src/simtest/holding.rs')
| -rw-r--r-- | src/simtest/holding.rs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index 16158b1..4a8098b 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -1726,3 +1726,83 @@ async fn store_attack_31() { ) .await; } + +/// A store carried by a set of events on `root`, for a node of `party`. +fn of_a_set(party: &str, root: &[u8]) -> Holding { + use crate::federation::store::set::Set; + holding(party).carrying(Set::new( + Store::<Federation>::new(root.to_vec(), Vec::new()).expect("a root"), + Duration::from_secs(600), + )) +} + +/// How many members' entries `node`'s set holds. +fn entries(node: &AppState) -> usize { + node.holding + .with_set(|set| set.entries().count()) + .unwrap_or(0) +} + +/// Where `node`'s set stands. +fn stands(node: &AppState) -> Option<crate::federation::store::passing::Stamp> { + node.holding + .with_set(crate::federation::store::passing::stamp) +} + +/// tv lists a and b, lass lists c: each node's store is carried by a set of events, +/// its own document, and nothing is in the Automerge document it holds. Each registers, +/// and its entry reaches the others; events put on a and on c reach all three; and they +/// come to stand alike. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_swarm_of_sets_passes_entries_and_events_on() { + let sim = Sim::with_identity(91); + let (tv, lass, _) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"]), (&lass, &["c"])]); + let nodes: Vec<AppState> = [("a", "tv"), ("b", "tv"), ("c", "lass")] + .into_iter() + .map(|(name, party)| { + let seeds: Vec<&str> = if name == "a" { Vec::new() } else { vec!["a"] }; + let root = root.clone(); + sim.start_with( + name, + &seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = of_a_set(party, &root); + }, + ) + }) + .collect(); + let members: Vec<&AppState> = nodes.iter().collect(); + let members = &members; + sim.wait_ready(members, SOON).await; + for node in members.iter() { + assert_eq!(node.kind(), crate::federation::store::set::KIND); + assert!(node.holding.tells_members()); + } + sim.wait_until("each holds the three entries", SOON, move || async move { + members.iter().all(|node| entries(node) == 3) + }) + .await; + + let on_a = tv.write(&[id], "home/tv/x", s("1")); + let on_c = lass.write(&[id], "home/lass/y", s("2")); + let ids = [Id::of(&on_a), Id::of(&on_c)]; + put(members[0], &[&on_a]).await; + put(members[2], &[&on_c]).await; + sim.wait_until("a, b and c hold both events", SOON, move || async move { + members.iter().all(|node| holds(node, &ids)) + }) + .await; + sim.wait_until("they stand alike", SOON, move || async move { + let first = stands(members[0]); + first.is_some() && members.iter().all(|node| stands(node) == first) + }) + .await; + for node in members.iter() { + assert_eq!(read(node, |store| store.state().values().len()), Some(2)); + // Nothing went into the document it holds beside. + assert!(node.doc.read().await.heads().is_empty()); + } +} |
