diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/federation/held.rs | 2 | ||||
| -rw-r--r-- | src/simtest/holding.rs | 92 |
2 files changed, 93 insertions, 1 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs index b7625e0..2eac8b2 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -1788,7 +1788,7 @@ mod tests { } /// Rows whose tests wait: remakes (stage 5), and flooding. - const LATER: &[u32] = &[11, 12, 13, 15, 16, 22, 28, 29, 30, 31]; + const LATER: &[u32] = &[11, 13, 15, 16, 22, 28, 29, 30, 31]; #[test] fn every_row_has_its_test() { diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index ba33470..187488e 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -922,3 +922,95 @@ async fn federation_attack_33() { ); assert_eq!(reads(&forks[1].1), Some((Id::of(&crafted_root), None))); } + +/// Every node of `nodes` on generation `generation` and ready, within `timeout`. +async fn on_generation(sim: &Sim, nodes: &[AppState], generation: u64, timeout: Duration) { + sim.wait_until( + &format!("every node is ready on generation {generation}"), + timeout, + move || async move { + for node in nodes { + if node.local_epoch().generation != generation || !node.is_ready().await { + return false; + } + } + true + }, + ) + .await; +} + +/// The compaction `node` proposes: its ID. +async fn compact(node: &AppState) -> String { + let (status, report) = + crate::remake::testing::start(node.clone(), serde_json::json!({ "kind": "compact" }), None) + .await; + assert!(status.is_success(), "proposal refused: {status} {report}"); + report["id"].as_str().expect("a remake's ID").to_owned() +} + +/// Events written beyond a base, on nodes that switch and on nodes that don't yet: put +/// again in the new epoch, the same events, the same state; and no change refused. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn store_attack_12() { + let sim = Sim::with_identity(91); + let (tv, lass, makefu) = three(); + let (_, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"]), (&makefu, &["c"])]); + let nodes = started( + &sim, + &root, + vec![ + ("a", holding("tv")), + ("b", holding("lass")), + ("c", holding("makefu")), + ], + ) + .await; + let all = &nodes; + let before = tv.write(&[id], "home/tv/before", s("1")); + put(&nodes[0], &[&before]).await; + let held = [Id::of(&before)]; + sim.wait_until("every node holds tv's write", LONG, move || async move { + all.iter().all(|node| holds(node, &held)) + }) + .await; + + let remake = compact(&nodes[0]).await; + let remake = remake.as_str(); + sim.wait_until("b and c hold it committed", LONG, move || async move { + for node in &all[1..] { + let committed = crate::remake::testing::report(node, remake) + .await + .is_some_and(|report| report["phase"] == "committed"); + if !committed { + return false; + } + } + true + }) + .await; + // Beyond its base, on nodes that haven't switched yet. + let during = [ + lass.write(&[Id::of(&before)], "home/lass/during", s("2")), + makefu.write(&[id], "home/makefu/during", s("3")), + ]; + put(&nodes[1], &[&during[0]]).await; + put(&nodes[2], &[&during[1]]).await; + on_generation(&sim, &nodes, 1, Duration::from_secs(60)).await; + let after = tv.write(&[Id::of(&during[0])], "home/tv/after", s("4")); + put(&nodes[0], &[&after]).await; + + let every = [&before, &during[0], &during[1], &after].map(|event| Id::of(event)); + sim.wait_until("every node holds every event", LONG, move || async move { + all.iter().all(|node| holds(node, &every)) + }) + .await; + let read: Vec<Option<Counts>> = nodes.iter().map(counts).collect(); + assert!(read.iter().all(|counts| counts == &read[0]), "{read:?}"); + for node in &nodes { + let refused = crate::locks::MutexExt::lock_or_recover(&*node.screening) + .refused() + .count(); + assert_eq!(refused, 0, "a change refused"); + } +} |
