aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/federation/held.rs2
-rw-r--r--src/simtest/holding.rs176
2 files changed, 177 insertions, 1 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs
index 4b28235..856a2f6 100644
--- a/src/federation/held.rs
+++ b/src/federation/held.rs
@@ -1822,7 +1822,7 @@ mod tests {
}
/// Rows whose tests wait: remakes (stage 5), and flooding.
- const LATER: &[u32] = &[15, 29, 31];
+ const LATER: &[u32] = &[29];
#[test]
fn every_row_has_its_test() {
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 4a60129..069cc1e 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -1405,3 +1405,179 @@ async fn store_attack_30() {
together(&sim, &nodes, &every, Duration::from_secs(90)).await;
assert_eq!(nodes[0].local_epoch(), lowest);
}
+
+/// 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, 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,
+) -> (
+ Sim,
+ Vec<AppState>,
+ Spec,
+ Id,
+ Vec<u8>,
+ crate::document::replica::Epoch,
+ crate::document::replica::Epoch,
+) {
+ let sim = Sim::with_identity(seed);
+ let parties = three();
+ let (tv, lass, makefu) = &parties;
+ let (first, root, id) = federation(&[
+ (tv, &["a"]),
+ (lass, &["b"]),
+ (makefu, &["c", "d", "e", "f"]),
+ ]);
+ let nodes = started(
+ &sim,
+ &root,
+ vec![
+ ("a", holding("tv")),
+ ("b", holding("lass")),
+ ("c", holding("makefu")),
+ ("d", holding("makefu")),
+ ],
+ )
+ .await;
+ let all = &nodes;
+ let head = tv.write(&[id], "home/tv/a", s("1"));
+ put(&nodes[0], &[&head]).await;
+ let held = [Id::of(&head)];
+ sim.wait_until("every node holds tv's write", LONG, move || async move {
+ all.iter().all(|node| holds(node, &held))
+ })
+ .await;
+ let old = nodes[3].doc.read().await.doc.clone();
+ 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 honest = nodes[0].local_epoch();
+
+ // As the remake's snapshot, by its retention, but at the old document's heads.
+ let policy = {
+ let replica = nodes[0].doc.read().await;
+ crate::document::store::read_path(
+ &replica.doc,
+ &crate::document::meta::path(&["epochs", "1"]),
+ )
+ .expect("the epoch's metadata reads")
+ .expect("the epoch's metadata")["policy"]
+ .clone()
+ };
+ let coordinator = sim_key("d").id();
+ let heads = old.get_heads();
+ let made_up = (0..)
+ .map(|n| {
+ crate::remake::snapshot::build(
+ &old,
+ &crate::remake::snapshot::SnapshotParams {
+ remake_id: &format!("made-up-{n}"),
+ coordinator: &coordinator,
+ previous: crate::document::replica::Epoch::GENESIS,
+ base_heads: &heads,
+ policy: &policy,
+ proposed_at: crate::clock::UnixMillis(0),
+ kind: "compact",
+ content: None,
+ translation: &serde_json::Value::Null,
+ held: Some(&Holding::default()),
+ },
+ )
+ .expect("a snapshot")
+ })
+ .find(|snapshot| snapshot.epoch.id < honest.id)
+ .expect("a lower epoch");
+ let lower = made_up.epoch;
+ assert!(events::checkpoint(&made_up.doc).is_none());
+ crate::remake::testing::serve(&nodes[3], lower, made_up.doc).await;
+ (sim, nodes, first, id, head, honest, lower)
+}
+
+/// Whether `node` gave up rejoining an epoch it doesn't follow.
+fn not_followed(node: &AppState) -> bool {
+ node.remake
+ .catch_up()
+ .and_then(|catch_up| catch_up.error)
+ .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: tv's write, not the checkpoint the others moved to; the
+/// epoch withholds, at worst. f, reaching only the others, takes not their epoch, whose
+/// checkpoint it neither builds nor has pinned.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn store_attack_15() {
+ let (sim, _nodes, first, id, head, _, lower) = made_up_epoch(97).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 head = Id::of(&head);
+ sim.wait_until(
+ "e takes the made-up epoch, with tv's write",
+ Duration::from_secs(60),
+ move || async move { e.local_epoch() == lower && e.is_ready().await && holds(e, &[head]) },
+ )
+ .await;
+ assert_eq!(checkpoint(e), Some(id));
+ assert_eq!(current(e), Some(first.hash()));
+ sim.wait_until(
+ "f doesn't take the others' epoch",
+ Duration::from_secs(60),
+ move || async move { not_followed(f) },
+ )
+ .await;
+ assert_eq!(f.local_epoch().generation, 0);
+ assert!(read(f, |_| ()).is_none());
+}
+
+/// A made-up epoch whose snapshot holds a checkpoint before the node's document's, the
+/// root: d serves one of a lower ID than the others' epoch. Not followed: each of the
+/// others tries, finds the root not its document's checkpoint, nor one it builds or
+/// 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, _, id, _, honest, _) = made_up_epoch(98).await;
+ let all = &nodes;
+ sim.wait_until(
+ "a, b and c don't follow d's epoch",
+ Duration::from_secs(90),
+ move || async move { all[..3].iter().all(not_followed) },
+ )
+ .await;
+ let later = Party::new("lass", 2).write(&[id], "home/lass/later", s("2"));
+ put(&nodes[1], &[&later]).await;
+ let later = [Id::of(&later)];
+ sim.wait_until(
+ "a, b and c are on their epoch, taking what is written on",
+ LONG,
+ move || async move {
+ for node in &all[..3] {
+ if node.local_epoch() != honest || !node.is_ready().await || !holds(node, &later) {
+ return false;
+ }
+ }
+ true
+ },
+ )
+ .await;
+}