aboutsummaryrefslogtreecommitdiffstats
path: root/src/simtest
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 02:16:13 +0000
committertv <tv@krebsco.de>2026-12-01 02:16:13 +0000
commitd3c12b3951d4078ea8dda61a436d46cc85fa8f33 (patch)
tree62eefedc83c7c86404cdf30d8b7da505d8d63dbb /src/simtest
parent22f9ac13bd0089f89cd2dd74932b522ab0c285c0 (diff)
simtest: keys voting twice part nodes of sets, too
The simulation of keys that voted twice, the nodes holding their stores in sets of events: each keeps the version the other side took beside its store, and b's operator has it drop its own and take that one; or, where the versions named checkpoints, each refuses the other side's as not above its own, and b begins its set anew from the checkpoint the others moved to, as a node given another pin does.
Diffstat (limited to 'src/simtest')
-rw-r--r--src/simtest/holding.rs114
1 files changed, 99 insertions, 15 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 0a40657..e6e2449 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -543,24 +543,49 @@ async fn store_attack_24() {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn federation_attack_49() {
for (seed, checkpoints) in [(84, false), (85, true)] {
- parted(seed, checkpoints).await;
+ parted(seed, checkpoints, false).await;
}
}
-async fn parted(seed: u64, checkpoints: bool) {
+/// [`federation_attack_49`], the nodes holding their stores in sets of events: each
+/// keeps the other side's version beside its store, for whoever takes it; or, where
+/// the versions named checkpoints, b begins its set anew from the one the others moved to.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn keys_voting_twice_part_nodes_of_sets() {
+ for (seed, checkpoints) in [(101, false), (102, true)] {
+ parted(seed, checkpoints, true).await;
+ }
+}
+
+async fn parted(seed: u64, checkpoints: bool, sets: bool) {
let sim = Sim::with_identity(seed);
let (tv, lass, makefu) = three();
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;
+ let nodes = if sets {
+ let nodes: Vec<AppState> = [("a", "tv"), ("b", "lass"), ("c", "makefu")]
+ .into_iter()
+ .map(|(name, party)| start_on_a_set(&sim, name, party, id, a_set(&root), None, false))
+ .collect();
+ let all: Vec<&AppState> = nodes.iter().collect();
+ let all = &all;
+ 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;
+ nodes
+ } else {
+ started(
+ &sim,
+ &root,
+ vec![
+ ("a", holding("tv")),
+ ("b", holding("lass")),
+ ("c", holding("makefu")),
+ ],
+ )
+ .await
+ };
sim.net.take_down("b");
let on = first.hash();
let (mut one, mut two) = (first.after(on), first.after(on));
@@ -591,14 +616,73 @@ async fn parted(seed: u64, checkpoints: bool) {
)
.await;
sim.net.bring_up("b");
- let members: Vec<&AppState> = nodes.iter().collect();
- sim.wait_converged(&members, LONG).await;
+ if sets && checkpoints {
+ // Each moved to its side's checkpoint, and refuses the other's as not above
+ // it: it holds none of that.
+ sim.wait_until("each refuses the other side's", LONG, move || async move {
+ all.iter()
+ .all(|node| read(node, |store| store.refused().count() > 0) == Some(true))
+ })
+ .await;
+ } else if sets {
+ // Each holds the version event the other side took, beside its store.
+ let sides = [
+ written(&nodes[0], one_hash).expect("a wrote what it took"),
+ written(&nodes[1], two_hash).expect("b wrote what it took"),
+ ];
+ sim.wait_until(
+ "each holds the other side's version event",
+ LONG,
+ move || async move {
+ all.iter().all(|node| {
+ node.holding
+ .with_set(|set| sides.iter().all(|id| set.get(id).is_some()))
+ == Some(true)
+ })
+ },
+ )
+ .await;
+ } else {
+ let members: Vec<&AppState> = nodes.iter().collect();
+ sim.wait_converged(&members, LONG).await;
+ }
// Parted: each keeps the version it took.
assert_eq!(current(&nodes[0]), Some(one_hash));
assert_eq!(current(&nodes[1]), Some(two_hash));
assert_eq!(current(&nodes[2]), Some(one_hash));
- let b = if checkpoints {
+ let b = if checkpoints && sets {
+ let pin = checkpoint(&nodes[0]).expect("a store");
+ // As a node given another pin than its set began from starts (`StoreStart::set`).
+ let start = nodes[1]
+ .holding
+ .with_set(|set| {
+ crate::federation::store::passing::Start::new(id, pin, Duration::from_secs(600))
+ .refusing_as(set)
+ })
+ .expect("a set");
+ let (own, _) = read(&nodes[1], |store| store.own()).expect("a store");
+ let b = sim.restart_with(
+ "b",
+ &["a"],
+ Start::FromDocument(Origin::Root),
+ move |config| {
+ config.store = Some(id);
+ config.holding = holding("lass").carrying_if(
+ Some(held::Begun::Start(Box::new(start))),
+ None,
+ Arc::new(Files::default()),
+ );
+ },
+ );
+ let again = &b;
+ sim.wait_until("b began its set anew", LONG, move || async move {
+ read(again, |_| ()).is_some()
+ })
+ .await;
+ assert_eq!(read(&b, |store| store.own().0), Some(own));
+ b
+ } else if checkpoints {
let pin = checkpoint(&nodes[0]).expect("a store");
sim.restart_with("b", &["a"], Start::Join, move |config| {
of_the_store(config, id, None, pinned("lass", pin))