diff options
Diffstat (limited to 'src/federation/store')
| -rw-r--r-- | src/federation/store/memory.rs | 23 |
1 files changed, 13 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, |
