aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 23:39:05 +0000
committertv <tv@krebsco.de>2026-11-17 01:02:36 +0100
commit4bebeca3056739c88ea22d9c076d69861f2f717b (patch)
treebcbf69829e433db66b6718b7b917135931c3960d
parent53212ecad04b3426dd2c694d527497d7c5148322 (diff)
simtest: a node away while the others moved to a checkpoint
`store_attack_24`: c is away while a and b take a version passing on tv's and lass's votes that only moves to a checkpoint, move there, forget what came before, and take a write after it. Back, c builds the checkpoint from the document, which holds what came before, and reads what a and b read. What happens after a remake leaving it out comes with the remakes.
-rw-r--r--src/simtest/holding.rs88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 657f019..b0e0442 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -122,6 +122,16 @@ fn holds(node: &AppState, ids: &[Id]) -> bool {
read(node, |store| ids.iter().all(|id| store.holds(id))) == Some(true)
}
+/// The version current, as `node`'s store reads, by its hash.
+fn current(node: &AppState) -> Option<Id> {
+ read(node, |store| store.state().current().hash)
+}
+
+/// The ID of the checkpoint `node`'s store holds.
+fn checkpoint(node: &AppState) -> Option<Id> {
+ read(node, |store| Id::of(store.checkpoint()))
+}
+
/// What counts, as `node`'s store reads: the current version, the values at places, and
/// the members; and the events it took after its checkpoint.
type Counts = (
@@ -260,3 +270,81 @@ async fn federation_attack_28() {
let counts = counts(&nodes[0]).expect("a store");
assert!(writes.iter().all(|write| counts.3.contains(write)));
}
+
+/// The version passing on the first version of tv, lass and makefu that only moves to a
+/// checkpoint at `heads`, proposed by tv, and backed by tv and lass: its spec, and the
+/// proposal and votes.
+fn checkpoint_at(
+ (tv, lass, _): &(Party, Party, Party),
+ first: &Spec,
+ heads: &[Id],
+) -> (Spec, [Vec<u8>; 3]) {
+ let on = first.hash();
+ let mut next = first.after(on);
+ next.checkpoint = Some(heads.to_vec());
+ let proposal = tv.propose(heads, &next.json());
+ let votes = [tv, lass].map(|party| party.vote(&[Id::of(&proposal)], on, next.hash(), true));
+ let [tv_yes, lass_yes] = votes;
+ (next, [proposal, tv_yes, lass_yes])
+}
+
+/// A node away while the others moved to a checkpoint and forgot what came before: c,
+/// back, builds the checkpoint from the document, which holds what came before, and
+/// reads what a and b read, what came after it too.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn store_attack_24() {
+ let sim = Sim::with_identity(83);
+ let parties = three();
+ let (tv, lass, makefu) = &parties;
+ let (first, 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;
+ sim.net.take_down("c");
+ let gone = tv.write(&[id], "home/tv/a", s("0"));
+ let head = tv.write(&[Id::of(&gone)], "home/tv/a", s("1"));
+ let (next, [proposal, tv_yes, lass_yes]) = checkpoint_at(&parties, &first, &[Id::of(&head)]);
+ put(&nodes[0], &[&gone, &head, &proposal, &tv_yes]).await;
+ put(&nodes[1], &[&lass_yes]).await;
+ let (all, passed) = (&nodes, next.hash());
+ sim.wait_until(
+ "a and b moved to the checkpoint",
+ LONG,
+ move || async move {
+ all[..2]
+ .iter()
+ .all(|node| current(node) == Some(passed) && checkpoint(node) != Some(id))
+ },
+ )
+ .await;
+ let after = tv.write(&[Id::of(&head)], "home/tv/b", s("2"));
+ put(&nodes[0], &[&after]).await;
+ let moved = checkpoint(&nodes[0]).expect("a store");
+ assert_eq!(checkpoint(&nodes[1]), Some(moved));
+ assert_eq!(
+ read(&nodes[0], |store| store.holds(&Id::of(&gone))),
+ Some(false)
+ );
+
+ sim.net.bring_up("c");
+ let after = Id::of(&after);
+ sim.wait_until(
+ "c moved there, and holds what came after",
+ LONG,
+ move || async move {
+ checkpoint(&all[2]) == Some(moved)
+ && holds(&all[2], &[after])
+ && holds(&all[0], &[after])
+ },
+ )
+ .await;
+ assert_eq!(counts(&nodes[2]), counts(&nodes[0]));
+ assert!(events::ids(&nodes[2].doc.read().await.doc).contains(&Id::of(&gone)));
+}