diff options
Diffstat (limited to 'src/federation')
| -rw-r--r-- | src/federation/store/memory.rs | 23 | ||||
| -rw-r--r-- | src/federation/vote.rs | 39 |
2 files changed, 52 insertions, 10 deletions
diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs index b4be6f0..092a606 100644 --- a/src/federation/store/memory.rs +++ b/src/federation/store/memory.rs @@ -339,22 +339,20 @@ impl<F: Fold> Store<F> { } /// Of `ids`, events the store took, those not among `heads`, in their history, nor - /// above them (each with them all in its history): what a checkpoint at `heads` leaves - /// out, by the voters' rule (`docs/federation.md`, Checkpoints). + /// above them (`above`): what a checkpoint at `heads` leaves out, by the voters' rule + /// (`docs/federation.md`, Checkpoints), which is what a move there refuses (`beside`). + /// One with every head in its history that also builds on something beside them is + /// left out. pub(crate) fn left_out<'a>( &self, heads: &[Id], ids: impl IntoIterator<Item = &'a Id>, ) -> Vec<Id> { - let covered = self.history(heads); + let set: BTreeSet<Id> = heads.iter().copied().collect(); + let before = self.history(heads); + let above = self.above(&set, &before); ids.into_iter() - .filter(|id| { - !heads.contains(id) - && !covered.contains(id) - && !heads - .iter() - .all(|head| self.history(std::slice::from_ref(id)).contains(head)) - }) + .filter(|id| !before.contains(id) && !above.contains(id)) .copied() .collect() } @@ -1210,6 +1208,11 @@ mod tests { let both = taken(store.offer(testfold::put(&[above, beside], "d", "1"))); assert_eq!(store.beside(&[head]), vec![beside, both]); assert_eq!(store.beside(&[head, beside]), vec![above, both]); + // And so do those heads leave it out, though it has them all in its history. + assert_eq!( + store.left_out(&[head], &[first, head, beside, above, both]), + vec![beside, both] + ); } /// A store whose root holds puts and a lock, cut at the lock: the cut's ID, the lock's, diff --git a/src/federation/vote.rs b/src/federation/vote.rs index 7000b40..a633b0e 100644 --- a/src/federation/vote.rs +++ b/src/federation/vote.rs @@ -520,6 +520,45 @@ mod tests { } } + /// The voters' rule backs no checkpoint whose move refuses what the node held for a + /// while: a write built on the heads and on something beside them, a proposal say, as + /// clients build on every head they hold, has the heads in its history, and the move + /// refuses it all the same. + #[test] + fn a_node_backs_no_checkpoint_that_refuses_what_it_held() { + let (tv, lass, _, first, mut store) = three(); + let root = store.id(); + let head = taken( + &mut store, + tv.write(&[root], "home/tv/a", harness::str("1")), + ); + let mut junk = first.after(first.hash()); + junk.rules.push(("names/x".to_owned(), harness::str("tv"))); + let beside = taken(&mut store, tv.propose(&[root], &junk.json())); + let write = taken( + &mut store, + lass.write(&[head, beside], "home/lass/b", harness::str("2")), + ); + let mut checkpoint = first.after(first.hash()); + checkpoint.checkpoint = Some(vec![head]); + let version = Version::read(&checkpoint.json()).unwrap(); + let rules = Rules { + held_for: Duration::from_secs(60), + ..Rules::default() + }; + let long = |_: &Id| Some(Duration::from_secs(3600)); + let seen = Seen { + store: &store, + held: &long, + since_move: Duration::from_secs(86400), + }; + let current = store.state().current().clone(); + let why = backs_checkpoint(&seen, &rules, ¤t, &version, Duration::ZERO) + .expect_err("its move refuses a write held for a while"); + assert!(why.contains(&write.to_string()), "{why}"); + assert_eq!(store.beside(&[head]), vec![beside, write]); + } + #[test] fn a_node_follows_a_party_on_checkpoints() { let (tv, lass, _, first, mut store) = three(); |
