diff options
| -rw-r--r-- | src/simtest/holding.rs | 97 |
1 files changed, 57 insertions, 40 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index e1336bc..f7ac715 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -1407,14 +1407,12 @@ async fn store_attack_30() { } /// A swarm on the epoch of a compaction whose snapshot holds a checkpoint, and d, of -/// makefu, serving an epoch of that generation it made up, of a `lower` ID or a higher, -/// whose snapshot holds the root and tv's write alone, as the document stood before the -/// checkpoint; of a higher, apart from the others, whose epoch it would rejoin: the -/// simulation, its nodes (a, b, c, d), the federation's first version and ID, tv's +/// makefu, serving an epoch of that generation it made up, of a lower ID, whose snapshot +/// holds the root and tv's write alone, as the document stood before the checkpoint: +/// the simulation, its nodes (a, b, c, d), the federation's first version and ID, tv's /// write, and the two epochs. async fn made_up_epoch( seed: u64, - lower: bool, ) -> ( Sim, Vec<AppState>, @@ -1498,16 +1496,10 @@ async fn made_up_epoch( ) .expect("a snapshot") }) - .find(|snapshot| (snapshot.epoch.id < honest.id) == lower) - .expect("an epoch"); + .find(|snapshot| snapshot.epoch.id < honest.id) + .expect("a lower epoch"); let lower = made_up.epoch; assert!(events::checkpoint(&made_up.doc).is_none()); - if made_up.epoch.id > honest.id { - for other in ["a", "b", "c"] { - cut(&sim, "d", other, true); - cut(&sim, other, "d", true); - } - } crate::remake::testing::serve(&nodes[3], lower, made_up.doc).await; (sim, nodes, first, id, head, honest, lower) } @@ -1520,42 +1512,67 @@ fn not_followed(node: &AppState) -> bool { .is_some_and(|error| error.contains("not followed")) } -/// A node with an empty document handed a made-up epoch: e, reaching only d, takes the -/// one d made up, whose checkpoint is the root its operator named, and reads what it -/// holds, judging every event: what d puts again there too, the epoch withholding at -/// worst, so that it reads as d does. f, reaching only the others, takes not their -/// epoch, whose checkpoint it neither builds nor has pinned. +/// A node with an empty document handed an epoch it can't check, as a made-up one would +/// be, whose snapshot holds a checkpoint other than the root: it takes the checkpoint +/// only where its operator named or pinned it, and judges every event after it. f, +/// pinning nothing, doesn't take the others' epoch; g, pinning its checkpoint, does, and +/// reads what they read. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn store_attack_15() { - // Of a higher ID than the others', which so leave it alone. - let (sim, nodes, _, id, head, _, made_up) = made_up_epoch(97, false).await; - let away: [(&str, &[&str]); 2] = [("e", &["a", "b", "c", "f"]), ("f", &["d", "e"])]; - for (joiner, others) in away { - for other in others { - cut(&sim, joiner, other, true); - cut(&sim, other, joiner, true); - } - } - let joining = |config: &mut NodeConfig| of_the_store(config, id, None, holding("makefu")); - let e = sim.start_with("e", &["d"], Start::Join, joining); - let f = sim.start_with("f", &["a"], Start::Join, joining); - let (e, f) = (&e, &f); + let sim = Sim::with_identity(97); + let parties = three(); + let (tv, lass, makefu) = &parties; + let (first, root, id) = federation(&[(tv, &["a"]), (lass, &["b"]), (makefu, &["c", "f", "g"])]); + let nodes = started( + &sim, + &root, + vec![ + ("a", holding("tv")), + ("b", holding("lass")), + ("c", holding("makefu")), + ], + ) + .await; + let all = &nodes; + let head = tv.write(&[id], "home/tv/a", s("1")); + put(&nodes[0], &[&head]).await; + let (next, [proposal, tv_yes, lass_yes]) = checkpoint_at(&parties, &first, &[Id::of(&head)]); + put(&nodes[0], &[&proposal, &tv_yes]).await; + put(&nodes[1], &[&lass_yes]).await; + let passed = next.hash(); + sim.wait_until( + "every node moved to the checkpoint", + LONG, + move || async move { all.iter().all(|node| current(node) == Some(passed)) }, + ) + .await; + compact(&nodes[0]).await; + on_generation(&sim, &nodes, 1, Duration::from_secs(60)).await; + let moved = checkpoint(&nodes[0]).expect("a store"); + assert_ne!(moved, id); + + let f = sim.start_with("f", &["a"], Start::Join, move |config| { + of_the_store(config, id, None, holding("makefu")) + }); + let g = sim.start_with("g", &["a"], Start::Join, move |config| { + of_the_store(config, id, None, pinned("makefu", moved)) + }); + let (f, g) = (&f, &g); let head = Id::of(&head); sim.wait_until( - "e takes the made-up epoch, with tv's write", + "g, pinning the checkpoint, takes the epoch", Duration::from_secs(60), move || async move { - e.local_epoch() == made_up && e.is_ready().await && holds(e, &[head]) + g.local_epoch() == all[0].local_epoch() + && g.is_ready().await + && checkpoint(g) == Some(moved) + && holds(g, &[head]) }, ) .await; - let d = &nodes[3]; - sim.wait_until("e reads as d does", LONG, move || async move { - counts(e) == counts(d) - }) - .await; + assert_eq!(counts(g), counts(&nodes[0])); sim.wait_until( - "f doesn't take the others' epoch", + "f, pinning nothing, doesn't take it", Duration::from_secs(60), move || async move { not_followed(f) }, ) @@ -1570,7 +1587,7 @@ async fn store_attack_15() { /// pinned, and stays where it is, taking what is written on. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn store_attack_31() { - let (sim, nodes, _, _, head, honest, _) = made_up_epoch(98, true).await; + let (sim, nodes, _, _, head, honest, _) = made_up_epoch(98).await; let all = &nodes; sim.wait_until( "a, b and c don't follow d's epoch", |
