aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/simtest/holding.rs80
1 files changed, 79 insertions, 1 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 956bd62..c5f8e96 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -4,18 +4,22 @@
//! doesn't list; and the attack rows marked sim, each by its test.
use std::collections::{BTreeMap, BTreeSet};
+use std::path::Path;
use std::sync::Arc;
use std::time::Duration;
use super::{SOON, Sim, sim_key};
use crate::document::events;
+use crate::federation::client::Record;
use crate::federation::event::Event;
use crate::federation::fold::Federation;
use crate::federation::harness::{self, Party, Spec};
-use crate::federation::held::{self, Holding};
+use crate::federation::held::{self, Holding, Voter};
use crate::federation::jcs::Json;
use crate::federation::store::memory::Store;
use crate::federation::store::{Fold, Id};
+use crate::federation::version::Version;
+use crate::federation::vote::Rules;
use crate::files::Files;
use crate::node::NodeConfig;
use crate::state::AppState;
@@ -73,6 +77,22 @@ fn pinned(party: &str, pin: Id) -> Holding {
.expect("no file to read")
}
+/// What a node of `party` keeps of its store, voting for its party by itself by `rules`
+/// with its key, its party's record in `dir`, begun before the federation `first` spells
+/// out: so it casts on the first version too.
+fn voting(party: &Party, rules: Rules, dir: &Path, first: &Spec) -> Holding {
+ let record = dir.join(format!("{}.json", party.name));
+ let version = Version::read(&first.json()).expect("a version");
+ let mut begun = Record::begin(Id::of(&first.root()), &party.name, &version);
+ begun.began = Id::of(b"before the federation").to_string();
+ begun.save(&record).expect("a record");
+ holding(&party.name).voting(Some(Voter {
+ key: party.key.clone(),
+ record,
+ rules,
+ }))
+}
+
/// `config`, of a node of the swarm holding the store `id`, keeping `holding`: started
/// from the store's `root` where given (`--store-root`), else joining by its ID
/// (`--store-id`).
@@ -458,3 +478,61 @@ async fn parted(seed: u64, checkpoints: bool) {
.await;
assert_eq!(checkpoint(b), checkpoint(&nodes[0]));
}
+
+/// A party keeps a proposal alive that nobody else backs, to hold back automatic
+/// checkpoints: makefu proposes a version and backs it alone. a votes for tv by itself,
+/// proposing a checkpoint once its store took five events; b votes for lass, following
+/// tv. a proposes one beside makefu's, b backs it, and every node moves there.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn federation_attack_67() {
+ let sim = Sim::with_identity(86);
+ let (tv, lass, makefu) = three();
+ let (first, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"]), (&makefu, &["c"])]);
+ let dir = crate::files::scratch_dir("sim-attack-67");
+ let proposing = Rules {
+ propose_events: Some(5),
+ ..Rules::default()
+ };
+ let following = Rules {
+ follow: vec!["tv".to_owned()],
+ ..Rules::default()
+ };
+ let nodes = started(
+ &sim,
+ &root,
+ vec![
+ ("a", voting(&tv, proposing, &dir, &first)),
+ ("b", voting(&lass, following, &dir, &first)),
+ ("c", holding("makefu")),
+ ],
+ )
+ .await;
+ let on = first.hash();
+ let mut other = first.after(on);
+ other.rules.push(("names/x".to_owned(), s("makefu")));
+ let alive = makefu.propose(&[id], &other.json());
+ let backed = makefu.vote(&[Id::of(&alive)], on, other.hash(), true);
+ put(&nodes[2], &[&alive, &backed]).await;
+ let writes: Vec<Vec<u8>> = (1..=3)
+ .map(|n| tv.write(&[id], &format!("home/tv/{n}"), s("1")))
+ .collect();
+ let writes: Vec<&[u8]> = writes.iter().map(Vec::as_slice).collect();
+ put(&nodes[0], &writes).await;
+ let (all, kept_alive) = (&nodes, other.hash());
+ sim.wait_until(
+ "every node moved to a checkpoint",
+ LONG,
+ move || async move {
+ all.iter().all(|node| {
+ let named = read(node, |store| {
+ let current = store.state().current();
+ current.number == 1
+ && current.checkpoint.is_some()
+ && current.hash != kept_alive
+ });
+ named == Some(true) && checkpoint(node) != Some(id)
+ })
+ },
+ )
+ .await;
+}