aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 16:21:02 +0000
committertv <tv@krebsco.de>2026-11-19 17:36:20 +0100
commit602718835d034ef0a96c8ca29e47f06ce37008dc (patch)
tree99a1ffbf50a4f59b3a5078dafa8c0cb3d192632c /src/federation
parent9784111bd3b95be5352669b74e174920c101f349 (diff)
events: what moving to a proposed checkpoint refuses, shown
federation.md, and row 68, said a node shows, for a proposed checkpoint, what it holds that its heads lack; no node did. `GET /events/counts` now shows, of each proposal whose version names a checkpoint, the writes, key sets and node lists the node took that moving there refuses (`beside`; null for another version): neither among its heads, in their history, nor above them, as the move has it, which their parties sign again. Proposals and votes lapse with the move, and merge events count for nothing: they are left out. `Store::beside` finds them in one pass, as the move itself does: the two share `Store::above`, which the move computed inline.
Diffstat (limited to 'src/federation')
-rw-r--r--src/federation/store/memory.rs54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs
index 05479e3..b4be6f0 100644
--- a/src/federation/store/memory.rs
+++ b/src/federation/store/memory.rs
@@ -359,6 +359,41 @@ impl<F: Fold> Store<F> {
.collect()
}
+ /// Of the events taken after the checkpoint, those a move to a checkpoint at `heads`
+ /// refuses: neither among them, nor in their history, nor above them (`moved`), where
+ /// they are heads a version may name.
+ pub(crate) fn beside(&self, heads: &[Id]) -> Vec<Id> {
+ let set: BTreeSet<Id> = heads.iter().copied().collect();
+ let before = self.history(heads);
+ let above = self.above(&set, &before);
+ self.order
+ .iter()
+ .filter(|id| !before.contains(id) && !above.contains(id))
+ .copied()
+ .collect()
+ }
+
+ /// Of the events taken after the checkpoint, those above `heads`, `before` being their
+ /// history: each building on the heads, or on what is above them, alone, and on all
+ /// the heads or on one above them.
+ fn above(&self, heads: &BTreeSet<Id>, before: &HashSet<Id>) -> HashSet<Id> {
+ let mut above: HashSet<Id> = HashSet::new();
+ for id in self.order.iter().filter(|id| !before.contains(id)) {
+ let dependencies = &self.events[id].dependencies;
+ let on = dependencies
+ .iter()
+ .all(|dependency| heads.contains(dependency) || above.contains(dependency));
+ let holds = dependencies
+ .iter()
+ .any(|dependency| above.contains(dependency))
+ || heads.iter().all(|head| dependencies.contains(head));
+ if on && holds {
+ above.insert(*id);
+ }
+ }
+ above
+ }
+
/// The events taken after the checkpoint among `ids` and all they build on.
fn history(&self, ids: &[Id]) -> HashSet<Id> {
let mut history = HashSet::new();
@@ -422,20 +457,7 @@ impl<F: Fold> Store<F> {
return false;
};
let before = self.history(&ids);
- let mut above: HashSet<Id> = HashSet::new();
- for id in self.order.iter().filter(|id| !before.contains(id)) {
- let dependencies = &self.events[id].dependencies;
- let on = dependencies
- .iter()
- .all(|dependency| heads.contains(dependency) || above.contains(dependency));
- let holds = dependencies
- .iter()
- .any(|dependency| above.contains(dependency))
- || heads.iter().all(|head| dependencies.contains(head));
- if on && holds {
- above.insert(*id);
- }
- }
+ let above = self.above(&heads, &before);
for id in &self.order {
if before.contains(id) {
if !kept.contains_key(id) && !heads.contains(id) {
@@ -1184,6 +1206,10 @@ mod tests {
store.left_out(&[head, beside], &[first, beside, above]),
vec![above]
);
+ // What a move there refuses: what is beside them, and what builds on it too.
+ 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]);
}
/// A store whose root holds puts and a lock, cut at the lock: the cut's ID, the lock's,