aboutsummaryrefslogtreecommitdiffstats
path: root/src/simtest/holding.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-30 19:36:56 +0000
committertv <tv@krebsco.de>2026-11-30 19:36:56 +0000
commit6a06bc4a955cdf2b5a183c9ff21e25c79a4e5d9f (patch)
tree8ca41fca8d70f938e8444b0cceed880975c9797a /src/simtest/holding.rs
parent3bc200a2fdae7b928c68b4a1f8bfee9a919e8ff8 (diff)
federation: a stopped node on a set passes on what it holds back
A store that stopped at an event it can't judge holds back what comes after, and its set gave none of it to others: what was put through such a node reached nobody, and a restart lost it. The set now names what its store holds back among what it gives, passes it on at once as it does what it took, and keeps it in its file; once the store takes again, it gives of it what the store took, or refused of its own.
Diffstat (limited to 'src/simtest/holding.rs')
-rw-r--r--src/simtest/holding.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 8091cfc..8f601dd 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -1807,6 +1807,78 @@ async fn a_swarm_of_sets_passes_entries_and_events_on() {
}
}
+/// On sets of events, a version of a federation this continuum doesn't know passes, and
+/// a version event writes it: every node stops there. What is put through one of them
+/// meanwhile, it holds back and passes on, as it can't tell what will be taken: the
+/// others hold it back too. Their operators have them drop that event: they take again,
+/// all alike.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn a_stopped_node_of_a_set_passes_on_what_it_holds_back() {
+ let sim = Sim::with_identity(99);
+ let (tv, lass, makefu) = three();
+ let (first, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"]), (&makefu, &["c"])]);
+ let nodes: Vec<AppState> = [("a", "tv"), ("b", "lass"), ("c", "makefu")]
+ .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 all = &members;
+ sim.wait_ready(all, SOON).await;
+ sim.wait_until("each holds the three entries", SOON, move || async move {
+ all.iter().all(|node| entries(node) == 3)
+ })
+ .await;
+
+ let on = first.hash();
+ let text = String::from_utf8(first.after(on).json().bytes())
+ .expect("UTF-8")
+ .replace(r#""federation":1"#, r#""federation":2"#);
+ let unknown = crate::federation::jcs::read(text.as_bytes()).expect("JCS");
+ let hash = Id::of(&unknown.bytes());
+ let proposal = tv.propose(&[id], &unknown);
+ let votes = [&tv, &lass].map(|party| party.vote(&[Id::of(&proposal)], on, hash, true));
+ let written = harness::version_event(&[Id::of(&votes[0]), Id::of(&votes[1])], hash);
+ let at = Id::of(&written);
+ put(all[0], &[&proposal, &votes[0], &votes[1], &written]).await;
+ sim.wait_until("every node stopped there", LONG, move || async move {
+ all.iter().all(|node| stopped(node) == Some(at))
+ })
+ .await;
+
+ let meanwhile = tv.write(&[id], "home/tv/a", s("1"));
+ put(all[0], &[&meanwhile]).await;
+ let meanwhile = Id::of(&meanwhile);
+ sim.wait_until("every node holds it back", LONG, move || async move {
+ all.iter()
+ .all(|node| holds_back(node, &[at, meanwhile], false))
+ })
+ .await;
+
+ for node in all.iter() {
+ let dropped = node.holding.drop_taken(&[at]).expect("a store");
+ assert_eq!(dropped, Ok(vec![at]));
+ }
+ sim.wait_until("every node takes again", LONG, move || async move {
+ all.iter()
+ .all(|node| stopped(node).is_none() && holds(node, &[meanwhile]))
+ })
+ .await;
+ let read: Vec<Option<Counts>> = all.iter().map(|node| counts(node)).collect();
+ assert!(read.iter().all(|counts| counts == &read[0]), "{read:?}");
+}
+
/// Starts `name`, of `party`, on a set of events `set`, kept in the file at `path` where
/// given: the first of them with no seed, the others seeded by `a`.
fn start_on_a_set(