aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/held.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-18 17:23:18 +0000
committertv <tv@krebsco.de>2026-11-18 18:30:32 +0100
commitf261a80b88c1fb640f4c892934809e15a7e05a95 (patch)
treeb899d8994ab6fd320d0094c8e6e56487c73cc53d /src/federation/held.rs
parentd130c0612b4c63f2d30da65ebcc231018c1f2606 (diff)
attacks: rows 45, 58 and 65 tested beside the code they test
The check that every attack row of the federation has its test looks beside the code a row is about too: a node's (`held`), a party's client's (`client`), and a node voting by itself (`vote`). Rows 45 (a version written on the side a node doesn't read, refused as its own and reported apart, the change that put it taken), 58 (a node following on checkpoints only, unless its operator chose any version) and 65 (a client keeping the nays that freed its `true`) have their tests there, and wait no more.
Diffstat (limited to 'src/federation/held.rs')
-rw-r--r--src/federation/held.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs
index abb3d30..c29dd0a 100644
--- a/src/federation/held.rs
+++ b/src/federation/held.rs
@@ -1539,6 +1539,76 @@ mod tests {
assert!(Holding::open(Some(path), files, None, None).is_err());
}
+ /// `event` put into `doc` by the node `node`, in a change of its own, judged as every
+ /// node judges a change.
+ fn put_by(doc: &mut Document, node: &str, event: &[u8]) -> Result<(), String> {
+ use crate::document::replica::{Epoch, Writer, transact};
+ use crate::document::typed::{TimestampFormat, Val};
+ doc.set_actor(crate::document::ActorId::random());
+ transact(
+ doc,
+ crate::clock::UnixMillis(1),
+ &Writer { node, user: None },
+ |tx| {
+ store::write_val_path(
+ tx,
+ &meta::path(&[meta::EVENTS, &Id::of(event).to_string()]),
+ &Val::Scalar(ScalarValue::Bytes(event.to_vec())),
+ store::Writing::sticky(TimestampFormat::default()),
+ )
+ .map(|_| ())
+ },
+ )
+ .unwrap();
+ let heads = doc.get_heads();
+ crate::access::rules::judge_held(doc, Epoch::GENESIS, &heads[0]).unwrap()
+ }
+
+ /// Row 45 (`docs/federation.md`): an honest node writes a version valid where it is
+ /// written, on the side this node doesn't read, of two changing one: refused by what
+ /// this node took before, reported apart (`own`); the change that put it is taken as
+ /// every node takes a change, so nothing is held against the node that put it.
+ #[test]
+ fn federation_attack_45() {
+ let (tv, lass, makefu) = (
+ Party::new("tv", 1),
+ Party::new("lass", 2),
+ Party::new("makefu", 3),
+ );
+ let first = Spec::first(&[&tv, &lass, &makefu], &[]);
+ let root = first.root();
+ let on = first.hash();
+ let one = first.after(on);
+ let mut two = first.after(on);
+ two.rules.push(("names/x".to_owned(), harness::str("tv")));
+ let p1 = tv.propose(&[Id::of(&root)], &one.json());
+ let p2 = lass.propose(&[Id::of(&root)], &two.json());
+ let votes = [
+ tv.vote(&[Id::of(&p1)], on, one.hash(), true),
+ lass.vote(&[Id::of(&p1)], on, one.hash(), true),
+ tv.vote(&[Id::of(&p2)], on, two.hash(), true),
+ makefu.vote(&[Id::of(&p2)], on, two.hash(), true),
+ ];
+ let v1 = harness::version_event(&[Id::of(&votes[0]), Id::of(&votes[1])], one.hash());
+ let v2 = harness::version_event(&[Id::of(&votes[2]), Id::of(&votes[3])], two.hash());
+ let holding = Holding::default();
+ let mut doc = events::started(Federation::NAME, &root, &[]).unwrap();
+ for event in [&p1, &p2].into_iter().chain(&votes).chain([&v1]) {
+ put(&mut doc, event);
+ }
+ read(&holding, &doc, 0);
+ assert_eq!(put_by(&mut doc, "node-b", &v2), Ok(()));
+ read(&holding, &doc, 0);
+ assert_eq!(
+ holding.with(|store| store.own()),
+ Some((vec![Id::of(&v2)], Vec::new()))
+ );
+ assert_eq!(
+ holding.with(|store| store.state().current().hash),
+ Some(one.hash())
+ );
+ }
+
// The store's attack rows (`docs/store.md`, Attacks) read from a document.
/// tv's federation, its root, and a document started from it.